Skip to content

Commit cd0f921

Browse files
test: Re-work tests to use Jest and not mockery and mock-fs (#119)
* fix: replace mocha with jest - allows removal of mockery, mock-fs - should improve speed of test runs - separates out integration-tests to run serially, and avoid impacts when working with real files in tmp dir Signed-off-by: Tim Knight <tim.knight1@engineering.digital.dwp.gov.uk> * build: enable tests on node lts and latest Signed-off-by: Tim Knight <tim.knight1@engineering.digital.dwp.gov.uk> * chore: remove cli.js from coverage report Signed-off-by: Tim Knight <tim.knight1@engineering.digital.dwp.gov.uk> * Update .github/workflows/ci.yaml * chore: extract eslint and jest configs Signed-off-by: Tim Knight <tim.knight1@engineering.digital.dwp.gov.uk> * chore: don't build vs latest Signed-off-by: Tim Knight <tim.knight1@engineering.digital.dwp.gov.uk> * fix: rename "mockers" to "jest-mocks" Signed-off-by: Tim Knight <tim.knight1@engineering.digital.dwp.gov.uk> * chore: why is invalid-config test flaky Signed-off-by: Tim Knight <tim.knight1@engineering.digital.dwp.gov.uk> * fix: use different temp directories for each integration test - And extract functions with WYSIWG naming Signed-off-by: Tim Knight <tim.knight1@engineering.digital.dwp.gov.uk> --------- Signed-off-by: Tim Knight <tim.knight1@engineering.digital.dwp.gov.uk> Co-authored-by: Timothy Jones <timothy.l.jones@gmail.com>
1 parent 16be049 commit cd0f921

20 files changed

+7251
-9249
lines changed

.eslintrc

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,49 @@
11
{
2-
"extends": ["prettier", "eslint:recommended", "plugin:mocha/recommended"],
3-
"env": { "node": true, "es6": true },
4-
"parserOptions": { "ecmaVersion": 2023 },
5-
"plugins": ["mocha", "@fintechstudios/eslint-plugin-chai-as-promised"],
2+
"extends": [
3+
"prettier",
4+
"eslint:recommended"
5+
],
6+
"env": {
7+
"node": true,
8+
"es6": true
9+
},
10+
"overrides": [
11+
{
12+
"env": {
13+
"node": true,
14+
"es6": true,
15+
"jest/globals": true
16+
},
17+
"files": [
18+
"test/**"
19+
],
20+
"plugins": [
21+
"jest"
22+
],
23+
"extends": [
24+
"prettier",
25+
"eslint:recommended",
26+
"plugin:jest/recommended"
27+
],
28+
"rules": {
29+
"jest/prefer-expect-assertions": "off",
30+
"jest/expect-expect": "off"
31+
}
32+
}
33+
],
34+
"parserOptions": {
35+
"ecmaVersion": 2023
36+
},
37+
"plugins": [
38+
"jest"
39+
],
640
"rules": {
741
"no-var": "error",
8-
"no-unused-vars": ["error", { "argsIgnorePattern": "_.*" }],
9-
"mocha/max-top-level-suites": "off",
10-
"mocha/no-setup-in-describe": "off",
11-
"@fintechstudios/chai-as-promised/no-unhandled-promises": "error",
12-
"@fintechstudios/chai-as-promised/no-await-in-condition": "error"
42+
"no-unused-vars": [
43+
"error",
44+
{
45+
"argsIgnorePattern": "_.*"
46+
}
47+
]
1348
}
1449
}

.github/workflows/ci.yaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@ jobs:
1010
runs-on: ${{ matrix.os }}
1111
strategy:
1212
matrix:
13-
node: [18, 20.4]
14-
os: [ubuntu-latest, windows-latest]
13+
node: [
14+
18,
15+
20.4, # Known good version of 20 which ran the previous Mocha and mock-fs based tests. If you go back to re-run those, tests Node 20.4 is the last version mock-fs worked with
16+
20,
17+
lts/*
18+
]
19+
os: [
20+
ubuntu-latest,
21+
windows-latest
22+
]
1523
env:
1624
OS: ${{ matrix.os }}
1725
NODE_VERSION: ${{ matrix.node }}
@@ -26,7 +34,6 @@ jobs:
2634
- run: node --version
2735
- run: npm install --engine-strict
2836
- run: npm test
29-
- run: npm run coverage
3037
- name: Codecov
3138
uses: codecov/codecov-action@v3
3239
with:

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ npm-debug.log
1414

1515
# coverage
1616
coverage
17+
18+
# temp dirs
19+
*-temp
20+
tmp

jest.config.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const config = {
2+
collectCoverage: true,
3+
collectCoverageFrom: [
4+
'**/*.{js,jsx,ts}',
5+
'!**/node_modules/**',
6+
'!**/tmp/**',
7+
'!**/test/**',
8+
'!**/coverage/**',
9+
'!**/bin/**',
10+
],
11+
coverageReporters: ['lcov', 'text'],
12+
projects: [
13+
{
14+
displayName: 'Unit Test',
15+
testMatch: ['**/test/*.spec.js'],
16+
},
17+
{
18+
displayName: 'Integration Test',
19+
runner: 'jest-serial-runner',
20+
testMatch: ['**/test/*.integration-test.js'],
21+
},
22+
],
23+
silent: true, // Suppresses runtime console logs during test runs
24+
testTimeout: 30000,
25+
verbose: true, // Prints test describe/it names into console during test runs
26+
};
27+
28+
module.exports = config;

0 commit comments

Comments
 (0)