Skip to content

Commit 1730b3f

Browse files
authored
Migrate to Vitest (#10410)
* Install vitest * Set up vitest config * Install tsconfigPaths * Set up root vite config * Set up vitest project for typescript-resolvers * Set up vitest for plugins-helpers and fix ESM test * Set up client preset vitest project * Prepare for vitest.setup.ts * Set up vitest for graphql-modules-preset * Set up vitest for typescript plugin * Set up vitest for typed-document-node * Set up vitest for typescript-operations * Set up vitest for gql-tag-operations * Set up vitest in typescript-document-nodes * Set up vitest for visitor-plugin-common * Set up vitest for time plugin * Set up vitest for schema-ast plugin * Set up vitest for introspection plugin * Set up vitest for fragment-matcher plugin * Set up vitest for add * Set up vitest for graphql-codegen-core * Install memfs to support fs testing * Set up test config for cli * Fix init tests * Set up vitest for graphql-codegen-testing * Update linting rules for test files * Fix cli-* specs * Handle cwd mocking for CLI command * Fix cjs vs esm issues in codegen.spec * Fix config.spec * Fix watcher.spec and trim down the mocks * Migrate rest of examples to vitest * By jest things. Not even jesting 🤡 * Fix cache jest -> vitest * Fix lint issues and unncessary disables * Fix vitest spec * Fix test and generated things in examples * Fix vitest things
1 parent d7c6bfb commit 1730b3f

File tree

160 files changed

+1807
-2373
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+1807
-2373
lines changed

.eslintrc.cjs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ module.exports = {
1414
'@typescript-eslint/explicit-function-return-type': 'off',
1515
'@typescript-eslint/ban-ts-ignore': 'off',
1616
'@typescript-eslint/ban-types': 'off',
17-
'import/no-extraneous-dependencies': [
18-
'error',
19-
{ devDependencies: ['**/*.test.ts', '**/*.spec.ts', '**/test/**/*.ts'] },
20-
],
17+
'import/no-extraneous-dependencies': 'error',
2118

2219
// todo: enable
2320
'unicorn/filename-case': 'off',
@@ -36,12 +33,17 @@ module.exports = {
3633
extends: '@theguild/eslint-config/react',
3734
},
3835
{
39-
files: ['**/tests/**/*.{js,ts,tsx}', '**/graphql-codegen-testing/**/*.ts', '*.spec.ts'],
40-
env: {
41-
jest: true,
42-
},
36+
files: [
37+
'*.spec.ts',
38+
'**/tests/**/*.{js,ts,tsx,cjs}',
39+
'**/graphql-codegen-testing/**/*.ts',
40+
'**/vitest.config.ts',
41+
'**/vitest.setup.ts',
42+
'**/__mocks__/*',
43+
],
4344
rules: {
4445
'import/no-extraneous-dependencies': 'off',
46+
'@typescript-eslint/no-require-imports': 'off',
4547
},
4648
},
4749
{
@@ -57,7 +59,7 @@ module.exports = {
5759
},
5860
},
5961
{
60-
files: ['scripts/*.{ts,js}', 'prettier.config.cjs', 'jest.config.js', 'jest.project.js'],
62+
files: ['scripts/*.{ts,js}', 'prettier.config.cjs'],
6163
rules: {
6264
'@typescript-eslint/no-require-imports': 'off',
6365
},

.github/workflows/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ jobs:
146146
run: node ./scripts/match-graphql.js ${{matrix.graphql_version}}
147147
- name: Install Dependencies
148148
run: yarn
149-
- name: Cache Jest
149+
- name: Cache Vitest
150150
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4
151151
with:
152-
path: .cache/jest
153-
key: ${{runner.os}}-${{matrix.node_version}}-${{matrix.graphql_version}}-jest-${{hashFiles('yarn.lock')}}
152+
path: node_modules/.vite
153+
key: ${{runner.os}}-${{matrix.node_version}}-${{matrix.graphql_version}}-vitest-${{hashFiles('yarn.lock')}}
154154
restore-keys: |
155-
${{runner.os}}-${{matrix.node_version}}-${{matrix.graphql_version}}-jest-
155+
${{runner.os}}-${{matrix.node_version}}-${{matrix.graphql_version}}-vitest-
156156
- name: Build
157157
run: yarn build
158158
- name: Test

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "Run open test file",
66
"type": "node",
77
"request": "launch",
8-
"runtimeArgs": ["--inspect-brk", "${workspaceRoot}/node_modules/.bin/jest", "--runInBand", "${relativeFile}"],
8+
"runtimeArgs": ["--inspect-brk", "${workspaceRoot}/node_modules/.bin/vitest", "--runInBand", "${relativeFile}"],
99
"console": "integratedTerminal",
1010
"internalConsoleOptions": "neverOpen"
1111
}

examples/persisted-documents-string-mode/codegen.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// eslint-disable-next-line import/no-extraneous-dependencies
21
import { type CodegenConfig } from '@graphql-codegen/cli';
32

43
const config: CodegenConfig = {

examples/persisted-documents-string-mode/jest.config.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/persisted-documents-string-mode/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
},
99
"devDependencies": {
1010
"@graphql-typed-document-node/core": "3.2.0",
11-
"jest": "28.1.3",
12-
"babel-jest": "29.7.0",
1311
"@graphql-codegen/cli": "5.0.7",
1412
"@babel/core": "7.25.2",
1513
"@babel/preset-env": "7.25.3",
1614
"@babel/preset-typescript": "7.26.0"
1715
},
1816
"scripts": {
19-
"test": "jest",
17+
"test": "vitest --no-watch",
2018
"codegen": "graphql-codegen --config codegen.ts",
2119
"build": "tsc",
2220
"test:end2end": "yarn test"

examples/persisted-documents-string-mode/src/yoga.spec.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, expect } from 'vitest';
12
import { graphql } from './gql/index';
23
import { makeYoga } from './yoga';
34
import persistedDocumentsDictionary from './gql/persisted-documents.json';
@@ -24,8 +25,8 @@ describe('Persisted Documents', () => {
2425
}),
2526
});
2627
expect(await result.json()).toMatchInlineSnapshot(`
27-
Object {
28-
"data": Object {
28+
{
29+
"data": {
2930
"hello": "Hello world!",
3031
},
3132
}
@@ -46,9 +47,9 @@ describe('Persisted Documents', () => {
4647
}),
4748
});
4849
expect(await result.json()).toMatchInlineSnapshot(`
49-
Object {
50-
"errors": Array [
51-
Object {
50+
{
51+
"errors": [
52+
{
5253
"message": "PersistedQueryOnly",
5354
},
5455
],
@@ -75,8 +76,8 @@ describe('Persisted Documents', () => {
7576
});
7677

7778
expect(await result.json()).toMatchInlineSnapshot(`
78-
Object {
79-
"data": Object {
79+
{
80+
"data": {
8081
"hello": "Hello world!",
8182
},
8283
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineProject, mergeConfig } from 'vitest/config';
2+
import { sharedConfig } from '../../vitest.config.js';
3+
4+
export default mergeConfig(
5+
sharedConfig,
6+
defineProject({
7+
test: {
8+
name: 'examples-persisted-documents-string-mode',
9+
include: ['**/*.spec.ts'],
10+
},
11+
})
12+
);

examples/persisted-documents/codegen.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// eslint-disable-next-line import/no-extraneous-dependencies
21
import { type CodegenConfig } from '@graphql-codegen/cli';
32

43
const config: CodegenConfig = {

examples/persisted-documents/jest.config.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)