Skip to content

[wip] migrate graphql-language-service-server to vitest #3834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 91 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
f590ae4
aa
dimaMachina Dec 11, 2024
810b0b2
aa
dimaMachina Dec 11, 2024
8066724
aa
dimaMachina Dec 11, 2024
4039e39
aa
dimaMachina Dec 11, 2024
4b7e458
aa
dimaMachina Dec 11, 2024
777eac5
aa
dimaMachina Dec 11, 2024
3786aca
aa
dimaMachina Dec 11, 2024
e1260f4
aa
dimaMachina Dec 11, 2024
1c5c46f
aa
dimaMachina Dec 11, 2024
16424ae
aa
dimaMachina Dec 11, 2024
dae03ba
aa
dimaMachina Dec 11, 2024
e1b3cc5
aa
dimaMachina Dec 11, 2024
67a2250
aa
dimaMachina Dec 11, 2024
2be769b
[skip ci]
dimaMachina Dec 13, 2024
785c103
fix
dimaMachina Dec 13, 2024
9a0a3cd
migrate `graphiql` from `jest` to `vitest`
dimaMachina Dec 13, 2024
a862023
add .js extension
dimaMachina Dec 13, 2024
3f3472a
add .js extension
dimaMachina Dec 13, 2024
5fd2901
Merge branch 'do-not-bundle-codemirror' into graphiql-vitest
dimaMachina Dec 13, 2024
be801e4
upd
dimaMachina Dec 13, 2024
398b087
upd
dimaMachina Dec 13, 2024
a337e82
Merge branch 'do-not-bundle-codemirror' into graphiql-vitest
dimaMachina Dec 13, 2024
731082d
upd
dimaMachina Dec 13, 2024
f69cd78
upd
dimaMachina Dec 13, 2024
ce223e3
upd
dimaMachina Dec 13, 2024
6f6f481
upd
dimaMachina Dec 13, 2024
a04d46d
upd
dimaMachina Dec 13, 2024
1be7078
Merge branch 'do-not-bundle-codemirror' into react-compiler
dimaMachina Dec 13, 2024
adf7725
Merge branch 'graphiql-vitest' into react-compiler
dimaMachina Dec 13, 2024
d6f62d4
upd
dimaMachina Dec 13, 2024
3ecae05
upd
dimaMachina Dec 13, 2024
8092f10
upd
dimaMachina Dec 13, 2024
ab2fec8
add
dimaMachina Dec 13, 2024
63bb7b4
upd
dimaMachina Dec 14, 2024
25129f5
upd
dimaMachina Dec 14, 2024
d2fb423
upd
dimaMachina Dec 14, 2024
1968198
upd
dimaMachina Dec 14, 2024
d7e2434
upd
dimaMachina Dec 14, 2024
57348be
upd
dimaMachina Dec 14, 2024
b28be43
upd
dimaMachina Dec 14, 2024
3546a58
upd
dimaMachina Dec 14, 2024
cc537f6
clean up deps
dimaMachina Dec 14, 2024
4031182
clean up deps
dimaMachina Dec 14, 2024
1878a0b
clean up deps
dimaMachina Dec 14, 2024
7453fe4
clean up deps
dimaMachina Dec 14, 2024
63674ed
clean up deps
dimaMachina Dec 14, 2024
dfb7578
upd
dimaMachina Dec 14, 2024
4993c1c
upd
dimaMachina Dec 14, 2024
12cd0b6
more changes from graphiql v4
dimaMachina Dec 14, 2024
1b91371
more
dimaMachina Dec 14, 2024
2f829f8
fix path isn't exported
dimaMachina Dec 14, 2024
4a23084
fix integration tests
dimaMachina Dec 14, 2024
6e95096
fix e2e
dimaMachina Dec 14, 2024
948fef0
bump
dimaMachina Dec 14, 2024
8c34ceb
add changeset
dimaMachina Dec 14, 2024
8410fed
remove unneeded beforeDevServer.js
dimaMachina Dec 14, 2024
d89dc49
found case which was not optimized
dimaMachina Dec 14, 2024
346a936
Merge branch 'main' into react-compiler2
dimaMachina Dec 14, 2024
460b51e
Delete .changeset/sour-onions-rhyme.md
dimaMachina Dec 14, 2024
42f65cc
Delete .changeset/silly-nails-double.md
dimaMachina Dec 14, 2024
65778d2
Merge branch 'main' into react-compiler2
dimaMachina Dec 14, 2024
d4d9062
polish graphiql tests setup
dimaMachina Dec 14, 2024
107e0b6
polish graphiql tests setup
dimaMachina Dec 14, 2024
22c4e7a
upd
dimaMachina Dec 14, 2024
dc8a6a5
upd
dimaMachina Dec 14, 2024
935cd6c
upd
dimaMachina Dec 14, 2024
130ee12
more
dimaMachina Dec 14, 2024
7f2fa66
more
dimaMachina Dec 14, 2024
20fa910
more
dimaMachina Dec 14, 2024
5d93679
more
dimaMachina Dec 14, 2024
009f8d8
more
dimaMachina Dec 14, 2024
403de21
more
dimaMachina Dec 14, 2024
79a5061
more
dimaMachina Dec 14, 2024
13304f0
more [skip ci]
dimaMachina Dec 14, 2024
69f401d
more [skip ci]
dimaMachina Dec 14, 2024
f252dcd
more
dimaMachina Dec 14, 2024
f5742e9
more
dimaMachina Dec 14, 2024
b60581e
more
dimaMachina Dec 14, 2024
05b8540
rm
dimaMachina Dec 14, 2024
fbca258
rm
dimaMachina Dec 14, 2024
0dc6f86
rm
dimaMachina Dec 14, 2024
439e7a5
rm babel
dimaMachina Dec 14, 2024
2c9d960
rm
dimaMachina Dec 14, 2024
a88a00b
rollback
dimaMachina Dec 14, 2024
c080231
fix build
dimaMachina Dec 14, 2024
8cc4fcf
Merge branch 'main' into react-compiler2
dimaMachina Dec 14, 2024
e0949ac
should be good
dimaMachina Dec 14, 2024
ad75cda
prettier
dimaMachina Dec 14, 2024
fe75b41
Merge branch 'react-compiler2' into gls-server
dimaMachina Dec 14, 2024
75b6457
fix ci
dimaMachina Dec 14, 2024
21d467d
polish
dimaMachina Dec 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/sour-onions-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'codemirror-graphql': minor
'graphiql': minor
---

