Skip to content

Commit

Permalink
Revert "chore: migrate to vitest (#42506)"
Browse files Browse the repository at this point in the history
This reverts commit 6759887.
  • Loading branch information
MadCcc committed Jun 7, 2023
1 parent 80264a7 commit af8c826
Show file tree
Hide file tree
Showing 444 changed files with 3,579 additions and 3,491 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Expand Up @@ -21,3 +21,4 @@ coverage
**/*.d.ts
# Scripts
scripts/previewEditor/**/*
jest-stare
27 changes: 9 additions & 18 deletions .eslintrc.js
Expand Up @@ -3,7 +3,7 @@ module.exports = {
'airbnb',
'prettier',
'plugin:compat/recommended',
'plugin:vitest/recommended',
'plugin:jest/recommended',
'plugin:react/recommended',
'plugin:import/typescript',
'plugin:markdown/recommended',
Expand All @@ -12,6 +12,7 @@ module.exports = {
browser: true,
node: true,
jasmine: true,
jest: true,
es6: true,
},
settings: {
Expand All @@ -24,15 +25,7 @@ module.exports = {
},
},
parser: '@typescript-eslint/parser',
plugins: [
'react',
'@babel',
'vitest',
'@typescript-eslint',
'react-hooks',
'unicorn',
'markdown',
],
plugins: ['react', '@babel', 'jest', '@typescript-eslint', 'react-hooks', 'unicorn', 'markdown'],
// https://github.com/typescript-eslint/typescript-eslint/issues/46#issuecomment-470486034
overrides: [
{
Expand Down Expand Up @@ -159,10 +152,8 @@ module.exports = {
'scripts/**',
'**/*.test.js',
'**/__tests__/*',
'__mocks__/**',
'*.config.js',
'**/*.md',
'vitest*config.ts',
],
},
],
Expand All @@ -188,12 +179,12 @@ module.exports = {
'no-restricted-globals': 0,
'max-classes-per-file': 0,

'vitest/prefer-to-be': 0,
'vitest/expect-expect': 0,
'vitest/no-done-callback': 0,
'vitest/valid-title': 0,
'vitest/no-conditional-expect': 0,
'vitest/no-standalone-expect': 0,
'jest/no-test-callback': 0,
'jest/expect-expect': 0,
'jest/no-done-callback': 0,
'jest/valid-title': 0,
'jest/no-conditional-expect': 0,
'jest/no-standalone-expect': 0,

'unicorn/better-regex': 2,
'unicorn/prefer-string-trim-start-end': 2,
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Expand Up @@ -191,7 +191,7 @@ jobs:
# dom test
- name: dom test
if: ${{ matrix.module == 'dom' }}
run: npm test -- --shard=${{matrix.shard}} --coverage
run: npm test -- --maxWorkers=2 --shard=${{matrix.shard}} --coverage

- name: persist coverages
if: ${{ matrix.module == 'dom' && matrix.react == '17' }}
Expand Down Expand Up @@ -347,7 +347,7 @@ jobs:
- name: test
# lib only run in master branch not in pull request
if: ${{ github.event_name != 'pull_request' || matrix.module != 'lib' }}
run: npm test -- --shard=${{matrix.shard}}
run: npm test -- --maxWorkers=2 --shard=${{matrix.shard}}
env:
LIB_DIR: ${{ matrix.module }}
needs: compile
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -58,6 +58,7 @@ components/version/token-meta.json
# Image snapshot diff
__diff_output__/
__image_snapshots__/
/jest-stare
/imageSnapshots
/imageDiffSnapshots

Expand Down
23 changes: 23 additions & 0 deletions .jest.image.js
@@ -0,0 +1,23 @@
const { moduleNameMapper, transformIgnorePatterns } = require('./.jest');

// jest config for image snapshots
module.exports = {
setupFiles: ['./tests/setup.js'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'md'],
moduleNameMapper,
transform: {
'\\.tsx?$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor',
'\\.js$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor',
'\\.md$': './node_modules/@ant-design/tools/lib/jest/demoPreprocessor',
'\\.(jpg|png|gif|svg)$': './node_modules/@ant-design/tools/lib/jest/imagePreprocessor',
},
testRegex: 'image\\.test\\.(j|t)s$',
transformIgnorePatterns,
globals: {
'ts-jest': {
tsConfigFile: './tsconfig.test.json',
},
},
preset: 'jest-puppeteer',
testTimeout: 10000,
};
68 changes: 68 additions & 0 deletions .jest.js
@@ -0,0 +1,68 @@
const compileModules = ['react-sticky-box', 'rc-tween-one', '@babel', '@ant-design', 'countup.js'];

const ignoreList = [];

// cnpm use `_` as prefix
['', '_'].forEach((prefix) => {
compileModules.forEach((module) => {
ignoreList.push(`${prefix}${module}`);
});
});

const transformIgnorePatterns = [
// Ignore modules without es dir.
// Update: @babel/runtime should also be transformed
`/node_modules/(?!${ignoreList.join('|')})[^/]+?/(?!(es)/)`,
];

function getTestRegex(libDir) {
if (['dist', 'lib', 'es'].includes(libDir)) {
return 'demo\\.test\\.(j|t)sx?$';
}
return '.*\\.test\\.(j|t)sx?$';
}

module.exports = {
verbose: true,
testEnvironment: 'jsdom',
setupFiles: ['./tests/setup.js', 'jest-canvas-mock'],
setupFilesAfterEnv: ['./tests/setupAfterEnv.ts'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'md'],
modulePathIgnorePatterns: ['/_site/'],
moduleNameMapper: {
'/\\.(css|less)$/': 'identity-obj-proxy',
'^antd$': '<rootDir>/components/index',
'^antd/es/(.*)$': '<rootDir>/components/$1',
},
testPathIgnorePatterns: ['/node_modules/', 'dekko', 'node', 'image.test.js', 'image.test.ts'],
transform: {
'\\.tsx?$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor',
'\\.(m?)js$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor',
'\\.md$': './node_modules/@ant-design/tools/lib/jest/demoPreprocessor',
'\\.(jpg|png|gif|svg)$': './node_modules/@ant-design/tools/lib/jest/imagePreprocessor',
},
testRegex: getTestRegex(process.env.LIB_DIR),
collectCoverageFrom: [
'components/**/*.{ts,tsx}',
'!components/*/style/index.tsx',
'!components/style/index.tsx',
'!components/*/locale/index.tsx',
'!components/*/__tests__/type.test.tsx',
'!components/**/*/interface.{ts,tsx}',
'!components/*/__tests__/image.test.{ts,tsx}',
'!components/__tests__/node.test.tsx',
'!components/*/demo/*.tsx',
'!components/*/design/**',
],
transformIgnorePatterns,
globals: {
'ts-jest': {
tsConfig: './tsconfig.test.json',
},
},
testEnvironmentOptions: {
url: 'http://localhost',
},
// bail: true,
maxWorkers: '50%',
};
19 changes: 19 additions & 0 deletions .jest.node.js
@@ -0,0 +1,19 @@
const { moduleNameMapper, transformIgnorePatterns } = require('./.jest');

// jest config for server render environment
module.exports = {
setupFiles: ['./tests/setup.js'],
setupFilesAfterEnv: ['./tests/setupAfterEnv.ts'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'md'],
moduleNameMapper,
transform: {
'\\.tsx?$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor',
'\\.js$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor',
'\\.md$': './node_modules/@ant-design/tools/lib/jest/demoPreprocessor',
'\\.(jpg|png|gif|svg)$': './node_modules/@ant-design/tools/lib/jest/imagePreprocessor',
},
testRegex: 'node\\.test\\.(j|t)sx$',
testEnvironment: 'node',
transformIgnorePatterns,
// bail: true,
};
21 changes: 21 additions & 0 deletions .jest.site.js
@@ -0,0 +1,21 @@
const { moduleNameMapper, transformIgnorePatterns } = require('./.jest');

// jest config for server render environment
module.exports = {
moduleFileExtensions: ['ts', 'tsx', 'js', 'md'],
moduleNameMapper,
transform: {
'\\.tsx?$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor',
'\\.js$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor',
'\\.md$': './node_modules/@ant-design/tools/lib/jest/demoPreprocessor',
'\\.(jpg|png|gif|svg)$': './node_modules/@ant-design/tools/lib/jest/imagePreprocessor',
},
testRegex: 'check-site\\.(j|t)s$',
testEnvironment: 'node',
transformIgnorePatterns,
globals: {
'ts-jest': {
tsConfigFile: './tsconfig.test.json',
},
},
};
3 changes: 0 additions & 3 deletions __mocks__/rc-virtual-list.ts

This file was deleted.

12 changes: 6 additions & 6 deletions components/__tests__/__snapshots__/index.test.ts.snap
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`antd > exports modules correctly 1`] = `
exports[`antd exports modules correctly 1`] = `
[
"Affix",
"Alert",
Expand Down Expand Up @@ -37,9 +37,7 @@ exports[`antd > exports modules correctly 1`] = `
"List",
"Mentions",
"Menu",
"message",
"Modal",
"notification",
"Pagination",
"Popconfirm",
"Popover",
Expand All @@ -61,7 +59,6 @@ exports[`antd > exports modules correctly 1`] = `
"Table",
"Tabs",
"Tag",
"theme",
"TimePicker",
"Timeline",
"Tooltip",
Expand All @@ -71,7 +68,10 @@ exports[`antd > exports modules correctly 1`] = `
"TreeSelect",
"Typography",
"Upload",
"version",
"Watermark",
"message",
"notification",
"theme",
"version",
]
`;
4 changes: 2 additions & 2 deletions components/__tests__/__snapshots__/setup.test.tsx.snap
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SetUp.Test > diff of React 18 & React 17 1`] = `
exports[`SetUp.Test diff of React 18 & React 17 1`] = `
NodeList [
<div>
bamboo
Expand Down
3 changes: 1 addition & 2 deletions components/__tests__/index.test.ts
@@ -1,7 +1,6 @@
import * as antd from '..';

const OLD_NODE_ENV = process.env.NODE_ENV;
process.env.NODE_ENV = 'development';
const antd = require('..');

describe('antd', () => {
afterAll(() => {
Expand Down
37 changes: 15 additions & 22 deletions components/__tests__/node.test.tsx
Expand Up @@ -3,24 +3,21 @@ import * as React from 'react';
import { renderToString } from 'react-dom/server';
import type { Options } from '../../tests/shared/demoTest';

globalThis.testConfig = {};
(global as any).testConfig = {};

vi.mock('../../tests/shared/demoTest', () => {
jest.mock('../../tests/shared/demoTest', () => {
function fakeDemoTest(name: string, option: Options = {}) {
globalThis.testConfig[name] = option;
(global as any).testConfig[name] = option;
}

fakeDemoTest.rootPropsTest = () => {};

return {
default: fakeDemoTest,
rootPropsTest: () => {},
};
return fakeDemoTest;
});

describe('node', () => {
beforeAll(() => {
vi.useFakeTimers().setSystemTime(new Date('2016-11-22'));
jest.useFakeTimers().setSystemTime(new Date('2016-11-22'));
});

// Find the component exist demo test file
Expand All @@ -30,27 +27,23 @@ describe('node', () => {
const componentName = componentTestFile.match(/components\/([^/]*)\//)![1];

// Test for ssr
// eslint-disable-next-line vitest/valid-describe-callback
describe(componentName, async () => {
describe(componentName, () => {
const demoList = globSync(`./components/${componentName}/demo/*.tsx`);

// Use mock to get config
await import(`../../${componentTestFile}`);
require(`../../${componentTestFile}`); // eslint-disable-line global-require, import/no-dynamic-require
const option = (global as any).testConfig?.[componentName];

demoList.forEach((demoFile) => {
const option = globalThis.testConfig?.[componentName];
const skip: string[] = option?.skip || [];
const test = skip.some((skipMarkdown) => demoFile.includes(skipMarkdown)) ? it.skip : it;

test(
demoFile,
async () => {
const Demo = (await import(`../../${demoFile}`)).default;
expect(() => {
renderToString(<Demo />);
}).not.toThrow();
},
120000,
);
test(demoFile, () => {
const Demo = require(`../../${demoFile}`).default; // eslint-disable-line global-require, import/no-dynamic-require
expect(() => {
renderToString(<Demo />);
}).not.toThrow();
});
});
});
});
Expand Down
3 changes: 1 addition & 2 deletions components/_util/PurePanel.tsx
Expand Up @@ -7,7 +7,7 @@ export interface BaseProps {
style?: React.CSSProperties;
}

/* c8 ignore start */
/* istanbul ignore next */
export default function genPurePanel<ComponentProps extends BaseProps>(
Component: any,
defaultPrefixCls?: string,
Expand Down Expand Up @@ -96,4 +96,3 @@ export default function genPurePanel<ComponentProps extends BaseProps>(
);
} as typeof Component;
}
/* c8 ignore stop */

0 comments on commit af8c826

Please sign in to comment.