Skip to content

Commit

Permalink
test(nx-graphql-codegen): migrate tests from jest to vitest (#1174)
Browse files Browse the repository at this point in the history
  • Loading branch information
gperdomor authored Dec 16, 2024
1 parent efb34d2 commit 1e67852
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 36 deletions.
6 changes: 5 additions & 1 deletion packages/nx-set-shas/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
"resolveJsonModule": true
},
"include": ["src/**/*.ts"],
"references": [],
"references": [
{
"path": "../core/tsconfig.lib.json"
}
],
"exclude": [
"vite.config.ts",
"vite.config.mts",
Expand Down
2 changes: 1 addition & 1 deletion plugins/nx-graphql-codegen/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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}'],
ignoredDependencies: ['@graphql-codegen/cli', 'ts-node'],
},
],
Expand Down
4 changes: 2 additions & 2 deletions plugins/nx-graphql-codegen/executors.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"executors": {
"generate": {
"implementation": "./src/executors/generate/executor",
"schema": "./src/executors/generate/schema.json",
"implementation": "./dist/executors/generate/executor",
"schema": "./dist/executors/generate/schema.json",
"description": "The generate command generates the data types corresponding to the graphql schema"
}
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/nx-graphql-codegen/generators.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"generators": {
"configuration": {
"factory": "./src/generators/configuration/generator",
"schema": "./src/generators/configuration/schema.json",
"factory": "./dist/generators/configuration/generator",
"schema": "./dist/generators/configuration/schema.json",
"description": "Add graphql-code-generator configuration to project"
}
}
Expand Down
9 changes: 0 additions & 9 deletions plugins/nx-graphql-codegen/jest.config.ts

This file was deleted.

4 changes: 3 additions & 1 deletion plugins/nx-graphql-codegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
},
"files": [
"dist",
"!**/*.tsbuildinfo"
"!**/*.tsbuildinfo",
"generators.json",
"executors.json"
]
}
17 changes: 7 additions & 10 deletions plugins/nx-graphql-codegen/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,16 @@
"input": "./plugins/nx-graphql-codegen/src",
"glob": "**/*.d.ts",
"output": "."
},
{
"input": "./plugins/nx-graphql-codegen",
"glob": "generators.json",
"output": "."
},
{
"input": "./plugins/nx-graphql-codegen",
"glob": "executors.json",
"output": "."
}
]
}
},
"test": {
"executor": "@nx/vite:test",
"outputs": ["{options.reportsDirectory}"],
"options": {
"reportsDirectory": "../../coverage/plugins/nx-graphql-codegen"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import { ExecutorContext } from '@nx/devkit';
import executor from './executor';
import { GenerateExecutorSchema } from './schema';

jest.mock('@nx-tools/core', () => {
const originalModule = jest.requireActual('@nx-tools/core');
vi.mock('@nx-tools/core', async (importOriginal) => {
return {
__esModule: true,
...originalModule,
getExecOutput: jest.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })),
...(await importOriginal<typeof import('@nx-tools/core')>()),
getExecOutput: vi.fn(async () => Promise.resolve({ stderr: '', exitCode: 0 })),
};
});

Expand All @@ -26,7 +24,7 @@ export const expectCommandToHaveBeenCalled = (cmd: string, args: string[]) => {

describe('Generate Executor', () => {
beforeEach(() => {
jest.spyOn(console, 'info').mockImplementation(() => true);
vi.spyOn(console, 'info').mockImplementation(() => true);
});

it('can run with empty options', async () => {
Expand Down
15 changes: 14 additions & 1 deletion plugins/nx-graphql-codegen/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,18 @@
"path": "../../packages/core/tsconfig.lib.json"
}
],
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
"exclude": [
"vite.config.ts",
"vite.config.mts",
"vitest.config.ts",
"vitest.config.mts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx"
]
}
20 changes: 17 additions & 3 deletions plugins/nx-graphql-codegen/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./out-tsc/jest",
"types": ["jest", "node"]
"outDir": "./out-tsc/vitest",
"types": ["vitest/globals", "vitest/importMeta", "vite/client", "node", "vitest"]
},
"include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"],
"include": [
"vite.config.ts",
"vite.config.mts",
"vitest.config.ts",
"vitest.config.mts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/**/*.d.ts"
],
"references": [
{
"path": "./tsconfig.lib.json"
Expand Down
19 changes: 19 additions & 0 deletions plugins/nx-graphql-codegen/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { defineConfig } from 'vite';

export default defineConfig({
root: __dirname,
cacheDir: '../../node_modules/.vite/plugins/nx-graphql-codegen',
plugins: [],
// Uncomment this if you are using workers.
// worker: {
// plugins: [ nxViteTsPaths() ],
// },
test: {
watch: false,
globals: true,
environment: 'jsdom',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
reporters: ['default'],
coverage: { reportsDirectory: '../../coverage/plugins/nx-graphql-codegen', provider: 'v8' },
},
});

0 comments on commit 1e67852

Please sign in to comment.