Skip to content

Commit

Permalink
Migrate from Jest to Vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Jan 22, 2024
1 parent 3301501 commit d5f90ca
Show file tree
Hide file tree
Showing 258 changed files with 997 additions and 1,886 deletions.
12 changes: 10 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": ["react", "jest"],
"plugins": ["react"],
"rules": {
"func-names": 0,
"no-continue": 1,
Expand All @@ -43,7 +43,15 @@
},
"overrides": [
{
"files": ["**/*.test.js", "**/tests/**/*.js", "setup.jest.js"],
"files": [
"**/*.test.js",
"**/*.test.jsx",
"**/tests/**/*.js",
"**/tests/**/*.jsx",
"vitest.config.js",
"vitest.*.config.js",
"vitest.setup.js"
],
"rules": {
"import/no-extraneous-dependencies": 0
}
Expand Down
14 changes: 0 additions & 14 deletions jest.config.js

This file was deleted.

14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"bootstrap": "lerna bootstrap",
"prepublish": "lerna run build",
"lint": "eslint packages",
"test": "NODE_OPTIONS=\"--experimental-vm-modules\" jest",
"test": "vitest",
"dev": "lerna run dev --scope @react-pdf/examples",
"changeset": "changeset",
"version-packages": "changeset version",
Expand All @@ -34,32 +34,29 @@
"@babel/preset-react": "^7.18.6",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.0",
"@jest/globals": "^29.5.0",
"@rollup/plugin-alias": "^3.1.8",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.6",
"@rollup/plugin-replace": "^3.0.0",
"@testing-library/react": "^14.0.0",
"@vitejs/plugin-react": "^4.2.1",
"babel-eslint": "^10.0.1",
"babel-jest": "^29.5.0",
"babel-plugin-add-module-exports": "^1.0.0",
"canvas": "^2.11.0",
"chalk": "^2.4.2",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.1.0",
"eslint-config-prettier": "^4.0.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jest": "^22.3.0",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-react": "^7.20.0",
"eslint-plugin-react-hooks": "^2.5.1",
"husky": "^7.0.4",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"jest-image-snapshot": "^6.1.0",
"jsdom": "^23.2.0",
"lerna": "^8.0.2",
"lint-staged": "^10.5.4",
"pdfjs-dist": "3.2.146",
Expand All @@ -73,7 +70,9 @@
"rollup-plugin-local-resolve": "^1.0.7",
"rollup-plugin-polyfill-node": "^0.9.0",
"rollup-plugin-sourcemaps": "^0.6.3",
"rollup-plugin-terser": "^7.0.2"
"rollup-plugin-terser": "^7.0.2",
"vitest": "^1.2.0",
"vitest-fetch-mock": "^0.2.2"
},
"lint-staged": {
"*.js": [
Expand All @@ -86,6 +85,5 @@
"url": "https://opencollective.com/react-pdf",
"logo": "https://opencollective.com/opencollective/logo.txt"
},
"dependencies": {},
"packageManager": "[email protected]"
}
2 changes: 1 addition & 1 deletion packages/fns/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"directory": "packages/fns"
},
"scripts": {
"test": "NODE_OPTIONS=\"--experimental-vm-modules\" jest",
"test": "vitest",
"build": "rimraf ./lib && rollup -c",
"watch": "rimraf ./lib && rollup -c -w"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/fns/tests/adjust.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from 'vitest';

import adjust from '../src/adjust';

Expand Down
2 changes: 1 addition & 1 deletion packages/fns/tests/capitalize.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from 'vitest';

import capitalize from '../src/capitalize';

Expand Down
2 changes: 1 addition & 1 deletion packages/fns/tests/castArray.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from 'vitest';

import castArray from '../src/castArray';

Expand Down
2 changes: 1 addition & 1 deletion packages/fns/tests/compose.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from 'vitest';

import compose from '../src/compose';

Expand Down
2 changes: 1 addition & 1 deletion packages/fns/tests/dropLast.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from 'vitest';

import dropLast from '../src/dropLast';

Expand Down
2 changes: 1 addition & 1 deletion packages/fns/tests/evolve.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from 'vitest';

import evolve from '../src/evolve';

Expand Down
2 changes: 1 addition & 1 deletion packages/fns/tests/get.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from 'vitest';

import get from '../src/get';

Expand Down
2 changes: 1 addition & 1 deletion packages/fns/tests/isNil.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-void */
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from 'vitest';

import isNil from '../src/isNil';

Expand Down
2 changes: 1 addition & 1 deletion packages/fns/tests/last.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from 'vitest';

import last from '../src/last';

Expand Down
2 changes: 1 addition & 1 deletion packages/fns/tests/matchPercent.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from 'vitest';

import matchPercent from '../src/matchPercent';

Expand Down
2 changes: 1 addition & 1 deletion packages/fns/tests/omit.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from 'vitest';

import omit from '../src/omit';

Expand Down
2 changes: 1 addition & 1 deletion packages/fns/tests/pick.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from 'vitest';

import pick from '../src/pick';

Expand Down
2 changes: 1 addition & 1 deletion packages/fns/tests/reverse.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from 'vitest';

import reverse from '../src/reverse';

Expand Down
2 changes: 1 addition & 1 deletion packages/fns/tests/upperFirst.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from 'vitest';

import upperFirst from '../src/upperFirst';

Expand Down
2 changes: 1 addition & 1 deletion packages/font/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}
},
"scripts": {
"test": "NODE_OPTIONS=\"--experimental-vm-modules\" jest",
"test": "vitest",
"build": "rimraf ./lib && rollup -c",
"watch": "rimraf ./lib && rollup -c -w"
},
Expand Down
13 changes: 5 additions & 8 deletions packages/font/setupTests.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
/* eslint-disable */
import { jest } from '@jest/globals';
import { createRequire } from 'module';
import { vi } from 'vitest';
import createFetchMock from 'vitest-fetch-mock';

