Skip to content

Commit

Permalink
Merge pull request #30 from MSA-Safety/feat/jest-eslint
Browse files Browse the repository at this point in the history
Feat/jest eslint
  • Loading branch information
rimesime authored Feb 23, 2023
2 parents 60a4f68 + cbe6bf2 commit 701b533
Show file tree
Hide file tree
Showing 12 changed files with 284 additions and 329 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/test_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run lint
- run: npm run test:unit
- run: npm run test

analyze:
name: Analyze
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
build
build
.vscode
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ appropriate usages might be e.g. network flakiness in integration and e2e tests.

```shell
$ cd demo
$ npm run test:unit # failure-free junit output; jest will return with exit code 1 nonetheless
$ npm run test # failure-free junit output; jest will return with exit code 1 nonetheless

> jest-flaky-retry-demo@0.0.1 test:unit
> jest --config jest.unit.config.js
> jest-flaky-retry-demo@0.0.1 test
> jest --config jest.config.js

Determining test suites to run...Loading list of known flaky tests from jest.unit.flakyRetry.json
Determining test suites to run...Loading list of known flaky tests from jest.flakyRetry.json
[ { failureMessages: [ 'Random Flaky Error' ] } ]
FAIL ./demo.unit.test.js
demo
Expand Down
17 changes: 17 additions & 0 deletions demo/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

module.exports = {
// Use this configuration option to add reporters to Jest
reporters: [
'default',
[
'<rootDir>/..', // refers to jest-flaky-retry
{
configFile: 'jest.flakyRetry.json',
junitOutputDirectory: 'build/results/unit',
},
],
],
// The glob patterns Jest uses to detect test files
testMatch: ['**/?(*.)+(unit.test).js?(x)'],
};
File renamed without changes.
32 changes: 0 additions & 32 deletions demo/jest.unit.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.1",
"description": "Demo project using jest-flaky-retry",
"scripts": {
"test:unit": "jest --config jest.unit.config.js"
"test": "jest"
},
"author": "Safety io - Cloud Platform Team",
"license": "ISC",
Expand Down
4 changes: 2 additions & 2 deletions index.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ describe('jestFlakyRetryReporter', () => {
let caughtError;

try {
execSync('cd demo && npm run test:unit');
execSync('cd demo && npm run test');
} catch (error) {
caughtError = error;
}
Expand All @@ -299,7 +299,7 @@ describe('jestFlakyRetryReporter', () => {
const stderr = caughtError.stderr.toString();

expect(status).toBe(1);
expect(stdout).toContain('Loading list of known flaky tests from jest.unit.flakyRetry.json');
expect(stdout).toContain('Loading list of known flaky tests from jest.flakyRetry.json');
expect(stdout).toContain('[ { failureMessages: [ \'Random Flaky Error\' ] } ]');
expect(stdout).toContain('Retrying test cases: [ \'demo should fail on first test run and succeed on subsequent run\' ]');
expect(stderr).toContain('1 failed, 1 total');
Expand Down
58 changes: 58 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use strict';

// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html

module.exports = {
// Run tests from one or more projects
projects: [
{
// Allows for a label to be printed alongside a test while it is running
displayName: 'test',
// The pattern or patterns Jest uses to detect test files
testRegex: ['.*unit\\.test\\.js$'],
// An array of regexp pattern strings that are matched against all test paths,
// matched tests are skipped
testPathIgnorePatterns: [
'/node_modules/',
'/demo/',
],
},
{
// Allows for a label to be printed alongside a test while it is running
displayName: 'lint',
// This option allows you to use a custom runner instead of Jest's default test runner
runner: 'jest-runner-eslint',
// The pattern or patterns Jest uses to detect test files
testRegex: ['.*\\.js$'],
// An array of regexp pattern strings that are matched against all test paths,
// matched tests are skipped
testPathIgnorePatterns: [
'/node_modules/',
'/build/',
],
},
],
// Indicates whether the coverage information should be collected while executing the test
collectCoverage: true,
// The directory where Jest should output its coverage files
coverageDirectory: 'build/coverage/unit',
// An array of regexp pattern strings used to skip coverage collection
coveragePathIgnorePatterns: ['node_modules'],
// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
// Automatically clear mock calls and instances between every test
clearMocks: true,
// Use this configuration option to add custom reporters to Jest
reporters: [
'default',
['jest-junit', { outputDirectory: 'build/results/unit' }],
],
};
201 changes: 0 additions & 201 deletions jest.unit.config.js

This file was deleted.

Loading

0 comments on commit 701b533

Please sign in to comment.