From 02819c5ec63e07e726345987528ca557c777a5aa Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Fri, 23 Aug 2024 22:43:44 +0200 Subject: [PATCH 1/2] aa --- .eslintrc.js | 2 +- package.json | 2 +- packages/graphiql-toolkit/jest.config.js | 5 -- packages/graphiql-toolkit/package.json | 3 +- .../__tests__/buildFetcher.spec.ts | 9 +- .../src/create-fetcher/__tests__/lib.spec.ts | 24 +++-- .../src/storage/__tests__/base.spec.ts | 4 +- packages/graphiql-toolkit/tsconfig.json | 3 +- packages/graphiql-toolkit/vitest.config.mts | 8 ++ packages/monaco-graphql/vitest.config.mts | 1 - .../vscode-graphql-syntax/vitest.config.mts | 1 - yarn.lock | 88 +++++++++---------- 12 files changed, 81 insertions(+), 69 deletions(-) delete mode 100644 packages/graphiql-toolkit/jest.config.js create mode 100644 packages/graphiql-toolkit/vitest.config.mts diff --git a/.eslintrc.js b/.eslintrc.js index 0a9cdf1f0ec..8fb38b34309 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -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', diff --git a/package.json b/package.json index 41f402e9534..aa272db9a91 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/packages/graphiql-toolkit/jest.config.js b/packages/graphiql-toolkit/jest.config.js deleted file mode 100644 index d5f2ae82f35..00000000000 --- a/packages/graphiql-toolkit/jest.config.js +++ /dev/null @@ -1,5 +0,0 @@ -const base = require('../../jest.config.base')(__dirname); - -module.exports = { - ...base, -}; diff --git a/packages/graphiql-toolkit/package.json b/packages/graphiql-toolkit/package.json index 7d5546709f3..77c9f4ced47 100644 --- a/packages/graphiql-toolkit/package.json +++ b/packages/graphiql-toolkit/package.json @@ -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", diff --git a/packages/graphiql-toolkit/src/create-fetcher/__tests__/buildFetcher.spec.ts b/packages/graphiql-toolkit/src/create-fetcher/__tests__/buildFetcher.spec.ts index de2e2a4934d..d6a857370e6 100644 --- a/packages/graphiql-toolkit/src/create-fetcher/__tests__/buildFetcher.spec.ts +++ b/packages/graphiql-toolkit/src/create-fetcher/__tests__/buildFetcher.spec.ts @@ -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, @@ -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); diff --git a/packages/graphiql-toolkit/src/create-fetcher/__tests__/lib.spec.ts b/packages/graphiql-toolkit/src/create-fetcher/__tests__/lib.spec.ts index 921ffcaebf1..9a77f98a492 100644 --- a/packages/graphiql-toolkit/src/create-fetcher/__tests__/lib.spec.ts +++ b/packages/graphiql-toolkit/src/create-fetcher/__tests__/lib.spec.ts @@ -1,3 +1,4 @@ +import { vi } from 'vitest'; import { parse } from 'graphql'; import { isSubscriptionWithName, @@ -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'; @@ -44,7 +45,7 @@ describe('isSubscriptionWithName', () => { describe('createWebsocketsFetcherFromUrl', () => { afterEach(() => { - jest.resetAllMocks(); + vi.resetAllMocks(); }); it('creates a websockets client using provided url', async () => { @@ -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); @@ -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( diff --git a/packages/graphiql-toolkit/src/storage/__tests__/base.spec.ts b/packages/graphiql-toolkit/src/storage/__tests__/base.spec.ts index f47bb386f66..7f0851a76b9 100644 --- a/packages/graphiql-toolkit/src/storage/__tests__/base.spec.ts +++ b/packages/graphiql-toolkit/src/storage/__tests__/base.spec.ts @@ -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); }); @@ -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); }); }); diff --git a/packages/graphiql-toolkit/tsconfig.json b/packages/graphiql-toolkit/tsconfig.json index 9209de32b24..4fcb973a796 100644 --- a/packages/graphiql-toolkit/tsconfig.json +++ b/packages/graphiql-toolkit/tsconfig.json @@ -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"] diff --git a/packages/graphiql-toolkit/vitest.config.mts b/packages/graphiql-toolkit/vitest.config.mts new file mode 100644 index 00000000000..527089358ab --- /dev/null +++ b/packages/graphiql-toolkit/vitest.config.mts @@ -0,0 +1,8 @@ +import { defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + globals: true, + environment: 'jsdom', + }, +}); diff --git a/packages/monaco-graphql/vitest.config.mts b/packages/monaco-graphql/vitest.config.mts index 50d382d83f8..7382f40e7d2 100644 --- a/packages/monaco-graphql/vitest.config.mts +++ b/packages/monaco-graphql/vitest.config.mts @@ -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({ diff --git a/packages/vscode-graphql-syntax/vitest.config.mts b/packages/vscode-graphql-syntax/vitest.config.mts index 3444fdd8e6e..9c294ab69b6 100644 --- a/packages/vscode-graphql-syntax/vitest.config.mts +++ b/packages/vscode-graphql-syntax/vitest.config.mts @@ -1,4 +1,3 @@ -// eslint-disable-next-line import-x/no-unresolved -- fix later import { defineConfig } from 'vitest/config'; export default defineConfig({ diff --git a/yarn.lock b/yarn.lock index cec5bf193f4..b47771846d7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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" @@ -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" @@ -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: From 71db1515fd432a058eca48df1f264abff73e7152 Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Fri, 23 Aug 2024 23:07:34 +0200 Subject: [PATCH 2/2] fix type errors from graphiql-toolkit's tests --- .../__tests__/buildFetcher.spec.ts | 40 +++++++++++++++---- .../src/create-fetcher/__tests__/lib.spec.ts | 19 +++++---- .../src/storage/__tests__/base.spec.ts | 4 +- .../src/storage/__tests__/query.spec.ts | 9 ++++- packages/graphiql-toolkit/tsconfig.json | 3 +- 5 files changed, 56 insertions(+), 19 deletions(-) diff --git a/packages/graphiql-toolkit/src/create-fetcher/__tests__/buildFetcher.spec.ts b/packages/graphiql-toolkit/src/create-fetcher/__tests__/buildFetcher.spec.ts index d6a857370e6..e34ab553061 100644 --- a/packages/graphiql-toolkit/src/create-fetcher/__tests__/buildFetcher.spec.ts +++ b/packages/graphiql-toolkit/src/create-fetcher/__tests__/buildFetcher.spec.ts @@ -1,4 +1,4 @@ -import { vi } from 'vitest'; +import { Mock } from 'vitest'; import { parse, getIntrospectionQuery } from 'graphql'; import { createGraphiQLFetcher } from '../createFetcher'; @@ -11,13 +11,13 @@ vi.mock('graphql-ws'); vi.mock('subscriptions-transport-ws'); import { - createWebsocketsFetcherFromUrl, - createMultipartFetcher, - createSimpleFetcher, - createWebsocketsFetcherFromClient, - createLegacyWebsocketsFetcher, + createWebsocketsFetcherFromUrl as _createWebsocketsFetcherFromUrl, + createMultipartFetcher as _createMultipartFetcher, + createSimpleFetcher as _createSimpleFetcher, + createWebsocketsFetcherFromClient as _createWebsocketsFetcherFromClient, + createLegacyWebsocketsFetcher as _createLegacyWebsocketsFetcher, } from '../lib'; -import { createClient } from 'graphql-ws'; +import { createClient as _createClient } from 'graphql-ws'; import { SubscriptionClient } from 'subscriptions-transport-ws'; const serverURL = 'http://localhost:3000/graphql'; @@ -25,11 +25,30 @@ const wssURL = 'ws://localhost:3000/graphql'; const exampleIntrospectionDocument = parse(getIntrospectionQuery()); +const createWebsocketsFetcherFromUrl = _createWebsocketsFetcherFromUrl as Mock< + typeof _createWebsocketsFetcherFromUrl +>; +const createMultipartFetcher = _createMultipartFetcher as Mock< + typeof _createMultipartFetcher +>; +const createSimpleFetcher = _createSimpleFetcher as Mock< + typeof _createSimpleFetcher +>; +const createClient = _createClient as Mock; +const createWebsocketsFetcherFromClient = + _createWebsocketsFetcherFromClient as Mock< + typeof _createWebsocketsFetcherFromClient + >; +const createLegacyWebsocketsFetcher = _createLegacyWebsocketsFetcher as Mock< + typeof _createLegacyWebsocketsFetcher +>; + describe('createGraphiQLFetcher', () => { afterEach(() => { vi.resetAllMocks(); }); it('returns fetcher without websocket client by default', () => { + // @ts-expect-error createWebsocketsFetcherFromUrl.mockReturnValue(true); createGraphiQLFetcher({ url: serverURL }); expect(createWebsocketsFetcherFromUrl.mock.calls).toEqual([]); @@ -39,6 +58,7 @@ describe('createGraphiQLFetcher', () => { }); it('returns simple fetcher for introspection', async () => { + // @ts-expect-error createSimpleFetcher.mockReturnValue(async () => 'hey!'); const fetcher = createGraphiQLFetcher({ url: serverURL }); expect(createWebsocketsFetcherFromUrl.mock.calls).toEqual([]); @@ -55,6 +75,7 @@ describe('createGraphiQLFetcher', () => { expect(res).toEqual('hey!'); }); it('returns fetcher without websocket client or multipart', () => { + // @ts-expect-error createWebsocketsFetcherFromUrl.mockReturnValue(true); createGraphiQLFetcher({ url: serverURL, enableIncrementalDelivery: false }); expect(createWebsocketsFetcherFromUrl.mock.calls).toEqual([]); @@ -64,6 +85,7 @@ describe('createGraphiQLFetcher', () => { ]); }); it('returns fetcher with websocket client', () => { + // @ts-expect-error createWebsocketsFetcherFromUrl.mockReturnValue('Client1'); const args = { @@ -78,7 +100,9 @@ describe('createGraphiQLFetcher', () => { }); it('returns fetcher with custom wsClient', () => { + // @ts-expect-error createClient.mockReturnValue('WSClient'); + // @ts-expect-error createWebsocketsFetcherFromUrl.mockReturnValue('CustomWSSFetcher'); const wsClient = createClient({ url: wssURL }); @@ -95,7 +119,9 @@ describe('createGraphiQLFetcher', () => { }); it('returns fetcher with custom legacyClient', () => { + // @ts-expect-error createClient.mockReturnValue('WSClient'); + // @ts-expect-error createLegacyWebsocketsFetcher.mockReturnValue('CustomWSSFetcher'); const legacyClient = new SubscriptionClient(wssURL); diff --git a/packages/graphiql-toolkit/src/create-fetcher/__tests__/lib.spec.ts b/packages/graphiql-toolkit/src/create-fetcher/__tests__/lib.spec.ts index 9a77f98a492..8d6b101b1de 100644 --- a/packages/graphiql-toolkit/src/create-fetcher/__tests__/lib.spec.ts +++ b/packages/graphiql-toolkit/src/create-fetcher/__tests__/lib.spec.ts @@ -1,4 +1,4 @@ -import { vi } from 'vitest'; +import { Mock } from 'vitest'; import { parse } from 'graphql'; import { isSubscriptionWithName, @@ -12,9 +12,12 @@ vi.mock('graphql-ws'); vi.mock('subscriptions-transport-ws'); -import { createClient } from 'graphql-ws'; +import { createClient as _createClient } from 'graphql-ws'; -import { SubscriptionClient } from 'subscriptions-transport-ws'; +import { SubscriptionClient as _SubscriptionClient } from 'subscriptions-transport-ws'; + +const createClient = _createClient as Mock; +const SubscriptionClient = _SubscriptionClient as Mock; const exampleWithSubscription = parse(/* GraphQL */ ` subscription Example { @@ -49,16 +52,16 @@ describe('createWebsocketsFetcherFromUrl', () => { }); it('creates a websockets client using provided url', async () => { + // @ts-expect-error createClient.mockReturnValue(true); await createWebsocketsFetcherFromUrl('wss://example.com'); - // @ts-ignore expect(createClient.mock.calls[0][0]).toEqual({ url: 'wss://example.com' }); }); it('creates a websockets client using provided url that fails', async () => { + // @ts-expect-error createClient.mockReturnValue(false); expect(await createWebsocketsFetcherFromUrl('wss://example.com')).toThrow(); - // @ts-ignore expect(createClient.mock.calls[0][0]).toEqual({ url: 'wss://example.com' }); }); }); @@ -68,20 +71,22 @@ describe('getWsFetcher', () => { vi.resetAllMocks(); }); it('provides an observable wsClient when custom wsClient option is provided', async () => { + // @ts-expect-error createClient.mockReturnValue(true); + // @ts-expect-error await getWsFetcher({ url: '', wsClient: true }); - // @ts-ignore expect(createClient.mock.calls).toHaveLength(0); }); it('creates a subscriptions-transports-ws observable when custom legacyClient option is provided', async () => { + // @ts-expect-error createClient.mockReturnValue(true); await getWsFetcher({ url: '', legacyClient: true }); - // @ts-ignore expect(createClient.mock.calls).toHaveLength(0); expect(SubscriptionClient.mock.calls).toHaveLength(0); }); it('if subscriptionsUrl is provided, create a client on the fly', async () => { + // @ts-expect-error createClient.mockReturnValue(true); await getWsFetcher({ url: '', subscriptionUrl: 'wss://example' }); expect(createClient.mock.calls[0]).toEqual([ diff --git a/packages/graphiql-toolkit/src/storage/__tests__/base.spec.ts b/packages/graphiql-toolkit/src/storage/__tests__/base.spec.ts index 7f0851a76b9..376aaf34ff1 100644 --- a/packages/graphiql-toolkit/src/storage/__tests__/base.spec.ts +++ b/packages/graphiql-toolkit/src/storage/__tests__/base.spec.ts @@ -70,7 +70,7 @@ describe('StorageAPI', () => { }); it('returns any error while setting a value', () => { - // @ts-ignore + // @ts-expect-error const throwingStorage = new StorageAPI({ setItem() { throw new DOMException('Terrible Error'); @@ -84,7 +84,7 @@ describe('StorageAPI', () => { }); it('returns isQuotaError to true if isQuotaError is thrown', () => { - // @ts-ignore + // @ts-expect-error const throwingStorage = new StorageAPI({ setItem() { throw new DOMException('Terrible Error', 'QuotaExceededError'); diff --git a/packages/graphiql-toolkit/src/storage/__tests__/query.spec.ts b/packages/graphiql-toolkit/src/storage/__tests__/query.spec.ts index a59f9cdd22c..ddfab64c5b1 100644 --- a/packages/graphiql-toolkit/src/storage/__tests__/query.spec.ts +++ b/packages/graphiql-toolkit/src/storage/__tests__/query.spec.ts @@ -3,9 +3,12 @@ import { QueryStore } from '../query'; class StorageMock { shouldThrow: () => boolean; + // @ts-expect-error count: number; map = {}; + // @ts-expect-error storage: Storage; + constructor(shouldThrow: () => boolean) { this.shouldThrow = shouldThrow; } @@ -19,7 +22,7 @@ class StorageMock { isQuotaError: true, }; } - + // @ts-expect-error this.map[key] = value; return { @@ -29,6 +32,7 @@ class StorageMock { } get(key: string) { + // @ts-expect-error return this.map[key] || null; } } @@ -47,6 +51,7 @@ describe('QueryStore', () => { it('will fail silently on quota error', () => { let i = 0; + // @ts-expect-error const store = new QueryStore('normal', new StorageMock(() => i > 4)); for (; i < 10; i++) { @@ -78,6 +83,7 @@ describe('QueryStore', () => { let retryCounter = 0; const store = new QueryStore( 'normal', + // @ts-expect-error new StorageMock(() => { retryCounter++; return shouldThrow(); @@ -110,6 +116,7 @@ describe('QueryStore', () => { let retryCounter = 0; const store = new QueryStore( 'normal', + // @ts-expect-error new StorageMock(() => { retryCounter++; return shouldThrow(); diff --git a/packages/graphiql-toolkit/tsconfig.json b/packages/graphiql-toolkit/tsconfig.json index 4fcb973a796..db8aa451eeb 100644 --- a/packages/graphiql-toolkit/tsconfig.json +++ b/packages/graphiql-toolkit/tsconfig.json @@ -12,6 +12,5 @@ "moduleResolution": "node", "types": ["vitest/globals"] }, - "include": ["src", "tsup.config.ts"], - "exclude": ["**/*.spec.ts"] + "include": ["src", "tsup.config.ts", "vitest.config.mts"] }