Skip to content

Commit

Permalink
fix(preset): modulePathIgnorePatterns prevented jest from finding tes…
Browse files Browse the repository at this point in the history
…ts (#49)

* fix(preset): modulePathIgnorePatterns prevented jest from finding tests

* chore(devDeps): update eslint and resolve peerDeps

* chore(workflows): add node 10 back to test matrix

* test(lint): downgrade eslint for node 10 support
  • Loading branch information
10xLaCroixDrinker authored Sep 7, 2022
1 parent c7e31ce commit bb39161
Show file tree
Hide file tree
Showing 12 changed files with 21,671 additions and 1,243 deletions.
9 changes: 8 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{
"extends": "amex"
"extends": "amex",
"overrides": [{
"files": ["__tests__/**"],
"extends": "amex/test",
"rules": {
"global-require": 0
}
}]
}
2 changes: 1 addition & 1 deletion .github/workflows/health-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ '10.x', '12.x', '14.x' ]
node: [ '10.x', '12.x', '14.x', '16.x', '18.x' ]
name: Node ${{ matrix.node }}
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 12
node-version: 16
- name: Install dependencies
run: npm ci
- name: Release
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ '10.x', '12.x', '14.x' ]
node: [ '10.x', '12.x', '14.x', '16.x', '18.x' ]
name: Node ${{ matrix.node }}
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ For a React specific Jest preset use: [amex-jest-preset-react](https://github.co

- [coverageThreshold](http://facebook.github.io/jest/docs/en/configuration.html#coveragethreshold-object) tells Jest to return failure unless code coverage is 100% for branch, function, line, and statement. (Yes this does mean that your build will fail if you don't have 100% code coverage)

- [modulePathIgnorePatterns](https://facebook.github.io/jest/docs/en/configuration.html#modulepathignorepatterns-array-string) tells Jest to not even consider `npm-cache` and `npm` directories for module loading. This prevents issues on CI server where `npm-cache` may be shared across build workspaces.

- [testEnvironment](https://jestjs.io/docs/en/configuration.html#testenvironment-string) tells Jest to use `node` as its test environment. This is done for performance reasons as the full `jsdom` environment is not needed for most tests and including it slows Jest startup time considerably.

- [testResultsProcessor](http://facebook.github.io/jest/docs/en/configuration.html#testresultsprocessor-string) is used to output test results onto our HTML report creator. That way pretty HTML test results are created in `<rootDir>/test-results/`
Expand Down
3 changes: 0 additions & 3 deletions __tests__/.eslintrc.json

This file was deleted.

17 changes: 9 additions & 8 deletions __tests__/html-report-creator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ function buildMockResult(mockResult = {}) {
startTime: 1497400767268,
success: true,
testResults: [
{ console: [],
{
console: [],
perfStats: {
end: 1497401364334,
start: 1497401364037,
Expand All @@ -56,7 +57,6 @@ function setupTest() {
fs.writeFileSync = jest.fn();
process.cwd = jest.fn(() => '/path/to/something');

// eslint-disable-next-line global-require
return require('../html-report-creator');
}

Expand All @@ -77,10 +77,11 @@ describe('html-report-creator', () => {
const mockResult = buildMockResult(
{
testResults: [
{ testExecError: {
message: 'error!',
stack: 'stacktrace for error',
},
{
testExecError: {
message: 'error!',
stack: 'stacktrace for error',
},
},
],
}
Expand Down Expand Up @@ -197,8 +198,8 @@ describe('html-report-creator', () => {

createHtmlReport(mockResult);
expect(fs.writeFileSync.mock.calls[0][0])
// eslint-disable-next-line no-useless-escape
.toMatch(/[\\\/]path[\\\/]to[\\\/]something[\\\/]test-results[\\\/]test-report.html/);

.toMatch(/[/\\]path[/\\]to[/\\]something[/\\]test-results[/\\]test-report.html/);
});

it('should write output to JEST_TEST_REPORT_PATH if variable exists', () => {
Expand Down
4 changes: 0 additions & 4 deletions __tests__/jest-preset.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* Copyright (c) 2017 American Express Travel Related Services Company, Inc.
*
Expand All @@ -20,7 +19,6 @@ describe('jest-preset.js', () => {
});

it('should produce valid jest preset config', () => {
// eslint-disable-next-line global-require
const jestPreset = require('../jest-preset');

expect(jestPreset).toMatchObject({
Expand Down Expand Up @@ -55,15 +53,13 @@ describe('jest-preset.js', () => {

it('should disable jest cache if running on CI server', () => {
jest.doMock('is-ci', () => true);
// eslint-disable-next-line global-require
const jestPreset = require('../jest-preset');

expect(jestPreset).toHaveProperty('cache', false);
});

it('should enable jest cache if running outside of a CI server', () => {
jest.doMock('is-ci', () => false);
// eslint-disable-next-line global-require
const jestPreset = require('../jest-preset');

expect(jestPreset).toHaveProperty('cache', true);
Expand Down
2 changes: 1 addition & 1 deletion html-report-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module.exports = (result) => {
const testTd = testTr.ele('td', `${statusIcon} ${test.fullName}`);
testTd.ele('span', { class: 'result' }, `${test.status} in ${test.duration / 1000}s`);

if (test.failureMessages.length !== 0) {
if (test.failureMessages.length > 0) {
const failureMsgDiv = testTd.ele('div');
test.failureMessages.forEach((failureMsg) => {
const plainFailureMessage = stripAnsi(failureMsg);
Expand Down
4 changes: 0 additions & 4 deletions jest-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,4 @@ module.exports = {
statements: 100,
},
},
modulePathIgnorePatterns: [
'npm-cache',
'.npm',
],
};
Loading

0 comments on commit bb39161

Please sign in to comment.