Skip to content

Commit

Permalink
migrate graphiql-toolkit to vitest (#3748)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina committed Aug 23, 2024
1 parent 21c4409 commit b40f77c
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ module.exports = {
'unicorn/prefer-node-protocol': 'error',
'import-x/no-unresolved': [
'error',
{ ignore: ['^node:', '\\.svg\\?react$'] },
{ ignore: ['^node:', '\\.svg\\?react$', 'vitest/config'] },
],
'no-extra-boolean-cast': [
'error',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"ts-jest": "^27.1.5",
"typedoc": "^0.19.2",
"typescript": "^4.6.3",
"vitest": "^2.0.4",
"vitest": "^2.0.5",
"wgutils": "^0.1.7",
"wsrun": "^5.2.4"
},
Expand Down
5 changes: 0 additions & 5 deletions packages/graphiql-toolkit/jest.config.js

This file was deleted.

3 changes: 2 additions & 1 deletion packages/graphiql-toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"build": "tsup",
"dev": "tsup --watch",
"prebuild": "yarn types:check",
"types:check": "tsc --noEmit"
"types:check": "tsc --noEmit",
"test": "vitest run"
},
"dependencies": {
"@n1ru4l/push-pull-async-iterable-iterator": "^3.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { vi } from 'vitest';
import { parse, getIntrospectionQuery } from 'graphql';
import { createGraphiQLFetcher } from '../createFetcher';

import 'isomorphic-fetch';

jest.mock('../lib');
vi.mock('../lib');

jest.mock('graphql-ws');
vi.mock('graphql-ws');

jest.mock('subscriptions-transport-ws');
vi.mock('subscriptions-transport-ws');

import {
createWebsocketsFetcherFromUrl,
Expand All @@ -26,7 +27,7 @@ const exampleIntrospectionDocument = parse(getIntrospectionQuery());

describe('createGraphiQLFetcher', () => {
afterEach(() => {
jest.resetAllMocks();
vi.resetAllMocks();
});
it('returns fetcher without websocket client by default', () => {
createWebsocketsFetcherFromUrl.mockReturnValue(true);
Expand Down
24 changes: 16 additions & 8 deletions packages/graphiql-toolkit/src/create-fetcher/__tests__/lib.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { vi } from 'vitest';
import { parse } from 'graphql';
import {
isSubscriptionWithName,
Expand All @@ -7,9 +8,9 @@ import {

import 'isomorphic-fetch';

jest.mock('graphql-ws');
vi.mock('graphql-ws');

jest.mock('subscriptions-transport-ws');
vi.mock('subscriptions-transport-ws');

import { createClient } from 'graphql-ws';

Expand Down Expand Up @@ -44,7 +45,7 @@ describe('isSubscriptionWithName', () => {

describe('createWebsocketsFetcherFromUrl', () => {
afterEach(() => {
jest.resetAllMocks();
vi.resetAllMocks();
});

it('creates a websockets client using provided url', async () => {
Expand All @@ -64,7 +65,7 @@ describe('createWebsocketsFetcherFromUrl', () => {

describe('getWsFetcher', () => {
afterEach(() => {
jest.resetAllMocks();
vi.resetAllMocks();
});
it('provides an observable wsClient when custom wsClient option is provided', async () => {
createClient.mockReturnValue(true);
Expand Down Expand Up @@ -92,10 +93,17 @@ describe('getWsFetcher', () => {

describe('missing `graphql-ws` dependency', () => {
it('should throw a nice error', async () => {
jest.resetModules();
jest.doMock('graphql-ws', () => {
// eslint-disable-next-line no-throw-literal
throw { code: 'MODULE_NOT_FOUND' };
vi.resetModules();
vi.doMock('graphql-ws', () => {
// While throwing an error directly inside this callback `code` is attached in `cause`
// property e.g. `Error.cause.code`, so I throw an error on calling `createClient` instead

return {
createClient: vi.fn().mockImplementation(() => {
// eslint-disable-next-line no-throw-literal
throw { code: 'MODULE_NOT_FOUND' };
}),
};
});

await expect(
Expand Down
4 changes: 2 additions & 2 deletions packages/graphiql-toolkit/src/storage/__tests__/base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('StorageAPI', () => {
});
const result = throwingStorage.set('key', 'value');

expect(result.error.message).toEqual('Terrible Error');
expect(result.error!.message).toEqual('Error: Terrible Error');
expect(result.isQuotaError).toBe(false);
});

Expand All @@ -93,7 +93,7 @@ describe('StorageAPI', () => {
});
const result = throwingStorage.set('key', 'value');

expect(result.error.message).toEqual('Terrible Error');
expect(result.error!.message).toEqual('QuotaExceededError: Terrible Error');
expect(result.isQuotaError).toBe(true);
});
});
3 changes: 2 additions & 1 deletion packages/graphiql-toolkit/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"skipLibCheck": true,
"allowJs": true,
"lib": ["es2022", "dom"],
"moduleResolution": "node"
"moduleResolution": "node",
"types": ["vitest/globals"]
},
"include": ["src", "tsup.config.ts"],
"exclude": ["**/*.spec.ts"]
Expand Down
8 changes: 8 additions & 0 deletions packages/graphiql-toolkit/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
globals: true,
environment: 'jsdom',
},
});
1 change: 0 additions & 1 deletion packages/monaco-graphql/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line import-x/no-unresolved -- todo: try to fix better rather ignoring here?
import { defineConfig } from 'vitest/config';

export default defineConfig({
Expand Down
1 change: 0 additions & 1 deletion packages/vscode-graphql-syntax/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line import-x/no-unresolved -- fix later
import { defineConfig } from 'vitest/config';

export default defineConfig({
Expand Down
88 changes: 44 additions & 44 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5122,53 +5122,53 @@
"@types/babel__core" "^7.20.5"
react-refresh "^0.14.2"

"@vitest/expect@2.0.4":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@vitest/expect/-/expect-2.0.4.tgz#d365c106c84f2a3aae96000e95be21956acc099c"
integrity sha512-39jr5EguIoanChvBqe34I8m1hJFI4+jxvdOpD7gslZrVQBKhh8H9eD7J/LJX4zakrw23W+dITQTDqdt43xVcJw==
"@vitest/expect@2.0.5":
version "2.0.5"
resolved "https://registry.yarnpkg.com/@vitest/expect/-/expect-2.0.5.tgz#f3745a6a2c18acbea4d39f5935e913f40d26fa86"
integrity sha512-yHZtwuP7JZivj65Gxoi8upUN2OzHTi3zVfjwdpu2WrvCZPLwsJ2Ey5ILIPccoW23dd/zQBlJ4/dhi7DWNyXCpA==
dependencies:
"@vitest/spy" "2.0.4"
"@vitest/utils" "2.0.4"
"@vitest/spy" "2.0.5"
"@vitest/utils" "2.0.5"
chai "^5.1.1"
tinyrainbow "^1.2.0"

"@vitest/pretty-format@2.0.4", "@vitest/pretty-format@^2.0.4":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@vitest/pretty-format/-/pretty-format-2.0.4.tgz#9a3934932e7f8ddd836b38c34ddaeec91bd0f82e"
integrity sha512-RYZl31STbNGqf4l2eQM1nvKPXE0NhC6Eq0suTTePc4mtMQ1Fn8qZmjV4emZdEdG2NOWGKSCrHZjmTqDCDoeFBw==
"@vitest/pretty-format@2.0.5", "@vitest/pretty-format@^2.0.5":
version "2.0.5"
resolved "https://registry.yarnpkg.com/@vitest/pretty-format/-/pretty-format-2.0.5.tgz#91d2e6d3a7235c742e1a6cc50e7786e2f2979b1e"
integrity sha512-h8k+1oWHfwTkyTkb9egzwNMfJAEx4veaPSnMeKbVSjp4euqGSbQlm5+6VHwTr7u4FJslVVsUG5nopCaAYdOmSQ==
dependencies:
tinyrainbow "^1.2.0"

"@vitest/runner@2.0.4":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@vitest/runner/-/runner-2.0.4.tgz#0b1edb8ab5f81a1c7dfd50090e5e7e971a117891"
integrity sha512-Gk+9Su/2H2zNfNdeJR124gZckd5st4YoSuhF1Rebi37qTXKnqYyFCd9KP4vl2cQHbtuVKjfEKrNJxHHCW8thbQ==
"@vitest/runner@2.0.5":
version "2.0.5"
resolved "https://registry.yarnpkg.com/@vitest/runner/-/runner-2.0.5.tgz#89197e712bb93513537d6876995a4843392b2a84"
integrity sha512-TfRfZa6Bkk9ky4tW0z20WKXFEwwvWhRY+84CnSEtq4+3ZvDlJyY32oNTJtM7AW9ihW90tX/1Q78cb6FjoAs+ig==
dependencies:
"@vitest/utils" "2.0.4"
"@vitest/utils" "2.0.5"
pathe "^1.1.2"

"@vitest/snapshot@2.0.4":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@vitest/snapshot/-/snapshot-2.0.4.tgz#7d7dea9df17c5c13386f1a7a433b99dc0ffe3c14"
integrity sha512-or6Mzoz/pD7xTvuJMFYEtso1vJo1S5u6zBTinfl+7smGUhqybn6VjzCDMhmTyVOFWwkCMuNjmNNxnyXPgKDoPw==
"@vitest/snapshot@2.0.5":
version "2.0.5"
resolved "https://registry.yarnpkg.com/@vitest/snapshot/-/snapshot-2.0.5.tgz#a2346bc5013b73c44670c277c430e0334690a162"
integrity sha512-SgCPUeDFLaM0mIUHfaArq8fD2WbaXG/zVXjRupthYfYGzc8ztbFbu6dUNOblBG7XLMR1kEhS/DNnfCZ2IhdDew==
dependencies:
"@vitest/pretty-format" "2.0.4"
"@vitest/pretty-format" "2.0.5"
magic-string "^0.30.10"
pathe "^1.1.2"

"@vitest/spy@2.0.4":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@vitest/spy/-/spy-2.0.4.tgz#19083386a741a158c2f142beffe43be68b1375cf"
integrity sha512-uTXU56TNoYrTohb+6CseP8IqNwlNdtPwEO0AWl+5j7NelS6x0xZZtP0bDWaLvOfUbaYwhhWp1guzXUxkC7mW7Q==
"@vitest/spy@2.0.5":
version "2.0.5"
resolved "https://registry.yarnpkg.com/@vitest/spy/-/spy-2.0.5.tgz#590fc07df84a78b8e9dd976ec2090920084a2b9f"
integrity sha512-c/jdthAhvJdpfVuaexSrnawxZz6pywlTPe84LUB2m/4t3rl2fTo9NFGBG4oWgaD+FTgDDV8hJ/nibT7IfH3JfA==
dependencies:
tinyspy "^3.0.0"

"@vitest/utils@2.0.4":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@vitest/utils/-/utils-2.0.4.tgz#2db1df35aaeb5caa932770a190df636a68d284d5"
integrity sha512-Zc75QuuoJhOBnlo99ZVUkJIuq4Oj0zAkrQ2VzCqNCx6wAwViHEh5Fnp4fiJTE9rA+sAoXRf00Z9xGgfEzV6fzQ==
"@vitest/utils@2.0.5":
version "2.0.5"
resolved "https://registry.yarnpkg.com/@vitest/utils/-/utils-2.0.5.tgz#6f8307a4b6bc6ceb9270007f73c67c915944e926"
integrity sha512-d8HKbqIcya+GR67mkZbrzhS5kKhtp8dQLcmRZLGTscGVg7yImT82cIrhtn2L8+VujWcy6KZweApgNmPsTAO/UQ==
dependencies:
"@vitest/pretty-format" "2.0.4"
"@vitest/pretty-format" "2.0.5"
estree-walker "^3.0.3"
loupe "^3.1.1"
tinyrainbow "^1.2.0"
Expand Down Expand Up @@ -18411,10 +18411,10 @@ vinyl@^1.1.1:
clone-stats "^0.0.1"
replace-ext "0.0.1"

vite-node@2.0.4:
version "2.0.4"
resolved "https://registry.yarnpkg.com/vite-node/-/vite-node-2.0.4.tgz#5600cc9f0d9c3ff9a64050c6858e7e1b62fb3fcd"
integrity sha512-ZpJVkxcakYtig5iakNeL7N3trufe3M6vGuzYAr4GsbCTwobDeyPJpE4cjDhhPluv8OvQCFzu2LWp6GkoKRITXA==
vite-node@2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/vite-node/-/vite-node-2.0.5.tgz#36d909188fc6e3aba3da5fc095b3637d0d18e27b"
integrity sha512-LdsW4pxj0Ot69FAoXZ1yTnA9bjGohr2yNBU7QKRxpz8ITSkhuDl6h3zS/tvgz4qrNjeRnvrWeXQ8ZF7Um4W00Q==
dependencies:
cac "^6.7.14"
debug "^4.3.5"
Expand Down Expand Up @@ -18447,18 +18447,18 @@ vite@^5.0.0, vite@^5.3.5:
optionalDependencies:
fsevents "~2.3.3"

vitest@^2.0.4:
version "2.0.4"
resolved "https://registry.yarnpkg.com/vitest/-/vitest-2.0.4.tgz#ac6bfbaee53e502cee864b07a5b2edf1fcba793e"
integrity sha512-luNLDpfsnxw5QSW4bISPe6tkxVvv5wn2BBs/PuDRkhXZ319doZyLOBr1sjfB5yCEpTiU7xCAdViM8TNVGPwoog==
vitest@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/vitest/-/vitest-2.0.5.tgz#2f15a532704a7181528e399cc5b754c7f335fd62"
integrity sha512-8GUxONfauuIdeSl5f9GTgVEpg5BTOlplET4WEDaeY2QBiN8wSm68vxN/tb5z405OwppfoCavnwXafiaYBC/xOA==
dependencies:
"@ampproject/remapping" "^2.3.0"
"@vitest/expect" "2.0.4"
"@vitest/pretty-format" "^2.0.4"
"@vitest/runner" "2.0.4"
"@vitest/snapshot" "2.0.4"
"@vitest/spy" "2.0.4"
"@vitest/utils" "2.0.4"
"@vitest/expect" "2.0.5"
"@vitest/pretty-format" "^2.0.5"
"@vitest/runner" "2.0.5"
"@vitest/snapshot" "2.0.5"
"@vitest/spy" "2.0.5"
"@vitest/utils" "2.0.5"
chai "^5.1.1"
debug "^4.3.5"
execa "^8.0.1"
Expand All @@ -18469,7 +18469,7 @@ vitest@^2.0.4:
tinypool "^1.0.0"
tinyrainbow "^1.2.0"
vite "^5.0.0"
vite-node "2.0.4"
vite-node "2.0.5"
why-is-node-running "^2.3.0"

vsce@^2.6.3:
Expand Down

0 comments on commit b40f77c

Please sign in to comment.