Skip to content

Commit

Permalink
Test Environment Improvements
Browse files Browse the repository at this point in the history
Motivation: 
* update the launch.json: remove windows-specific program
* update CI.yml to run test script
* jest.setupfiles.ts to help log unhandledRejections
  • Loading branch information
rgomezp authored and jkasten2 committed Jul 25, 2023
1 parent 00ca3ec commit 5ce9715
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
continue-on-error: true
run: yarn lint
- name: "[Test] Run all jest tests"
run: yarn jest
run: yarn test
6 changes: 1 addition & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@
"request": "launch",
"name": "Jest: current file",
//"env": { "NODE_ENV": "test" },
"program": "${workspaceFolder}/node_modules/.bin/jest",
"program": "${workspaceFolder}/node_modules/jest/bin/jest --detectOpenHandles --runInBand --unhandled-rejections=strict",
"args": ["${fileBasenameNoExtension}", "--config", "jest.config.js"],
"console": "integratedTerminal",
"disableOptimisticBPs": true,
"runtimeExecutable": "/Users/rodrigo/.nvm/versions/node/v14.20.1/bin/node",
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
}
}
]
}
3 changes: 3 additions & 0 deletions __test__/jest/jest.setupfiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
process.on('unhandledRejection', (reason, p) => {
console.log('jest.setupfiles.ts: unhandledRejection: Unhandled Rejection at: Promise', p, 'reason:', reason);
});
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ module.exports = async () => {
return {
verbose: true,
preset: "ts-jest",
forceExit: true,
bail: true,
testEnvironment: "jsdom",
// Run these files after jest has been
// installed in the environment
setupFilesAfterEnv: ["<rootDir>/__test__/jest/jest.setup.ts"], // use .js if you prefer JavaScript,
setupFiles: ["jest-localstorage-mock", "<rootDir>/__test__/jest/jest.setupfiles.ts"],
resetMocks: false,
// hide type errors: https://stackoverflow.com/questions/73687337/disable-type-checking-stopped-working-after-ts-jest-upgrade-to-29-0
globals: {
'ts-jest': {
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
"build:dev": "ENV=development yarn transpile:sources && ENV=development yarn bundle-sw && ENV=development yarn bundle-sdk && ENV=development yarn bundle-page-sdk-es6 && ENV=development build/scripts/publish.sh",
"build:staging": "ENV=staging yarn transpile:sources && ENV=staging yarn bundle-sw && ENV=staging yarn bundle-sdk && ENV=staging yarn bundle-page-sdk-es6 && ENV=staging build/scripts/publish.sh",
"build:prod": "ENV=production yarn transpile:sources && ENV=production yarn bundle-sw && ENV=production yarn bundle-sdk && ENV=production yarn bundle-page-sdk-es6 && bundlesize && ENV=production build/scripts/publish.sh",
"test": "yarn run jest",
"test:noWatch": "ENV=development yarn transpile:tests && ava --verbose --color --watch=false",
"test:CI": "ENV=development yarn transpile:tests && ava --config ava-ci-config.js --verbose --color --watch=false",
"test": "NODE_OPTIONS=\"--trace-warnings --unhandled-rejections=warn\" yarn run jest --detectOpenHandles --forceExit --runInBand",
"publish": "yarn clean && yarn build:prod && yarn",
"build:dev-dev": "./build/scripts/build.sh -f development -t development",
"build:dev-prod": "./build/scripts/build.sh -f development -t production",
Expand Down Expand Up @@ -82,6 +80,7 @@
"imports-loader": "^0.7.1",
"jest": "^29.0.1",
"jest-environment-jsdom": "^29.4.1",
"jest-localstorage-mock": "^2.4.26",
"jsdom": "^21.1.0",
"md5-file": "^3.2.2",
"nock": "^9.1.6",
Expand Down

0 comments on commit 5ce9715

Please sign in to comment.