Skip to content

Commit

Permalink
test(nx-container): migrate tests from jest to vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
gperdomor committed Dec 16, 2024
1 parent 823e4a0 commit 8e6a708
Show file tree
Hide file tree
Showing 19 changed files with 402 additions and 318 deletions.
180 changes: 118 additions & 62 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"jest-environment-jsdom": "29.7.0",
"jest-environment-node": "29.7.0",
"lint-staged": "15.2.10",
"mocked-env": "1.3.5",
"memfs": "4.15.0",
"nx": "20.2.2",
"prettier": "2.8.8",
"ts-jest": "29.2.4",
Expand Down
5 changes: 5 additions & 0 deletions plugins/nx-container/__mocks__/node:fs.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// we can also use `import`, but then
// every export should be explicitly defined

const { fs } = require('memfs');
module.exports = fs;
6 changes: 5 additions & 1 deletion plugins/nx-container/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ module.exports = [
'@nx/dependency-checks': [
'error',
{
ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'],
ignoredFiles: [
'{projectRoot}/eslint.config.{js,cjs,mjs}',
'{projectRoot}/vite.config.{js,ts,mjs,mts}',
'{projectRoot}/__mocks__/*',
],
ignoredDependencies: ['dotenv', '@nx-tools/container-metadata'],
},
],
Expand Down
9 changes: 0 additions & 9 deletions plugins/nx-container/jest.config.ts

This file was deleted.

7 changes: 7 additions & 0 deletions plugins/nx-container/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
}
]
}
},
"test": {
"executor": "@nx/vite:test",
"outputs": ["{options.reportsDirectory}"],
"options": {
"reportsDirectory": "../../coverage/plugins/nx-container"
}
}
}
}
12 changes: 5 additions & 7 deletions plugins/nx-container/src/executors/build/context.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,18 @@ PejgXO0uIRolYQ3sz2tMGhx1MfBqH64=
=WbwB
-----END PGP PRIVATE KEY BLOCK-----`;

jest.mock('./context', () => {
const originalModule = jest.requireActual('./context');
vi.mock('./context', async (importOriginal) => {
return {
__esModule: true,
...originalModule,
defaultContext: jest.fn(() => 'https://github.com/docker/build-push-action.git#refs/heads/test-jest'),
tmpDir: jest.fn(() => {
...(await importOriginal<typeof import('./context')>()),
defaultContext: vi.fn(() => 'https://github.com/docker/build-push-action.git#refs/heads/test-jest'),
tmpDir: vi.fn(() => {
const tmpDir = path.join('/tmp/.docker-build-push-jest').split(path.sep).join(path.posix.sep);
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir, { recursive: true });
}
return tmpDir;
}),
tmpNameSync: jest.fn(() =>
tmpNameSync: vi.fn(() =>
path.join('/tmp/.docker-build-push-jest', '.tmpname-jest').split(path.sep).join(path.posix.sep)
),
};
Expand Down
Loading

0 comments on commit 8e6a708

Please sign in to comment.