Skip to content

Commit 28f96e2

Browse files
authored
Refactor from Jest to Vitest (#1969)
* refactor: remove jest configs * refactor: to setup vitest with jsdom * refactor: to make config files mjs * refactor: grit migration without edits * refactor: biome format * refactor: biome check * refactor: add missing dep * refactor: add local storage mock * test: rewrite test to pass with vitest * refactor: js files with jsx to jsx extension * test: fix react testing setup * refactor: no more default imports and exports * test: adjust last tests for vitest * fix: jest mentions removal * fix: typescript * fix: add coverage plugin
1 parent dc17f93 commit 28f96e2

File tree

207 files changed

+1811
-2219
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

207 files changed

+1811
-2219
lines changed

.github/workflows/test.yml

+10-15
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ jobs:
1010
install:
1111
runs-on: ubuntu-latest
1212

13-
strategy:
14-
matrix:
15-
node-version: [20.x, 22.x]
16-
1713
steps:
1814
- name: Checkout
1915
uses: actions/checkout@v4
@@ -23,10 +19,10 @@ jobs:
2319
with:
2420
run_install: false
2521

26-
- name: Setup Node.js ${{ matrix.node-version }}
22+
- name: Setup Node.js
2723
uses: actions/setup-node@v4
2824
with:
29-
node-version: ${{ matrix.node-version }}
25+
node-version-file: '.nvmrc'
3026
cache: 'pnpm'
3127

3228
- name: Install
@@ -41,22 +37,21 @@ jobs:
4137
- name: Build
4238
run: pnpm build
4339

44-
- name: Test
45-
if: startsWith(matrix.node-version, '20')
46-
run: pnpm test:ci
47-
env:
48-
CI: true
49-
5040
- name: Test (with coverage)
51-
if: startsWith(matrix.node-version, '22')
52-
run: pnpm test:ci:coverage
41+
run: pnpm test:coverage
5342
env:
5443
CI: true
5544
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
5645

5746
- name: Upload coverage
58-
if: startsWith(matrix.node-version, '22')
5947
uses: codecov/codecov-action@v5
6048
with:
6149
fail_ci_if_error: true
50+
verbose: true
6251
token: ${{ secrets.CODECOV_TOKEN }} # required
52+
53+
- name: Upload test results to Codecov
54+
if: ${{ !cancelled() }}
55+
uses: codecov/test-results-action@v1
56+
with:
57+
token: ${{ secrets.CODECOV_TOKEN }}

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ dist
4141
coverage
4242

4343
.vscode
44+
45+
junit.xml

biome.json

+1-16
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,6 @@
7777
"bracketSpacing": true,
7878
"quoteStyle": "single"
7979
},
80-
"globals": [
81-
"cy",
82-
"VERSION",
83-
"Cypress",
84-
"SplitIO",
85-
"it",
86-
"describe",
87-
"expect",
88-
"jest",
89-
"before",
90-
"beforeAll",
91-
"beforeEach",
92-
"after",
93-
"afterAll",
94-
"afterEach"
95-
]
80+
"globals": ["cy", "VERSION", "Cypress", "SplitIO"]
9681
}
9782
}

