Skip to content

test: Migrate all packages from jest to vitest #13

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

Merged
merged 3 commits into from
Aug 7, 2024
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
5 changes: 2 additions & 3 deletions .depcheckrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ ignores:
- '@metamask/auto-changelog'
- '@ts-bridge/cli'
- '@ts-bridge/shims'
- '@types/jest'
- '@types/node'
- '@yarnpkg/*'
- 'jest-silent-reporter'
- 'jsdom'
- 'prettier-plugin-*'
- 'ts-jest'
- 'typedoc'
- 'vite'
- 'vitest'
63 changes: 37 additions & 26 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ module.exports = {

ignorePatterns: [
'!.eslintrc.js',
'!jest.config.js',
'!vite.config.mts',
'!vitest.config.mts',
'node_modules',
'**/dist',
'**/docs',
Expand Down Expand Up @@ -49,7 +50,7 @@ module.exports = {
},

{
files: ['**/scripts/*.mjs'],
files: ['**/scripts/*.mjs', '*.mts'],
parserOptions: {
ecmaVersion: '2022',
},
Expand Down Expand Up @@ -98,34 +99,44 @@ module.exports = {
},

{
files: ['**/jest.environment.js'],
// @metamask/eslint-plugin-vitest does not exist, so this is copied from the
// jest-equivalent. All of the rules we specify are the same. Ref:
// https://github.com/MetaMask/eslint-config/blob/95275db568999bf48670894a3dc6b6c1a2f517f9/packages/jest/src/index.js
files: ['**/*.test.{ts,js}'],
plugins: ['vitest'],
extends: ['plugin:vitest/recommended'],
rules: {
// These files run under Node, and thus `require(...)` is expected.
'n/global-require': 'off',
},
},

{
files: ['*.test.{ts,js}', '**/tests/**/*.{ts,js}'],
extends: ['@metamask/eslint-config-jest'],
rules: {
'@typescript-eslint/no-shadow': [
// From the jest/style ruleset (no corresponding ruleset for vitest). Ref:
// https://github.com/jest-community/eslint-plugin-jest/blob/39719a323466aada48531fe28ec953e17dee6e65/src/index.ts#L74-L77
'vitest/no-alias-methods': 'error', // We upgrade this to an error
'vitest/prefer-to-be': 'error',
'vitest/prefer-to-contain': 'error',
'vitest/prefer-to-have-length': 'error',
// From MetaMask's custom ruleset
'vitest/consistent-test-it': ['error', { fn: 'it' }],
'vitest/no-conditional-in-test': 'error', // Previously "jest/no-if"
'vitest/no-duplicate-hooks': 'error',
'vitest/no-test-return-statement': 'error',
'vitest/prefer-hooks-on-top': 'error',
'vitest/prefer-lowercase-title': ['error', { ignore: ['describe'] }],
'vitest/prefer-spy-on': 'error',
'vitest/prefer-strict-equal': 'error',
'vitest/prefer-todo': 'error',
'vitest/require-top-level-describe': 'error',
'vitest/require-to-throw-message': 'error',
'vitest/valid-expect': ['error', { alwaysAwait: true }],
'vitest/no-restricted-matchers': [
'error',
{ allow: ['describe', 'expect', 'it'] },
{
resolves: 'Use `expect(await promise)` instead.',
toBeFalsy: 'Avoid `toBeFalsy`',
toBeTruthy: 'Avoid `toBeTruthy`',
toMatchSnapshot: 'Use `toMatchInlineSnapshot()` instead',
toThrowErrorMatchingSnapshot:
'Use `toThrowErrorMatchingInlineSnapshot()` instead',
},
],
},
},

{
// These files are test helpers, not tests. We still use the Jest ESLint
// config here to ensure that ESLint expects a test-like environment, but
// various rules meant just to apply to tests have been disabled.
files: ['**/tests/**/*.{ts,js}', '!*.test.{ts,js}'],
rules: {
'jest/no-export': 'off',
'jest/require-top-level-describe': 'off',
'jest/no-if': 'off',
},
},
],
};
17 changes: 6 additions & 11 deletions constraints.pro
Original file line number Diff line number Diff line change
Expand Up @@ -299,29 +299,24 @@ gen_enforced_field(WorkspaceCwd, 'scripts.changelog:update', CorrectChangelogUpd
\+ atom_concat(ExpectedPrefix, _, ChangelogUpdateCommand).

% All non-root packages must have the same "test" script.
gen_enforced_field(WorkspaceCwd, 'scripts.test', 'jest --reporters=jest-silent-reporter') :-
WorkspaceCwd \= 'packages/extension',
gen_enforced_field(WorkspaceCwd, 'scripts.test', 'vitest run --config vitest.config.mts') :-
WorkspaceCwd \= 'packages/shims',
WorkspaceCwd \= '.'.

% All non-root packages must have the same "test:clean" script.
gen_enforced_field(WorkspaceCwd, 'scripts.test:clean', 'jest --clearCache') :-
WorkspaceCwd \= 'packages/extension',
gen_enforced_field(WorkspaceCwd, 'scripts.test:clean', 'yarn test --no-cache --coverage.clean') :-
WorkspaceCwd \= '.'.

% All non-root packages must have the same "test:verbose" script.
gen_enforced_field(WorkspaceCwd, 'scripts.test:verbose', 'jest --verbose') :-
WorkspaceCwd \= 'packages/extension',
% All non-root packages must have the same "test:dev" script.
gen_enforced_field(WorkspaceCwd, 'scripts.test:dev', 'yarn test --coverage false') :-
WorkspaceCwd \= '.'.

% All non-root packages must have the same "test:verbose" script.
gen_enforced_field(WorkspaceCwd, 'scripts.test:dev', 'jest --verbose --coverage false') :-
WorkspaceCwd \= 'packages/extension',
gen_enforced_field(WorkspaceCwd, 'scripts.test:verbose', 'yarn test --reporter verbose') :-
WorkspaceCwd \= '.'.

% All non-root packages must have the same "test:watch" script.
gen_enforced_field(WorkspaceCwd, 'scripts.test:watch', 'jest --watch') :-
WorkspaceCwd \= 'packages/extension',
gen_enforced_field(WorkspaceCwd, 'scripts.test:watch', 'vitest --config vitest.config.mts') :-
WorkspaceCwd \= '.'.

% All dependency ranges must be recognizable (this makes it possible to apply
Expand Down
220 changes: 0 additions & 220 deletions jest.config.packages.js

This file was deleted.

Loading