migrate `graphiql` from `jest` to `vitest`
8 changes: 7 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,13 @@ module.exports = {
},
{
// Rule for ignoring imported dependencies from tests files
files: ['**/__tests__/**', 'webpack.config.js', '**/tests/**'],
files: [
'**/__tests__/**',
'webpack.config.js',
'**/tests/**',
'test.config.js',
'vitest.config.mts',
],
rules: {
'import-x/no-extraneous-dependencies': 'off',
},
Expand Down
7 changes: 1 addition & 6 deletions jest.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,14 @@ module.exports = (dir, env = 'jsdom') => {
coverageDirectory: `${__dirname}/coverage/jest`,
setupFilesAfterEnv,
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'identity-obj-proxy',
'\\.(css|less)$': 'identity-obj-proxy',
'\\.css$': 'identity-obj-proxy',
'^graphql-language-service-([^/]+)': `${__dirname}/packages/graphql-language-service/src/$1`,
'^graphql-language-([^/]+)': `${__dirname}/packages/graphql-language-$1/src`,
'^@graphiql\\/([^/]+)': `${__dirname}/packages/graphiql-$1/src`,
'^@graphiql-plugins\\/([^/]+)': `${__dirname}/plugins/$1/src`,
'^codemirror-graphql\\/esm([^]+)\\.js': `${__dirname}/packages/codemirror-graphql/src/$1`,
'^codemirror-graphql\\/cjs([^]+)': `${__dirname}/packages/codemirror-graphql/src/$1`,
// relies on compilation
'^cm6-graphql\\/src\\/([^]+)': `${__dirname}/packages/cm6-graphql/dist/$1`,
'^example-([^/]+)': `${__dirname}/examples/$1/src`,
'^-!svg-react-loader.*$': '<rootDir>/resources/jest/svgImportMock.js',
// because of the svelte compiler's export patterns i guess?
'svelte/compiler': `${__dirname}/node_modules/svelte/compiler.cjs`,
},
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
"@manypkg/get-packages": "^1.1.3",
"@shopify/eslint-plugin": "^45.0.0",
"@strictsoftware/typedoc-plugin-monorepo": "^0.3.1",
"@testing-library/jest-dom": "5.16.5",
"@types/codemirror": "^0.0.90",
"@types/express": "^4.17.11",
"@types/fetch-mock": "^7.3.2",
Expand Down Expand Up @@ -138,7 +137,7 @@
"ts-jest": "^27.1.5",
"typedoc": "^0.19.2",
"typescript": "^4.6.3",
"vitest": "^2.0.5",
"vitest": "^2.1.8",
"wgutils": "^0.1.7",
"wsrun": "^5.2.4"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/codemirror-graphql/src/hint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

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

import { FragmentDefinitionNode, GraphQLSchema, GraphQLType } from 'graphql';
import type {
Expand Down
4 changes: 3 additions & 1 deletion packages/graphiql-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@
},
"devDependencies": {
"babel-plugin-react-compiler": "19.0.0-beta-37ed2a7-20241206",
"@types/react-dom": "^18.3.1",
"@babel/helper-string-parser": "^7.19.4",
"@testing-library/react": "14.0.0",
"@testing-library/dom": "^10.4.0",
"@testing-library/react": "^16.1.0",
"@types/markdown-it": "^14.1.2",
"@types/get-value": "^3.0.5",
"@types/set-value": "^4.0.1",
Expand Down
3 changes: 2 additions & 1 deletion packages/graphiql-react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"jsx": "react-jsx",
"declaration": true,
"declarationDir": "types",
"outDir": "tsc"
"outDir": "tsc",
"types": ["jest", "@testing-library/jest-dom"]
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
Expand Down
12 changes: 1 addition & 11 deletions packages/graphiql/__mocks__/codemirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ function CodeMirror(node: HTMLElement, { value, ...options }) {
node.append(mockWrapper);

function _emit(event, data) {
if (_eventListeners[event]) {
_eventListeners[event](data);
}
_eventListeners[event]?.(data);
}

return {
Expand All @@ -30,11 +28,9 @@ function CodeMirror(node: HTMLElement, { value, ...options }) {
linterOptions: {},
},
},

on(event, handler) {
_eventListeners[event] = handler;
},

off(event) {
if (!Object.prototype.hasOwnProperty.call(_eventListeners, event)) {
return;
Expand All @@ -47,29 +43,23 @@ function CodeMirror(node: HTMLElement, { value, ...options }) {
}
_eventListeners = updatedEventListeners;
},

getValue() {
return mockTextArea.value;
},

setValue(newValue) {
mockTextArea.value = newValue;
},
addKeyMap() {},
removeKeyMap() {},
setOption() {},
refresh() {},
setSize() {},

emit: _emit,
};
}

CodeMirror.defineExtension = () => {};
CodeMirror.registerHelper = () => {};
CodeMirror.defineOption = () => {};
CodeMirror.defineMode = () => {};

CodeMirror.signal = (mockCodeMirror, event, ...args) => {
mockCodeMirror.emit(event, ...args);
};
Expand Down
7 changes: 0 additions & 7 deletions packages/graphiql/__mocks__/svg.jsx

This file was deleted.

9 changes: 0 additions & 9 deletions packages/graphiql/jest.config.js

This file was deleted.

8 changes: 4 additions & 4 deletions packages/graphiql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"dev": "cross-env NODE_ENV=development webpack-dev-server --config resources/webpack.config.js",
"e2e": "yarn e2e-server 'cypress run'",
"e2e-server": "start-server-and-test 'cross-env PORT=8080 node test/e2e-server' 'http-get://localhost:8080/graphql?query={test { id }}'",
"webpack": "webpack-cli --config resources/webpack.config.js"
"webpack": "webpack-cli --config resources/webpack.config.js",
"test": "vitest"
},
"dependencies": {
"@graphiql/react": "^0.27.0"
Expand All @@ -56,9 +57,8 @@
},
"devDependencies": {
"@graphiql/toolkit": "^0.11.0",
"@testing-library/jest-dom": "5.16.5",
"@testing-library/react": "14.0.0",
"@types/testing-library__jest-dom": "5.14.5",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.1.0",
"babel-loader": "^9.1.2",
"babel-plugin-macros": "^3.1.0",
"cross-env": "^7.0.2",
Expand Down
22 changes: 13 additions & 9 deletions packages/graphiql/postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
module.exports = ({ options, webpackLoaderContext }) => ({
plugins: {
// https://github.com/postcss/postcss-import/issues/442#issuecomment-822427606
'postcss-import': { root: webpackLoaderContext.context },
// contains autoprefixer, etc
'postcss-preset-env': options['postcss-preset-env'] || false,
cssnano: process.env.NODE_ENV === 'production' ? options.cssnano : false,
},
});
module.exports =
process.env.NODE_ENV === 'test'
? {}
: ({ options, webpackLoaderContext }) => ({
plugins: {
// https://github.com/postcss/postcss-import/issues/442#issuecomment-822427606
'postcss-import': { root: webpackLoaderContext.context },
// contains autoprefixer, etc
'postcss-preset-env': options['postcss-preset-env'] || false,
cssnano:
process.env.NODE_ENV === 'production' ? options.cssnano : false,
},
});
15 changes: 15 additions & 0 deletions packages/graphiql/setup-files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import '@testing-library/jest-dom';

// @ts-expect-error
document.createRange = function () {
return {
setEnd() {},
setStart() {},
getClientRects() {
return { top: 0, bottom: 0, left: 0, right: 0 };
},
getBoundingClientRect() {
return { right: 0 };
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import '@testing-library/jest-dom';
import { act, render, waitFor, fireEvent } from '@testing-library/react';
import React from 'react';
import { GraphiQL } from '../GraphiQL';
import React, { Component } from 'react';
import { GraphiQL } from './GraphiQL';
import { Fetcher } from '@graphiql/toolkit';
import { ToolbarButton } from '@graphiql/react';

Expand Down Expand Up @@ -37,7 +36,7 @@ describe('GraphiQL', () => {

describe('fetcher', () => {
it('should throw error without fetcher', () => {
const spy = jest.spyOn(console, 'error').mockImplementation(() => {});
const spy = vi.spyOn(console, 'error').mockImplementation(() => {});

// @ts-expect-error fetcher is a required prop to GraphiQL
expect(() => render(<GraphiQL />)).toThrow(
Expand Down Expand Up @@ -273,13 +272,12 @@ describe('GraphiQL', () => {
describe('panel resizing', () => {
it('readjusts the query wrapper flex style field when the result panel is resized', async () => {
// Mock the drag bar width
const clientWidthSpy = jest
const clientWidthSpy = vi
.spyOn(Element.prototype, 'clientWidth', 'get')
.mockReturnValue(0);
// Mock the container width
const boundingClientRectSpy = jest
const boundingClientRectSpy = vi
.spyOn(Element.prototype, 'getBoundingClientRect')
// @ts-expect-error missing properties from type 'DOMRect'
.mockReturnValue({ left: 0, right: 900 });

const { container } = render(<GraphiQL fetcher={noOpFetcher} />);
Expand Down Expand Up @@ -312,13 +310,12 @@ describe('GraphiQL', () => {

it('allows for resizing the doc explorer correctly', async () => {
// Mock the drag bar width
const clientWidthSpy = jest
const clientWidthSpy = vi
.spyOn(Element.prototype, 'clientWidth', 'get')
.mockReturnValue(0);
// Mock the container width
const boundingClientRectSpy = jest
const boundingClientRectSpy = vi
.spyOn(Element.prototype, 'getBoundingClientRect')
// @ts-expect-error missing properties from type 'DOMRect'
.mockReturnValue({ left: 0, right: 1200 });

const { container } = render(<GraphiQL fetcher={noOpFetcher} />);
Expand Down Expand Up @@ -529,10 +526,10 @@ describe('GraphiQL', () => {

it('properly ignores fragments', async () => {
const myFragment = (
<React.Fragment>
<>
<MyFunctionalComponent />
<MyFunctionalComponent />
</React.Fragment>
</>
);

const { container, getByRole } = render(
Expand Down Expand Up @@ -566,7 +563,7 @@ describe('GraphiQL', () => {

it('properly ignores non-override class components', async () => {
// eslint-disable-next-line react/prefer-stateless-function
class MyClassComponent extends React.Component {
class MyClassComponent extends Component {
render() {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql/src/cdn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import * as GraphiQLReact from '@graphiql/react';
import { createGraphiQLFetcher, createLocalStorage } from '@graphiql/toolkit';
import * as GraphQL from 'graphql';
import { GraphiQL } from './components/GraphiQL';
import { GraphiQL } from './GraphiQL';

import '@graphiql/react/font/roboto.css';
import '@graphiql/react/font/fira-code.css';
Expand Down
11 changes: 2 additions & 9 deletions packages/graphiql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,7 @@ export { GraphiQLProvider } from '@graphiql/react';
/**
* Definitions
*/
export type {
GraphiQLProps,
GraphiQLInterfaceProps,
} from './components/GraphiQL';
export type { GraphiQLProps, GraphiQLInterfaceProps } from './GraphiQL';
export type { GraphiQLProviderProps } from '@graphiql/react';

export {
GraphiQLInterface,
GraphiQL,
GraphiQL as default,
} from './components/GraphiQL';
export { GraphiQLInterface, GraphiQL, GraphiQL as default } from './GraphiQL';
12 changes: 3 additions & 9 deletions packages/graphiql/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@
"composite": false,
"jsx": "react",
"baseUrl": ".",
"target": "es5"
"target": "es5",
"types": ["@testing-library/jest-dom", "vitest/globals"]
},
"include": ["src"],
"exclude": [
"**/__tests__/**",
"**/dist/**.*",
"**/*.spec.ts",
"**/*.spec.js",
"**/*-test.ts",
"**/*-test.js"
],
"exclude": ["**/*.spec.tsx"],
"references": [
{
"path": "../codemirror-graphql"
Expand Down
5 changes: 3 additions & 2 deletions packages/graphiql/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
"composite": true,
"jsx": "react",
"target": "es5",
"strictPropertyInitialization": false
"strictPropertyInitialization": false,
"types": ["@testing-library/jest-dom", "vitest/globals"]
},
"include": ["src"],
"exclude": ["**/__tests__/**", "**/dist/**.*", "cypress/**"],
"exclude": ["**/*.spec.tsx"],
"references": [
{
"path": "../codemirror-graphql"
Expand Down
30 changes: 30 additions & 0 deletions packages/graphiql/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import path from 'node:path';
import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';

const mockedCodemirror = path.resolve('__mocks__', 'codemirror.ts');

export default defineConfig({
plugins: [react()],
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['./setup-files.ts'],
alias: {
'codemirror/addon/edit/matchbrackets.js': mockedCodemirror,
'codemirror/addon/hint/show-hint.js': mockedCodemirror,
'codemirror/addon/edit/closebrackets.js': mockedCodemirror,
'codemirror/addon/fold/brace-fold.js': mockedCodemirror,
'codemirror/addon/fold/foldgutter.js': mockedCodemirror,
'codemirror/addon/lint/lint.js': mockedCodemirror,
'codemirror/addon/search/searchcursor.js': mockedCodemirror,
'codemirror/addon/search/jump-to-line.js': mockedCodemirror,
'codemirror/addon/dialog/dialog.js': mockedCodemirror,
'codemirror/keymap/sublime.js': mockedCodemirror,
'codemirror/mode/javascript/javascript.js': mockedCodemirror,
'codemirror/addon/comment/comment.js': mockedCodemirror,
'codemirror/addon/search/search.js': mockedCodemirror,
codemirror: mockedCodemirror,
},
},
});
Loading