Skip to content
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

Migrate RTK test suite from Jest to Vitest #3102

Merged
merged 8 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
- name: Install build artifact
run: yarn workspace @reduxjs/toolkit add $(pwd)/package.tgz

- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json ./jest.config.js ./src/tests/*.* ./src/query/tests/*.*
- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json ./vitest.config.ts ./src/tests/*.* ./src/query/tests/*.*

- name: Run tests, against dist
run: yarn test
Expand Down Expand Up @@ -121,7 +121,7 @@ jobs:
- name: Install build artifact
run: yarn add ./package.tgz

- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json ./jest.config.js ./src/tests/*.* ./src/query/tests/*.*
- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json ./vitest.config.ts ./src/tests/*.* ./src/query/tests/*.*

- name: Test types
run: |
Expand Down
41 changes: 41 additions & 0 deletions .yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
diff --git a/src/index.js b/src/index.js
index 90ff7fa3d7d4fa62dbbf638958ae4e28abd089a8..28434687b5163b7472e86bdb11bed69e0868e660 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,4 +1,4 @@
-import { mockConsole, createConsole } from './pure';
+import { mockConsole, createConsole } from './pure.js';

// Keep an instance of the original console and export it
const originalConsole = global.console;
diff --git a/src/pure.js b/src/pure.js
index b00ea2abbaea833e336676aa46e7ced2d59d6d88..42b83ed83fa16cf2234571500fe09868debd9f01 100644
--- a/src/pure.js
+++ b/src/pure.js
@@ -228,10 +228,11 @@ export function restore() {
global.console = global.originalConsole;
}

+/*
if (typeof expect === 'function' && typeof expect.extend === 'function') {
expect.extend({
toMatchInlineSnapshot(received, ...args) {
- /* ------- Workaround for custom inline snapshot matchers ------- */
+ // Workaround for custom inline snapshot matchers
const error = new Error();
const stacks = error.stack.split('\n');

@@ -245,7 +246,6 @@ if (typeof expect === 'function' && typeof expect.extend === 'function') {
error.stack = stacks.join('\n');

const context = Object.assign(this, { error });
- /* -------------------------------------------------------------- */

const testingConsoleInstance =
(received && received.testingConsole) || received;
@@ -270,3 +270,4 @@ if (typeof expect === 'function' && typeof expect.extend === 'function') {
},
});
}
+*/
\ No newline at end of file
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"@babel/helper-compilation-targets": "7.19.3",
"@babel/traverse": "7.19.3",
"@babel/types": "7.19.3",
"console-testing-library": "patch:console-testing-library@npm:0.3.1#.yarn/patches/console-testing-library__npm_0.3.1.patch",
"esbuild": "0.17.0",
"jest-snapshot": "29.3.1",
"msw": "patch:msw@npm:0.40.2#.yarn/patches/msw-npm-0.40.2-2107d48752",
"jscodeshift": "0.13.1",
"react-redux": "npm:8.0.2",
Expand All @@ -63,7 +63,8 @@
"docs/react-dom": "npm:17.0.2",
"docs/@types/react-dom": "npm:17.0.11",
"docs/@types/react": "npm:17.0.11",
"type-fest": "2.19.0"
"type-fest": "2.19.0",
"console-testing-library@0.6.1": "patch:console-testing-library@npm%3A0.6.1#./.yarn/patches/console-testing-library-npm-0.6.1-4d9957d402.patch"
},
"scripts": {
"build": "yarn build:packages",
Expand Down
3 changes: 2 additions & 1 deletion packages/rtk-query-codegen-openapi/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const { resolve } = require('path');

const tsConfigPath = resolve('./test/tsconfig');
const tsConfigPath = resolve('./test/tsconfig.json');

/** @typedef {import('ts-jest/dist/types')} */
/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
rootDir: './test',
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
preset: 'ts-jest',
globals: {
'ts-jest': {
tsconfig: tsConfigPath,
Expand Down
4 changes: 2 additions & 2 deletions packages/rtk-query-codegen-openapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
"esbuild": "~0.17",
"esbuild-runner": "^2.2.1",
"husky": "^4.3.6",
"jest": "^27",
"jest": "^29",
"msw": "^0.40.2",
"openapi-types": "^9.1.0",
"pretty-quick": "^3.1.0",
"ts-jest": "^27",
"ts-jest": "^29",
"ts-node": "^10.4.0",
"yalc": "^1.0.0-pre.47"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/rtk-query-codegen-openapi/test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Done

expect(fromTs).toEqual(fromJs);
expect(fromJson).toEqual(fromJs);
}, 25000);
}, 120000);

test('missing parameters doesnt fail', async () => {
const out = await cli([`./config.invalid-example.json`], __dirname);
Expand Down
1 change: 1 addition & 0 deletions packages/rtk-query-codegen-openapi/test/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-ignore
global.fetch = require('node-fetch');
const { format } = require('prettier');
const { server } = require('./mocks/server');
Expand Down
1 change: 1 addition & 0 deletions packages/rtk-query-codegen-openapi/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"lib": ["es2019"],
"paths": {
"@/*": ["./test/fixtures/*"],
"@rtk-query/codegen-openapi": ["./src"]
Expand Down
22 changes: 0 additions & 22 deletions packages/toolkit/jest.config.js

This file was deleted.

8 changes: 4 additions & 4 deletions packages/toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"axios": "^0.19.2",
"console-testing-library": "^0.3.1",
"console-testing-library": "0.6.1",
"convert-source-map": "^1.7.0",
"esbuild": "~0.17",
"eslint": "^7.25.0",
Expand All @@ -75,7 +75,7 @@
"eslint-plugin-react-hooks": "^4.2.0",
"fs-extra": "^9.1.0",
"invariant": "^2.2.4",
"jest": "^27",
"jsdom": "^21.0.0",
"json-stringify-safe": "^5.0.1",
"magic-string": "^0.25.7",
"merge-source-map": "^1.1.0",
Expand All @@ -89,10 +89,10 @@
"size-limit": "^4.11.0",
"source-map": "^0.7.3",
"terser": "^5.6.1",
"ts-jest": "^27",
"tslib": "^1.10.0",
"tsx": "^3.12.2",
"typescript": "~4.9",
"vitest": "^0.27.2",
"yargs": "^15.3.1"
},
"scripts": {
Expand All @@ -104,7 +104,7 @@
"format": "prettier --write \"(src|examples)/**/*.{ts,tsx}\" \"**/*.md\"",
"format:check": "prettier --list-different \"(src|examples)/**/*.{ts,tsx}\" \"docs/*/**.md\"",
"lint": "eslint src examples",
"test": "jest --runInBand",
"test": "vitest",
"type-tests": "yarn tsc -p src/tests/tsconfig.typetests.json && yarn tsc -p src/query/tests/tsconfig.typetests.json",
"prepack": "npm run build-prepare"
},
Expand Down
Loading