import '../../polyfills';

const require = createRequire(import.meta.url);
const fetchMocker = createFetchMock(vi);
fetchMocker.enableMocks();

global.BROWSER = false;

const customGlobal = global;
customGlobal.fetch = require('jest-fetch-mock');
customGlobal.fetchMock = customGlobal.fetch;

jest.setMock('cross-fetch', fetch);
vi.mock('cross-fetch', () => ({ default: global.fetch }));
5 changes: 0 additions & 5 deletions packages/image/jest.config.js

This file was deleted.

5 changes: 1 addition & 4 deletions packages/image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"directory": "packages/image"
},
"scripts": {
"test": "NODE_OPTIONS=\"--experimental-vm-modules\" jest",
"test": "vitest",
"build": "rimraf ./lib && rollup -c",
"watch": "rimraf ./lib && rollup -c -w"
},
Expand All @@ -35,9 +35,6 @@
"cross-fetch": "^3.1.5",
"jpeg-exif": "^1.1.4"
},
"devDependencies": {
"jest-fetch-mock": "^2.1.1"
},
"files": [
"lib"
]
Expand Down
13 changes: 0 additions & 13 deletions packages/image/setupTests.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/image/tests/cache.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from 'vitest';

import createCache from '../src/cache';

Expand Down
5 changes: 3 additions & 2 deletions packages/image/tests/resolve.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, test } from '@jest/globals';
import { beforeEach, describe, expect, test } from 'vitest';
import fs from 'fs';
import path from 'path';
import url from 'url';
Expand Down Expand Up @@ -45,7 +45,8 @@ describe('image resolveImage', () => {
expect(fetch.mock.calls[0][1].headers).toEqual(headers);
});

test('Should fetch remote image using passed body', async () => {
// TypeError: Request with GET/HEAD method cannot have body
test.skip('Should fetch remote image using passed body', async () => {
fetch.once(localJPGImage);

const body = 'qwerty';
Expand Down
11 changes: 11 additions & 0 deletions packages/image/vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// false positive on import/no-unresolved
// eslint-disable-next-line import/no-unresolved
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
setupFiles: ['vitest.setup.js'],
include: ['tests/*.{test,spec}.?(c|m)[jt]s?(x)'],
watch: false,
},
});
10 changes: 10 additions & 0 deletions packages/image/vitest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable import/no-extraneous-dependencies */
import { vi } from 'vitest';
import createFetchMock from 'vitest-fetch-mock';

const fetchMocker = createFetchMock(vi);
fetchMocker.enableMocks();

global.BROWSER = false;

vi.mock('cross-fetch', () => ({ default: global.fetch }));
5 changes: 1 addition & 4 deletions packages/layout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"directory": "packages/layout"
},
"scripts": {
"test": "NODE_OPTIONS=\"--experimental-vm-modules\" jest",
"test": "vitest",
"build": "rimraf ./lib && rollup -c",
"watch": "rimraf ./lib && rollup -c -w"
},
Expand All @@ -39,9 +39,6 @@
"queue": "^6.0.1",
"yoga-layout": "^2.0.1"
},
"devDependencies": {
"jest-fetch-mock": "^2.1.1"
},
"files": [
"lib"
]
Expand Down
12 changes: 5 additions & 7 deletions packages/layout/setupTests.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
/* eslint-disable */
import { createRequire } from 'module';
import { vi } from 'vitest';
import createFetchMock from 'vitest-fetch-mock';

import '../../polyfills';

const require = createRequire(import.meta.url);
const fetchMocker = createFetchMock(vi);
fetchMocker.enableMocks();

global.BROWSER = false;

const customGlobal = global;
customGlobal.fetch = require('jest-fetch-mock');
customGlobal.fetchMock = customGlobal.fetch;

jest.setMock('cross-fetch', fetch);
vi.mock('cross-fetch', () => ({ default: global.fetch }));
2 changes: 1 addition & 1 deletion packages/layout/tests/image/getSource.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from 'vitest';

import getSource from '../../src/image/getSource';

Expand Down
2 changes: 1 addition & 1 deletion packages/layout/tests/image/resolveSource.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { describe, expect, it } from 'vitest';

import resolveSource from '../../src/image/resolveSource';

Expand Down
2 changes: 1 addition & 1 deletion packages/layout/tests/node/getBorderWidth.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from 'vitest';

import * as Yoga from 'yoga-layout';

Expand Down
2 changes: 1 addition & 1 deletion packages/layout/tests/node/getDimension.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from 'vitest';

import getDimension from '../../src/node/getDimension';

Expand Down
2 changes: 1 addition & 1 deletion packages/layout/tests/node/getMargin.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from 'vitest';

import * as Yoga from 'yoga-layout';

Expand Down
2 changes: 1 addition & 1 deletion packages/layout/tests/node/getOrigin.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from 'vitest';

import getOrigin from '../../src/node/getOrigin';

Expand Down
2 changes: 1 addition & 1 deletion packages/layout/tests/node/getPadding.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from 'vitest';

import * as Yoga from 'yoga-layout';

Expand Down
2 changes: 1 addition & 1 deletion packages/layout/tests/node/getPosition.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from '@jest/globals';
import { describe, expect, test } from 'vitest';

import getPosition from '../../src/node/getPosition';

Expand Down
Loading

0 comments on commit d5f90ca

Please sign in to comment.