Skip to content

Commit

Permalink
Replace jest with vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Aug 1, 2024
2 parents 6f7fdef + 54ef2e8 commit fe1c5cf
Show file tree
Hide file tree
Showing 195 changed files with 1,699 additions and 2,046 deletions.
33 changes: 23 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const vitest = require('eslint-plugin-vitest');

module.exports = {
env: {
es6: true,
jest: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:jest/recommended',
'plugin:jest/style',
'plugin:import/errors',
'plugin:import/warnings',
'prettier',
Expand All @@ -16,6 +15,11 @@ module.exports = {
__DEV__: true,
__LIB_VERSION__: true,
ENV_DEVELOPMENT: true,
afterEach: true,
beforeEach: true,
describe: true,
expect: true,
vi: true,
},
ignorePatterns: ['*.d.ts', '/website/'],
overrides: [
Expand Down Expand Up @@ -58,9 +62,6 @@ module.exports = {
{
excludedFiles: ['./**/__tests__/**/*.*'],
files: ['*.ts'],
rules: {
'jest/no-export': 0,
},
},
{
files: ['./**/vest/src/**/*.*'],
Expand All @@ -69,9 +70,21 @@ module.exports = {
'vest-internal/use-use': 2,
},
},
{
files: ['./**/__tests__/**/*.*'],
rules: {
...vitest.configs.recommended.rules,
'vitest/expect-expect': [
'error',
{
assertFunctionNames: ['expect', 'assert', 'enforce'],
},
],
},
},
],
parser: '@typescript-eslint/parser',
plugins: ['jest', 'vest-internal'],
plugins: ['vitest', 'vest-internal'],
rules: {
complexity: [2, { max: 5 }],
'import/extensions': [0, 'ignorePackages'],
Expand Down Expand Up @@ -100,9 +113,9 @@ module.exports = {
],
},
],
'jest/expect-expect': 0,
'jest/no-identical-title': 0,
'jest/no-standalone-expect': 0,
'vitest/expect-expect': 0,
'vitest/no-identical-title': 0,
'vitest/no-standalone-expect': 0,
'max-params': [1, { max: 4 }],
'no-console': 2,
'no-else-return': 1,
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The structure of the repo is as follows
├── vx # Repo setup and CI config
│   ├── commands # All the supported cli commands
│   ├── config
│   │   ├── jest
│   │   ├── vitest
│   │   └── rollup
│   │   ├── plugins
│   ├── scripts # All the scripts used to build and release the packages
Expand Down Expand Up @@ -57,13 +57,13 @@ The naming convention for a test file is `moduleName.test.ts`.

#### Running tests

To run tests, you need to run `vx test`. This will run all tests in all packages. The tests are being run by jest.
To run tests, you need to run `vx test`. This will run all tests in all packages. The tests are being run by vitest.

You can narrow it down by specifying the package name:

`vx test vest`

Normal jest options can be passed to the test command.
Normal vitest options can be passed to the test command.

`vx test --watch`

Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@
],
"devDependencies": {
"@faker-js/faker": "^8.4.1",
"@types/jest": "^29.5.12",
"@types/lodash": "^4.17.5",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.9.0",
"husky": "^8.0.3",
"lodash": "^4.17.21",
"prettier": "^3.3.1",
Expand Down
1 change: 1 addition & 0 deletions packages/anyone/src/__tests__/all.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { sample, random } from 'lodash';
import { describe, it, expect } from 'vitest';

import { TRUTHY_VALUES, FALSY_VALUES } from './anyoneTestValues';

Expand Down
1 change: 1 addition & 0 deletions packages/anyone/src/__tests__/any.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { sample, random } from 'lodash';
import { describe, it, expect } from 'vitest';

import { TRUTHY_VALUES, FALSY_VALUES } from './anyoneTestValues';

Expand Down
1 change: 1 addition & 0 deletions packages/anyone/src/__tests__/none.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { sample, random } from 'lodash';
import { describe, it, expect } from 'vitest';

import { TRUTHY_VALUES, FALSY_VALUES } from './anyoneTestValues';

Expand Down
1 change: 1 addition & 0 deletions packages/anyone/src/__tests__/one.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { sample, random } from 'lodash';
import { describe, it, expect } from 'vitest';

import { TRUTHY_VALUES, FALSY_VALUES } from './anyoneTestValues';

Expand Down
2 changes: 2 additions & 0 deletions packages/anyone/src/__tests__/runAnyoneMethods.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect } from 'vitest';

import { FALSY_VALUES, TRUTHY_VALUES } from './anyoneTestValues';

import run from 'runAnyoneMethods';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Cascading Context context.run Should clear context after callback run 1`] = `
exports[`Cascading Context > context.run > Should clear context after callback run 1`] = `
{
"a": 1,
}
`;

exports[`Cascading Context context.run Should clear context after callback run 2`] = `
exports[`Cascading Context > context.run > Should clear context after callback run 2`] = `
{
"a": 1,
"b": 2,
}
`;

exports[`Cascading Context createCascade Should return all methods 1`] = `
exports[`Cascading Context > createCascade > Should return all methods 1`] = `
{
"bind": [Function],
"run": [Function],
Expand Down
12 changes: 7 additions & 5 deletions packages/context/src/__tests__/cascade.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect, beforeEach, vi } from 'vitest';

import { createCascade, CtxCascadeApi } from 'context';

describe('Cascading Context', () => {
Expand Down Expand Up @@ -141,7 +143,7 @@ describe('Cascading Context', () => {

describe('context.bind', () => {
it('Returns a function', () => {
expect(typeof ctx.bind({}, jest.fn())).toBe('function');
expect(typeof ctx.bind({}, vi.fn())).toBe('function');
});

it('Wraps the function with context', () => {
Expand All @@ -160,7 +162,7 @@ describe('Cascading Context', () => {
});

it('Passes runtime arguments to bound function', () => {
const fn = jest.fn();
const fn = vi.fn();
const args = Array.from({ length: 100 }, (_, i) => `${i}`); // 1-100
ctx.bind({}, fn)(...args);

Expand Down Expand Up @@ -269,7 +271,7 @@ describe('Cascading Context', () => {

describe('init argument', () => {
it('Should run init function on every context.run', () => {
const init = jest.fn();
const init = vi.fn();

const ctx = createCascade(init);

Expand All @@ -293,7 +295,7 @@ describe('Cascading Context', () => {
});

it('Should accept ctxRef as first argument', () => {
const init = jest.fn();
const init = vi.fn();

const ctx = createCascade(init);
const ref1 = { a: 1, b: 2 };
Expand All @@ -307,7 +309,7 @@ describe('Cascading Context', () => {
});

it('Should accept parentContext as second argument', () => {
const init = jest.fn();
const init = vi.fn();

const ctx = createCascade(init);
let p1;
Expand Down
2 changes: 2 additions & 0 deletions packages/context/src/__tests__/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect, beforeEach } from 'vitest';

import { createContext, CtxApi } from 'context';

describe('Context', () => {
Expand Down
17 changes: 3 additions & 14 deletions packages/n4s/src/__tests__/enforce.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import { TEnforceMock } from '../../testUtils/TEnforceMock';
import { describe, it, expect, beforeEach } from 'vitest';

import * as ruleReturn from 'ruleReturn';
import { enforce } from 'enforce';

const _proxy = global.Proxy;
let enforce: TEnforceMock;
import * as ruleReturn from 'ruleReturn';

describe(`enforce`, () => {
beforeEach(() => {
jest.resetModules();
enforce = require('enforce').enforce as TEnforceMock;
});

afterEach(() => {
jest.resetModules();
global.Proxy = _proxy;
});

describe('eager assertions', () => {
it('Should throw an error when invalid', () => {
expect(() => enforce('4').isNumber()).toThrow();
Expand Down
2 changes: 2 additions & 0 deletions packages/n4s/src/__tests__/enforceEager.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect, afterEach } from 'vitest';

import enforceEager from 'enforceEager';

describe(`enforce eager`, () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/n4s/src/exports/__tests__/compose.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect } from 'vitest';

import compose from 'compose';
import { enforce } from 'n4s';
import * as ruleReturn from 'ruleReturn';
Expand Down
2 changes: 2 additions & 0 deletions packages/n4s/src/exports/__tests__/date.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect } from 'vitest';

import { enforce } from 'n4s';
import 'date';

Expand Down
2 changes: 2 additions & 0 deletions packages/n4s/src/exports/__tests__/email.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect } from 'vitest';

import { enforce } from 'n4s';
import 'email';

Expand Down
2 changes: 2 additions & 0 deletions packages/n4s/src/exports/__tests__/isUrl.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect } from 'vitest';

import { enforce } from 'n4s';
import 'isURL';

Expand Down
2 changes: 2 additions & 0 deletions packages/n4s/src/plugins/compounds/__tests__/allOf.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect } from 'vitest';

import { enforce } from 'enforce';
import * as ruleReturn from 'ruleReturn';
import 'compounds';
Expand Down
2 changes: 2 additions & 0 deletions packages/n4s/src/plugins/compounds/__tests__/noneOf.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect } from 'vitest';

import { enforce } from 'enforce';
import * as ruleReturn from 'ruleReturn';
import 'compounds';
Expand Down
2 changes: 2 additions & 0 deletions packages/n4s/src/plugins/compounds/__tests__/oneOf.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect } from 'vitest';

import { enforce } from 'enforce';
import * as ruleReturn from 'ruleReturn';

Expand Down
2 changes: 2 additions & 0 deletions packages/n4s/src/plugins/schema/__tests__/isArrayOf.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect } from 'vitest';

import { enforce } from 'enforce';
import 'schema';
import 'compounds';
Expand Down
2 changes: 2 additions & 0 deletions packages/n4s/src/plugins/schema/__tests__/loose.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect } from 'vitest';

import { enforce } from 'enforce';
import * as ruleReturn from 'ruleReturn';
import 'schema';
Expand Down
2 changes: 2 additions & 0 deletions packages/n4s/src/plugins/schema/__tests__/optional.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect } from 'vitest';

import { enforce } from 'enforce';
import * as ruleReturn from 'ruleReturn';
import 'schema';
Expand Down
2 changes: 2 additions & 0 deletions packages/n4s/src/plugins/schema/__tests__/partial.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect } from 'vitest';

import { enforce } from 'enforce';
import * as ruleReturn from 'ruleReturn';
import { partial } from 'schema';
Expand Down
2 changes: 2 additions & 0 deletions packages/n4s/src/plugins/schema/__tests__/shape&loose.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect } from 'vitest';

import { enforce } from 'enforce';
import * as ruleReturn from 'ruleReturn';
import 'schema';
Expand Down
2 changes: 2 additions & 0 deletions packages/n4s/src/plugins/schema/__tests__/shape.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect } from 'vitest';

import { enforce } from 'enforce';
import * as ruleReturn from 'ruleReturn';
import 'schema';
Expand Down
2 changes: 2 additions & 0 deletions packages/n4s/src/rules/__tests__/endsWith.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect } from 'vitest';

import { endsWith } from 'endsWith';

describe('Tests isArray rule', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/n4s/src/rules/__tests__/equals.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { faker } from '@faker-js/faker';
import { sample } from 'lodash';
import { describe, it, expect } from 'vitest';

import { equals } from 'equals';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { faker } from '@faker-js/faker';
import { describe, it, expect, beforeEach } from 'vitest';

import { greaterThanOrEquals } from 'greaterThanOrEquals';

Expand Down
2 changes: 2 additions & 0 deletions packages/n4s/src/rules/__tests__/inside.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect } from 'vitest';

import { inside } from 'inside';

describe('Inside rule', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/n4s/src/rules/__tests__/isBetween.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect } from 'vitest';

import { isBetween } from 'isBetween';

describe('Tests isBetween rule', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/n4s/src/rules/__tests__/isBlank.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect } from 'vitest';

import { isBlank, isNotBlank } from 'isBlank';

describe('isBlank', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/n4s/src/rules/__tests__/isBoolean.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect } from 'vitest';

import { enforce } from 'enforce';

describe('isBoolean', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/n4s/src/rules/__tests__/isEven.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { faker } from '@faker-js/faker';
import { describe, it, expect, beforeAll } from 'vitest';

import { isEven } from 'isEven';

Expand Down
2 changes: 2 additions & 0 deletions packages/n4s/src/rules/__tests__/isKeyOf.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect } from 'vitest';

import { enforce } from 'enforce';
import { isKeyOf, isNotKeyOf } from 'isKeyOf';

Expand Down
2 changes: 2 additions & 0 deletions packages/n4s/src/rules/__tests__/isNaN.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect } from 'vitest';

import * as NaNRule from 'isNaN';

describe('Tests isNaN rule', () => {
Expand Down
Loading

0 comments on commit fe1c5cf

Please sign in to comment.