Skip to content

Commit 7cdcabf

Browse files
authored
[2/3] [v3] migrate graphiql from jest to vitest (#3825)
* [skip ci] * fix * migrate `graphiql` from `jest` to `vitest` * add .js extension * add .js extension * upd * upd * upd * upd * upd * upd
1 parent 72f06bc commit 7cdcabf

23 files changed

+284
-274
lines changed

.changeset/sour-onions-rhyme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'codemirror-graphql': minor
3+
'graphiql': minor
4+
---
5+
6+
migrate `graphiql` from `jest` to `vitest`

.eslintrc.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,13 @@ module.exports = {
424424
},
425425
{
426426
// Rule for ignoring imported dependencies from tests files
427-
files: ['**/__tests__/**', 'webpack.config.js', '**/tests/**'],
427+
files: [
428+
'**/__tests__/**',
429+
'webpack.config.js',
430+
'**/tests/**',
431+
'test.config.js',
432+
'vitest.config.mts',
433+
],
428434
rules: {
429435
'import-x/no-extraneous-dependencies': 'off',
430436
},

jest.config.base.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,14 @@ module.exports = (dir, env = 'jsdom') => {
1717
coverageDirectory: `${__dirname}/coverage/jest`,
1818
setupFilesAfterEnv,
1919
moduleNameMapper: {
20-
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
21-
'identity-obj-proxy',
22-
'\\.(css|less)$': 'identity-obj-proxy',
20+
'\\.css$': 'identity-obj-proxy',
2321
'^graphql-language-service-([^/]+)': `${__dirname}/packages/graphql-language-service/src/$1`,
2422
'^graphql-language-([^/]+)': `${__dirname}/packages/graphql-language-$1/src`,
2523
'^@graphiql\\/([^/]+)': `${__dirname}/packages/graphiql-$1/src`,
26-
'^@graphiql-plugins\\/([^/]+)': `${__dirname}/plugins/$1/src`,
2724
'^codemirror-graphql\\/esm([^]+)\\.js': `${__dirname}/packages/codemirror-graphql/src/$1`,
2825
'^codemirror-graphql\\/cjs([^]+)': `${__dirname}/packages/codemirror-graphql/src/$1`,
2926
// relies on compilation
3027
'^cm6-graphql\\/src\\/([^]+)': `${__dirname}/packages/cm6-graphql/dist/$1`,
31-
'^example-([^/]+)': `${__dirname}/examples/$1/src`,
32-
'^-!svg-react-loader.*$': '<rootDir>/resources/jest/svgImportMock.js',
3328
// because of the svelte compiler's export patterns i guess?
3429
'svelte/compiler': `${__dirname}/node_modules/svelte/compiler.cjs`,
3530
},

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
"@manypkg/get-packages": "^1.1.3",
9797
"@shopify/eslint-plugin": "^45.0.0",
9898
"@strictsoftware/typedoc-plugin-monorepo": "^0.3.1",
99-
"@testing-library/jest-dom": "5.16.5",
10099
"@types/codemirror": "^0.0.90",
101100
"@types/express": "^4.17.11",
102101
"@types/fetch-mock": "^7.3.2",
@@ -137,7 +136,7 @@
137136
"ts-jest": "^27.1.5",
138137
"typedoc": "^0.19.2",
139138
"typescript": "^4.6.3",
140-
"vitest": "^2.0.5",
139+
"vitest": "^2.1.8",
141140
"wgutils": "^0.1.7",
142141
"wsrun": "^5.2.4"
143142
},

packages/codemirror-graphql/src/hint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212
import CodeMirror, { Hints, Hint } from 'codemirror';
13-
import 'codemirror/addon/hint/show-hint';
13+
import 'codemirror/addon/hint/show-hint.js';
1414

1515
import { FragmentDefinitionNode, GraphQLSchema, GraphQLType } from 'graphql';
1616
import type {

packages/graphiql-react/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@
6666
"set-value": "^4.1.0"
6767
},
6868
"devDependencies": {
69+
"@types/react-dom": "^18.3.1",
6970
"@babel/helper-string-parser": "^7.19.4",
70-
"@testing-library/react": "14.0.0",
71+
"@testing-library/dom": "^10.4.0",
72+
"@testing-library/react": "^16.1.0",
7173
"@types/markdown-it": "^14.1.2",
7274
"@types/get-value": "^3.0.5",
7375
"@types/set-value": "^4.0.1",

packages/graphiql-react/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"jsx": "react-jsx",
1717
"declaration": true,
1818
"declarationDir": "types",
19-
"outDir": "tsc"
19+
"outDir": "tsc",
20+
"types": ["jest", "@testing-library/jest-dom"]
2021
},
2122
"include": ["src"],
2223
"references": [{ "path": "./tsconfig.node.json" }]

packages/graphiql/__mocks__/codemirror.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ function CodeMirror(node: HTMLElement, { value, ...options }) {
1313
node.append(mockWrapper);
1414

1515
function _emit(event, data) {
16-
if (_eventListeners[event]) {
17-
_eventListeners[event](data);
18-
}
16+
_eventListeners[event]?.(data);
1917
}
2018

2119
return {
@@ -30,11 +28,9 @@ function CodeMirror(node: HTMLElement, { value, ...options }) {
3028
linterOptions: {},
3129
},
3230
},
33-
3431
on(event, handler) {
3532
_eventListeners[event] = handler;
3633
},
37-
3834
off(event) {
3935
if (!Object.prototype.hasOwnProperty.call(_eventListeners, event)) {
4036
return;
@@ -47,29 +43,23 @@ function CodeMirror(node: HTMLElement, { value, ...options }) {
4743
}
4844
_eventListeners = updatedEventListeners;
4945
},
50-
5146
getValue() {
5247
return mockTextArea.value;
5348
},
54-
5549
setValue(newValue) {
5650
mockTextArea.value = newValue;
5751
},
5852
addKeyMap() {},
5953
removeKeyMap() {},
6054
setOption() {},
6155
refresh() {},
62-
setSize() {},
63-
6456
emit: _emit,
6557
};
6658
}
6759

68-
CodeMirror.defineExtension = () => {};
6960
CodeMirror.registerHelper = () => {};
7061
CodeMirror.defineOption = () => {};
7162
CodeMirror.defineMode = () => {};
72-
7363
CodeMirror.signal = (mockCodeMirror, event, ...args) => {
7464
mockCodeMirror.emit(event, ...args);
7565
};

packages/graphiql/__mocks__/svg.jsx

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

packages/graphiql/jest.config.js

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

0 commit comments

Comments
 (0)