Skip to content

Commit

Permalink
chore: setup jest for use with Typescript tests (#106)
Browse files Browse the repository at this point in the history
* chore: add ts-jest and dependencies

* chore: expand tsconfig to `test` directory

* chore: add jest config and script to run Typescript tests

* chore: improve import sort linting autogrouping

* tests: convert submission.server.model tests to Typescript

* chore: add jest-mongodb present to jest setup

This allows for use of mongodb without any setting up or tearing down of mongodb between tests

* test: migrate myinfo service test to Typescript

* feat: remove usage of spec in db-handler

* build: add specific tsconfig for building that ignores tests

* chore: add jest-mongodb-config and migrate SmsCountModel tests

With this, we can eventually stop using `npm run download-binary` and delete `tests/end-to-end/helpers/get-mongo-binary.js` since the config automatically retrieves that information for us.

* chore: add documentation to gitignore

* fix: check mongoose MD5 binary when starting jest tests

* refactor: convert form_fields schema tests to Typescript
  • Loading branch information
karrui authored Aug 11, 2020
1 parent 1d2ee6b commit 56e9b89
Show file tree
Hide file tree
Showing 40 changed files with 4,319 additions and 2,460 deletions.
20 changes: 19 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,25 @@ module.exports = {
plugins: ['@typescript-eslint', 'import', 'simple-import-sort'],
rules: {
// Rules for auto sort of imports
'simple-import-sort/sort': 'error',
'simple-import-sort/sort': [
'error',
{
groups: [
// Side effect imports.
['^\\u0000'],
// Packages.
// Things that start with a letter (or digit or underscore), or
// `@` followed by a letter.
['^@?\\w'],
// Root imports
['^(src)(/.*|$)'],
// Parent imports. Put `..` last.
['^\\.\\.(?!/?$)', '^\\.\\./?$'],
// Other relative imports. Put same-folder imports and `.` last.
['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'],
],
},
],
'sort-imports': 'off',
'import/order': 'off',
'import/first': 'error',
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@ tmp/
!.elasticbeanstalk/*.global.yml

# Localstack
# =======
.localstack

# @shelf/jest-mongodb generated file
# =======
globalConfig.json
12 changes: 12 additions & 0 deletions jest-mongodb-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
mongodbMemoryServerOptions: {
binary: {
version: process.env.MONGO_BINARY_VERSION || '3.6.12',
checkMD5: true,
},
instance: {
dbName: 'jest',
},
autoStart: false,
},
}
12 changes: 12 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { defaults: tsJestPreset } = require('ts-jest/presets')

module.exports = {
preset: '@shelf/jest-mongodb',
testEnvironment: 'node',
testMatch: ['**/?(*.)+(spec|test).[t]s?(x)'],
modulePaths: ['<rootDir>'],
transform: {
// Needed to use @shelf/jest-mongodb preset.
...tsJestPreset.transform,
},
}
Loading

0 comments on commit 56e9b89

Please sign in to comment.