-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AC-1743] pt. 2.5 ⮕ Fix the unit tests for good (#398)
* Remove uneeded redirects to a tsconfig.spec.json * Got the tests running again * Delete webCryptoFunctionService * Delete unused utils tests * Add a test workflow
- Loading branch information
1 parent
d1cb92b
commit 39ed935
Showing
27 changed files
with
90 additions
and
1,300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
name: Run tests | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- "main" | ||
- "rc" | ||
- "hotfix-rc-*" | ||
pull_request: {} | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
jobs: | ||
test: | ||
name: Run tests | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 | ||
|
||
- name: Get Node Version | ||
id: retrieve-node-version | ||
run: | | ||
NODE_NVMRC=$(cat .nvmrc) | ||
NODE_VERSION=${NODE_NVMRC/v/''} | ||
echo "node_version=$NODE_VERSION" >> $GITHUB_OUTPUT | ||
- name: Set up Node | ||
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 | ||
with: | ||
cache: 'npm' | ||
cache-dependency-path: '**/package-lock.json' | ||
node-version: ${{ steps.retrieve-node-version.outputs.node_version }} | ||
|
||
- name: Print environment | ||
run: | | ||
node --version | ||
npm --version | ||
- name: Install Node dependencies | ||
run: npm ci | ||
|
||
# We use isolatedModules: true which disables typechecking in tests | ||
# Tests in apps/ are typechecked when their app is built, so we just do it here for libs/ | ||
# See https://bitwarden.atlassian.net/browse/EC-497 | ||
- name: Run typechecking | ||
run: npm run test:types --coverage | ||
|
||
- name: Run tests | ||
run: npm run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,42 @@ | ||
const { pathsToModuleNameMapper } = require("ts-jest"); | ||
|
||
const { compilerOptions } = require("./tsconfig"); | ||
|
||
/** @type {import('jest').Config} */ | ||
const tsPreset = require("ts-jest/jest-preset"); | ||
const angularPreset = require("jest-preset-angular/jest-preset"); | ||
const { defaultTransformerOptions } = require("jest-preset-angular/presets"); | ||
|
||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
reporters: ["default", "jest-junit"], | ||
// ...tsPreset, | ||
// ...angularPreset, | ||
preset: "jest-preset-angular", | ||
|
||
collectCoverage: true, | ||
coverageReporters: ["html", "lcov"], | ||
coverageDirectory: "coverage", | ||
testEnvironment: "jsdom", | ||
testMatch: ["**/+(*.)+(spec).+(ts)"], | ||
|
||
moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, { | ||
prefix: "<rootDir>/", | ||
}), | ||
projects: [ | ||
"<rootDir>/jslib/angular/jest.config.js", | ||
"<rootDir>/jslib/common/jest.config.js", | ||
"<rootDir>/jslib/electron/jest.config.js", | ||
"<rootDir>/jslib/node/jest.config.js", | ||
], | ||
roots: ["<rootDir>"], | ||
modulePaths: [compilerOptions.baseUrl], | ||
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: "<rootDir>/" }), | ||
setupFilesAfterEnv: ["<rootDir>/test.setup.ts"], | ||
|
||
// Workaround for a memory leak that crashes tests in CI: | ||
// https://github.com/facebook/jest/issues/9430#issuecomment-1149882002 | ||
// Also anecdotally improves performance when run locally | ||
maxWorkers: 3, | ||
|
||
transform: { | ||
"^.+\\.tsx?$": [ | ||
"jest-preset-angular", | ||
// 'ts-jest', | ||
{ | ||
...defaultTransformerOptions, | ||
tsconfig: "./tsconfig.json", | ||
// Further workaround for memory leak, recommended here: | ||
// https://github.com/kulshekhar/ts-jest/issues/1967#issuecomment-697494014 | ||
// Makes tests run faster and reduces size/rate of leak, but loses typechecking on test code | ||
// See https://bitwarden.atlassian.net/browse/EC-497 for more info | ||
isolatedModules: true, | ||
}, | ||
], | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.