Skip to content

Commit

Permalink
chore: enhance jest test reliability (#800)
Browse files Browse the repository at this point in the history
* feat: manually set new mongo db server per test setup

instead of relying on @shelf/mongodb

* fix(temp): use isolatedModules in ts-jest

`isolatedModules` being set to true will fix a memory leak in ts-jest. However, type checking will not be performed whilst running tests (will still have type checking when writing tests).

Revert after the memory leak is fixed.
See kulshekhar/ts-jest#1967
See: https://kulshekhar.github.io/ts-jest/user/config/isolatedModules

* ref: use mongodb-memory-server-core instead of mongodb-memory-server

* chore(tests): inline mongo memory server generation

* chore: remove unused jest-environment-node dependency
  • Loading branch information
karrui authored Dec 7, 2020
1 parent 3738df4 commit 584dc7a
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 375 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ tmp/
# =======
.localstack

# @shelf/jest-mongodb generated file
# =======
globalConfig.json

# Tests
# =======
coverage/
11 changes: 0 additions & 11 deletions jest-mongodb-config.js

This file was deleted.

17 changes: 9 additions & 8 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
const { defaults: tsJestPreset } = require('ts-jest/presets')

module.exports = {
preset: '@shelf/jest-mongodb',
preset: 'ts-jest',
testMatch: ['**/?(*.)+(spec|test).[t]s?(x)'],
modulePaths: ['<rootDir>'],
testEnvironment: 'node',
testPathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/node_modules/'],
transform: {
// Needed to use @shelf/jest-mongodb preset.
...tsJestPreset.transform,
},
collectCoverageFrom: ['./src/**/*.{ts,js}', '!**/__tests__/**'],
coveragePathIgnorePatterns: ['./node_modules/', './tests'],
coverageReporters: ['lcov', 'text'],
Expand All @@ -17,5 +12,11 @@ module.exports = {
statements: 38, // Increase this percentage as test coverage improves
},
},
testEnvironment: 'node',
globals: {
// Revert when memory leak in ts-jest is fixed.
// See https://github.com/kulshekhar/ts-jest/issues/1967.
'ts-jest': {
isolatedModules: true,
},
},
}
Loading

0 comments on commit 584dc7a

Please sign in to comment.