Skip to content

Commit 6cc76a5

Browse files
authored
test: port legacy-tests to jest (#221)
This converts the rest of the legacy-tests to jest. This was a little more involved than the ava ones since they had a bit more magic/complexity baked into them. I would still like to consider them "legacy", but I wanted to get them in jest anyway so we could get full library coverage via a single tool. So I'm considering this a step towards deleting/replacing them with modern es6/typescript integration-type tests - but in doing that we should be sure we're not dropping any coverage - which is good right now. Here's the report output by `yarn test --coverage`: ``` --------------------|---------|----------|---------|---------|------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s --------------------|---------|----------|---------|---------|------------------- All files | 96.48 | 92.23 | 97.3 | 96.91 | src | 96.33 | 90.71 | 96 | 96.94 | index.ts | 100 | 100 | 100 | 100 | migration.ts | 90 | 76.47 | 100 | 89.66 | 28,47,51 migrationsList.ts | 100 | 100 | 100 | 100 | umzug.ts | 97.01 | 92.62 | 94.87 | 97.99 | 23,357,396 src/storage | 96.97 | 95.45 | 100 | 96.83 | contract.ts | 100 | 100 | 100 | 100 | index.ts | 100 | 100 | 100 | 100 | json.ts | 100 | 100 | 100 | 100 | memory.ts | 100 | 100 | 100 | 100 | mongodb.ts | 100 | 94.74 | 100 | 100 | 29 sequelize.ts | 92.31 | 93.94 | 100 | 92.31 | 104,150 --------------------|---------|----------|---------|---------|------------------- ``` The changes to the implementation of the legacy tests are: - convert to jest using jest-codemods again. In most cases we're still using sinon rather than `jest.fn()` to keep this change from getting too big - the `helper` is now a function which takes a subdirectory name. All the legacy tests were trying to write to the same folder which caused problems when switching to jest, which parallelises tests. Getting a helper went from `const helper = require('helper')` to `const helper = require('helper')('some-subdirectory-name')` - references to `this`, which were used for test state/context, have been replaced by `const state = {}` at the top of each test file. Then `this.umzug = new Umzug(...)` became `state.umzug = new Umzug(...)` in `beforeEach`, etc. - use `memoryStorage()` rather than `new JSONStorage(...)` for each test's storage to avoid unnecessary writing to disk - added a bunch of `/* eslint-disable ... */` comments to the top of the ported files, rather than disabling the linter completely for all of them. The actual setups, assertions, business logic etc. are untouched. This has allowed us to drop a few dependencies - `mocha`, `chai`, and `sinon-chai`.
1 parent 31d010f commit 6cc76a5

34 files changed

+1601
-2013
lines changed

.eslintrc.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
module.exports = {
22
parser: '@typescript-eslint/parser',
3-
parserOptions: { ecmaVersion: 2018, sourceType: 'module', project: './tsconfig.json' },
3+
parserOptions: {
4+
ecmaVersion: 2018,
5+
sourceType: 'module',
6+
project: ['./tsconfig.json', 'test/tsconfig.json'],
7+
},
48
plugins: [
59
'@typescript-eslint/eslint-plugin',
610
'prettier',
@@ -20,7 +24,7 @@ module.exports = {
2024
'xo',
2125
'xo-typescript',
2226
],
23-
ignorePatterns: ['lib', 'node_modules'],
27+
ignorePatterns: ['lib', 'node_modules', 'test/generated', 'test/fixtures/javascript', 'coverage'],
2428
globals: { __dirname: true, process: true },
2529
rules: {
2630
'codegen/codegen': 'warn',
@@ -45,7 +49,7 @@ module.exports = {
4549

4650
'jest/expect-expect': [
4751
'error',
48-
{assertFunctionNames: ['expect', 'expectTypeOf']}
52+
{assertFunctionNames: ['expect', 'expectTypeOf', 'verify']}
4953
],
5054

5155
'@typescript-eslint/prefer-function-type': 'error',

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
node_modules
2-
legacy-tests/tmp
32
lib
43
umzug.json
54
.vscode

legacy-tests/.eslintrc.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

legacy-tests/Umzug/constructor.test.js

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)