commitlint.config.js commitlint.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {
1+
export default {
22
extends: ['@commitlint/config-conventional'],
33
parserPreset: {
44
parserOpts: {

jest-runner-test.config.js

-1
This file was deleted.

jest.test.config.js

-36
This file was deleted.

lint-staged.config.js lint-staged.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {
1+
export default {
22
'*': [
33
'biome check --write --no-errors-on-unmatched', // Format, sort imports, lint, and apply safe fixes
44
'git add -u',

package.json

+14-14
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@
77
"postinstall": "husky install && preconstruct dev && manypkg check && check-node-version --package --print",
88
"reinstall": "manypkg exec rm -rf node_modules && rm -rf node_modules pnpm-lock.yaml && pnpm install",
99
"auth": "npm_config_registry=https://registry.npmjs.org npm whoami",
10-
"develop": "jest --projects jest.test.config.js --watch",
1110
"lint": "biome lint",
1211
"typecheck": "tsc --project tsconfig.json --noEmit && tsc --project packages/cypress-plugin/tsconfig.json --noEmit",
1312
"format": "biome format --write",
1413
"fix:biome": "biome lint --write",
1514
"biome:check": "biome check --write",
1615
"lint:ci": "biome ci",
17-
"test": "cross-env NODE_ENV=test jest --config jest.test.config.js",
18-
"test:ci": "cross-env NODE_ENV=test pnpm test -- --no-watchman --maxWorkers 5 --no-cache",
19-
"test:ci:coverage": "cross-env NODE_ENV=test pnpm test:ci --coverage",
20-
"test:watch": "cross-env NODE_ENV=test pnpm test -- --watch",
21-
"test:coverage": "cross-env NODE_ENV=test pnpm test -- --coverage",
16+
"test:coverage": "pnpm test -- --coverage",
17+
"test": "vitest run",
18+
"test:report": "vitest --reporter=junit --outputFile=junit.xml",
2219
"build": "preconstruct build",
2320
"build:watch": "preconstruct watch",
2421
"changeset": "changeset",
@@ -61,33 +58,36 @@
6158
"@biomejs/biome": "1.9.4",
6259
"@changesets/changelog-github": "0.5.0",
6360
"@changesets/cli": "2.27.10",
64-
"@commercetools/jest-enzyme-matchers": "1.1.2",
6561
"@commitlint/cli": "19.6.0",
6662
"@commitlint/config-conventional": "19.6.0",
6763
"@manypkg/cli": "0.21.4",
6864
"@preconstruct/cli": "2.8.10",
65+
"@testing-library/jest-dom": "6.6.3",
6966
"@types/jest": "29.5.14",
7067
"@types/lodash": "4.17.13",
7168
"@types/node": "22.9.1",
72-
"babel-jest": "29.7.0",
69+
"@vitejs/plugin-react": "4.3.4",
70+
"@vitest/coverage-v8": "2.1.6",
71+
"@vitest/ui": "2.1.6",
7372
"babel-plugin-transform-dynamic-import": "2.1.0",
7473
"check-node-version": "4.2.1",
7574
"colors": "1.4.0",
7675
"core-js": "3.39.0",
77-
"cross-env": "7.0.3",
7876
"husky": "9.1.7",
79-
"jest": "29.7.0",
80-
"jest-environment-jsdom": "29.7.0",
81-
"jest-localstorage-mock": "2.4.26",
77+
"jsdom": "25.0.1",
8278
"lint-staged": "15.2.10",
8379
"pinst": "3.0.0",
8480
"raf": "3.4.1",
81+
"react": "18.3.1",
82+
"react-dom": "18.3.1",
8583
"regenerator-runtime": "0.14.1",
8684
"rimraf": "6.0.1",
87-
"ts-jest": "29.2.5",
8885
"ts-node": "10.9.2",
8986
"tslib": "2.8.1",
90-
"typescript": "5.6.3"
87+
"typescript": "5.6.3",
88+
"vite": "5.1.8",
89+
"vitest": "2.1.6",
90+
"vitest-localstorage-mock": "0.1.2"
9191
},
9292
"keywords": [
9393
"react",
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import denormalizeFlagName from './denormalize-flag-name';
1+
import { describe, expect, it } from 'vitest';
2+
import { denormalizeFlagName } from './denormalize-flag-name';
23

34
describe('with camel case', () => {
4-
it('should camel case to uppercased flag names', () => {
5+
it('should camel case to uppercase flag names', () => {
56
expect(denormalizeFlagName('aFlag')).toEqual('a-flag');
67
});
78
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { TFlagName } from '@flopflip/types';
2+
import { describe, expect, it } from 'vitest';
3+
import { denormalizeFlagName } from './denormalize-flag-name';
4+
5+
describe('with camel case', () => {
6+
it('should camel case to uppercased flag names', () => {
7+
const input: TFlagName = 'aFlag';
8+
const expected: string = 'a-flag';
9+
10+
expect(denormalizeFlagName(input)).toEqual(expected);
11+
});
12+
});

packages/adapter-utilities/src/denormalize-flag-name/denormalize-flag-name.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ import kebabCase from 'lodash/kebabCase';
33

44
const denormalizeFlagName = (flagName: TFlagName) => kebabCase(flagName);
55

6-
export default denormalizeFlagName;
6+
export { denormalizeFlagName };
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { default } from './denormalize-flag-name';
1+
export { denormalizeFlagName } from './denormalize-flag-name';

packages/adapter-utilities/src/expose-globally/expose-globally.spec.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import getGlobalThis from 'globalthis';
2+
import { expect, it } from 'vitest';
23

3-
import exposeGlobally from './expose-globally';
4+
import { exposeGlobally } from './expose-globally';
45

56
const testAdapter = {
67
id: 'test',

packages/adapter-utilities/src/expose-globally/expose-globally.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ const exposeGlobally = (adapter: TAdapter) => {
99
global.__flopflip__[adapter.id] = adapter;
1010
};
1111

12-
export default exposeGlobally;
12+
export { exposeGlobally };
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { default } from './expose-globally';
1+
export { exposeGlobally } from './expose-globally';
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { default as denormalizeFlagName } from './denormalize-flag-name';
2-
export { default as exposeGlobally } from './expose-globally';
3-
export { default as normalizeFlag } from './normalize-flag';
4-
export { default as normalizeFlags } from './normalize-flags';
1+
export { denormalizeFlagName } from './denormalize-flag-name';
2+
export { exposeGlobally } from './expose-globally';
3+
export { normalizeFlag } from './normalize-flag';
4+
export { normalizeFlags } from './normalize-flags';
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { default } from './normalize-flag';
1+
export { normalizeFlag } from './normalize-flag';

packages/adapter-utilities/src/normalize-flag/normalize-flag.spec.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import normalizeFlag from './normalize-flag';
1+
import { describe, expect, it } from 'vitest';
2+
import { normalizeFlag } from './normalize-flag';
23

34
describe('with dashes', () => {
45
it('should camel case to uppercased flag names', () => {

packages/adapter-utilities/src/normalize-flag/normalize-flag.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ const normalizeFlag = (
1010
flagValue == null ? false : flagValue,
1111
];
1212

13-
export default normalizeFlag;
13+
export { normalizeFlag };
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { default } from './normalize-flags';
1+
export { normalizeFlags } from './normalize-flags';

packages/adapter-utilities/src/normalize-flags/normalize-flags.spec.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import normalizeFlag from '../normalize-flag';
2-
import normalizeFlags from './normalize-flags';
1+
import { describe, expect, it, vi } from 'vitest';
2+
import { normalizeFlag } from '../normalize-flag';
3+
import { normalizeFlags } from './normalize-flags';
34

45
const rawFlags = {
56
'a-flag': true,
@@ -27,7 +28,7 @@ describe('with default normalization', () => {
2728

2829
describe('with custom normalization', () => {
2930
it('should use the custom normalization function', () => {
30-
const customNormalizeFlag = jest.fn((...args) => normalizeFlag(...args));
31+
const customNormalizeFlag = vi.fn((...args) => normalizeFlag(...args));
3132

3233
expect(normalizeFlags(rawFlags, customNormalizeFlag)).toEqual({
3334
aFlag: true,

packages/adapter-utilities/src/normalize-flags/normalize-flags.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { TFlag, TFlagVariation, TFlags } from '@flopflip/types';
22

3-
import defaultNormalizeFlag from '../normalize-flag/normalize-flag';
3+
import { normalizeFlag as defaultNormalizeFlag } from '../normalize-flag/normalize-flag';
44

55
const normalizeFlags = (
66
rawFlags: TFlags,
@@ -20,4 +20,4 @@ const normalizeFlags = (
2020
{}
2121
);
2222

23-
export default normalizeFlags;
23+
export { normalizeFlags };

packages/cache/src/cache/cache.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { adapterIdentifiers, cacheIdentifiers } from '@flopflip/types';
2+
import { describe, expect, it } from 'vitest';
23

34
import {
45
encodeCacheContext,

packages/cache/src/cache/cache.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async function getCache(
5252
const cacheModule = await importCache(cacheIdentifier);
5353

5454
const CACHE_PREFIX = getCachePrefix(adapterIdentifiers);
55-
const createCache = cacheModule.default;
55+
const createCache = cacheModule.createCache;
5656
let encodedCacheContext = '';
5757
try {
5858
encodedCacheContext = encodeCacheContext(cacheContext);

0 commit comments

Comments
 (0)