Skip to content

Commit 95dee40

Browse files
committed
chore: supersede Vitest with Rstest
1 parent 8e02535 commit 95dee40

File tree

13 files changed

+59
-18
lines changed

13 files changed

+59
-18
lines changed

biome.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"!**/*.vue",
4949
"!**/.rslib/**/*",
5050
"!tests/integration/**/*/src/**/*",
51-
"!tests/e2e/react-component/public/umd/**/*"
51+
"!tests/e2e/react-component/public/umd/**/*",
52+
"!**/.rstest-temp/**"
5253
],
5354
"rules": {
5455
"recommended": true,

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"devDependencies": {
4545
"@biomejs/biome": "^2.0.4",
4646
"@changesets/cli": "^2.29.5",
47+
"@rstest/core": "link:../rstest/packages/core",
4748
"@types/fs-extra": "^11.0.4",
4849
"@types/node": "^22.15.32",
4950
"check-dependency-version-consistency": "^5.0.1",
@@ -75,6 +76,7 @@
7576
"simple-git-hooks"
7677
],
7778
"overrides": {
79+
"@rstest/core": "link:../rstest/packages/core",
7880
"zx>@types/node": "-"
7981
}
8082
}

packages/core/rstest.config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { defineConfig } from '@rstest/core';
2+
// import { shared } from '../../vitest.workspace';
3+
4+
export default defineConfig({
5+
// test: {
6+
// ...shared,
7+
globals: true,
8+
testEnvironment: 'node',
9+
testTimeout: 60000,
10+
restoreMocks: true,
11+
exclude: ['**/node_modules/**'],
12+
name: 'unit',
13+
// },
14+
});

packages/core/tests/__snapshots__/config.test.ts.snap

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
1+
// Rstest Snapshot v1
22

33
exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config in each format 1`] = `
44
[
@@ -15,6 +15,16 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
1515
},
1616
"externals": [
1717
[Function],
18+
/\\^@rsbuild\\\\/core\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
19+
/\\^rsbuild-plugin-dts\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
20+
/\\^tinyglobby\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
21+
/\\^@microsoft\\\\/api-extractor\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
22+
/\\^typescript\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
23+
"@rsbuild/core",
24+
"rsbuild-plugin-dts",
25+
"tinyglobby",
26+
"@microsoft/api-extractor",
27+
"typescript",
1828
"assert",
1929
"assert/strict",
2030
"async_hooks",
@@ -73,7 +83,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
7383
"pnpapi",
7484
],
7585
"filename": {
76-
"js": "[name].mjs",
86+
"js": "[name].js",
7787
},
7888
"filenameHash": false,
7989
"minify": {
@@ -264,6 +274,16 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
264274
"jsAsync": "./",
265275
},
266276
"externals": [
277+
/\\^@rsbuild\\\\/core\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
278+
/\\^rsbuild-plugin-dts\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
279+
/\\^tinyglobby\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
280+
/\\^@microsoft\\\\/api-extractor\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
281+
/\\^typescript\\(\\$\\|\\\\/\\|\\\\\\\\\\)/,
282+
"@rsbuild/core",
283+
"rsbuild-plugin-dts",
284+
"tinyglobby",
285+
"@microsoft/api-extractor",
286+
"typescript",
267287
"assert",
268288
"assert/strict",
269289
"async_hooks",
@@ -322,7 +342,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
322342
"pnpapi",
323343
],
324344
"filename": {
325-
"js": "[name].js",
345+
"js": "[name].cjs",
326346
},
327347
"filenameHash": false,
328348
"minify": {

packages/core/tests/config.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { join } from 'node:path';
22
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
3-
import { describe, expect, test, vi } from 'vitest';
3+
import { describe, expect, rs, test } from '@rstest/core';
44
import {
55
composeCreateRsbuildConfig,
66
composeRsbuildEnvironments,
77
loadConfig,
88
} from '../src/config';
99
import type { RslibConfig } from '../src/types/config';
1010

11-
vi.mock('rslog');
11+
rs.mock('rslog');
1212

1313
describe('Should load config file correctly', () => {
1414
test('Load config.js in cjs project', async () => {

packages/core/tests/constant.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, test } from 'vitest';
1+
import { expect, test } from '@rstest/core';
22
import {
33
CSS_EXTENSIONS_PATTERN,
44
DTS_EXTENSIONS_PATTERN,

packages/core/tests/extension.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, it, vi } from 'vitest';
1+
import { describe, expect, it, rs } from '@rstest/core';
22
import type { Format, PkgJson } from '../src/types';
33
import { getDefaultExtension } from '../src/utils/extension';
44

@@ -8,7 +8,7 @@ type Options = {
88
autoExtension: boolean;
99
};
1010

11-
vi.mock('rslog');
11+
rs.mock('rslog');
1212

1313
describe('should get extension correctly', () => {
1414
it('autoExtension is false', () => {

packages/core/tests/external.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { describe, expect, it, vi } from 'vitest';
1+
import { describe, expect, it, rs } from '@rstest/core';
22
import { composeAutoExternalConfig } from '../src/config';
33

4-
vi.mock('rslog');
4+
rs.mock('rslog');
55

66
describe('should composeAutoExternalConfig correctly', () => {
77
it('autoExternal default value', () => {

packages/core/tests/helper.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { join } from 'node:path';
2-
import { expect, it, vi } from 'vitest';
2+
import { expect, it, rs } from '@rstest/core';
33
import { checkMFPlugin, readPackageJson } from '../src/utils/helper';
44

5-
vi.mock('rslog');
5+
rs.mock('rslog');
66

77
it('readPackageJson correctly', async () => {
88
expect(readPackageJson('path/to/root')).toBeUndefined();

packages/core/tests/lcp.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import os from 'node:os';
2+
import { beforeEach, describe, expect, it, rs } from '@rstest/core';
23
import { vol } from 'memfs';
3-
import { beforeEach, describe, expect, it, vi } from 'vitest';
44
import { calcLongestCommonPath } from '../src/utils/helper';
55

6-
vi.mock('node:fs');
7-
vi.mock('node:fs/promises');
6+
rs.mock('node:fs');
7+
rs.mock('node:fs/promises');
88

99
// LCP test mock will affect other tests
1010
describe('LCP calculate correctly', () => {

0 commit comments

Comments
 (0)