Skip to content
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6223563
feat: init projects config
9aoy Jul 23, 2025
2c7175e
fix: merge conflict
9aoy Jul 23, 2025
8a6f5d6
Merge branch 'main' of https://github.com/web-infra-dev/rstest into p…
9aoy Jul 24, 2025
d2b564a
feat: support test projects
9aoy Jul 25, 2025
dc73f68
fix: setupFiles
9aoy Jul 25, 2025
434eaaf
fix: merge conflict
9aoy Jul 25, 2025
e230567
feat: support glob pattern
9aoy Jul 25, 2025
3a42499
fix: should throw error when project not found
9aoy Jul 25, 2025
bf5a5e6
feat: should run test failed when test file not found
9aoy Jul 29, 2025
3ac39e0
Merge branch 'main' of https://github.com/web-infra-dev/rstest into p…
9aoy Jul 29, 2025
a0ad3f0
fix: merge conflict
9aoy Jul 29, 2025
83105ff
fix: tests
9aoy Jul 29, 2025
afc83ef
perf: reuse pool
9aoy Jul 29, 2025
1855377
fix: merge conflict
9aoy Aug 1, 2025
32a2f1c
fix: merge conflict
9aoy Aug 8, 2025
146adf6
fix: lint
9aoy Aug 11, 2025
446a423
fix: formatEnvironmentName
9aoy Aug 11, 2025
b2cb773
fix: merge conflict
9aoy Aug 11, 2025
94d1279
fix: project rootPath
9aoy Aug 11, 2025
1d7d7fc
fix: merge conflict
9aoy Aug 25, 2025
3370a75
fix: should not inherit root config by default
9aoy Aug 25, 2025
1841fe4
docs: add projects config
9aoy Aug 25, 2025
32ad196
fix: merge conflict
9aoy Aug 25, 2025
863ede7
fix: update `no test files found` log
9aoy Aug 25, 2025
cc74f9e
fix: update log
9aoy Aug 26, 2025
3ca6e0b
Update website/docs/zh/config/test/projects.mdx
9aoy Aug 26, 2025
e7a861f
Update website/docs/en/config/test/projects.mdx
fi3ework Aug 26, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@ jobs:

- name: E2E Test
if: steps.changes.outputs.changed == 'true'
run: pnpm run e2e && pnpm run test:example
run: pnpm run e2e
2 changes: 1 addition & 1 deletion e2e/build/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('test build config', () => {
command: 'rstest',
args: [
'run',
`fixtures/${name}/index.test.ts`,
`fixtures/${name}`,
'-c',
`fixtures/${name}/rstest.config.ts`,
],
Expand Down
3 changes: 2 additions & 1 deletion e2e/dom/fixtures/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"scripts": {
"dev": "rsbuild dev --open",
"build": "rsbuild build",
"preview": "rsbuild preview"
"preview": "rsbuild preview",
"test": "rstest run"
},
"dependencies": {
"react": "^19.1.1",
Expand Down
1 change: 1 addition & 0 deletions e2e/dom/fixtures/rstest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import rsbuildConfig from './rsbuild.config';
export default defineConfig({
...(rsbuildConfig as RstestConfig),
setupFiles: ['./test/setup.ts'],
testEnvironment: 'jsdom',
});
1 change: 1 addition & 0 deletions e2e/dom/fixtures/rstest.externals.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import rsbuildConfig from './rsbuild.config';
export default defineConfig({
...(rsbuildConfig as RstestConfig),
setupFiles: ['./test/setup.ts'],
testEnvironment: 'jsdom',
output: {
externals: [/react/],
},
Expand Down
25 changes: 25 additions & 0 deletions e2e/projects/fixtures/packages/client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@rstest/tests-project-client",
"private": true,
"scripts": {
"dev": "rsbuild dev --open",
"build": "rsbuild build",
"test": "rstest run",
"preview": "rsbuild preview"
},
"dependencies": {
"react": "^19.1.1",
"react-dom": "^19.1.1"
},
"devDependencies": {
"@rsbuild/core": "1.5.0-rc.0",
"@rsbuild/plugin-react": "^1.3.5",
"@testing-library/jest-dom": "^6.8.0",
"@testing-library/dom": "^10.4.1",
"@testing-library/react": "^16.3.0",
"@types/react": "^19.1.10",
"@types/react-dom": "^19.1.7",
"jsdom": "^26.1.0",
"typescript": "^5.9.2"
}
}
6 changes: 6 additions & 0 deletions e2e/projects/fixtures/packages/client/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';

export default defineConfig({
plugins: [pluginReact()],
});
8 changes: 8 additions & 0 deletions e2e/projects/fixtures/packages/client/rstest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig, type RstestConfig } from '@rstest/core';
import rsbuildConfig from './rsbuild.config';

export default defineConfig({
...(rsbuildConfig as RstestConfig),
testEnvironment: 'jsdom',
setupFiles: ['./test/setup.ts'],
});
10 changes: 10 additions & 0 deletions e2e/projects/fixtures/packages/client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const App = () => {
return (
<div className="content">
<h1>Rsbuild with React</h1>
<p>Start building amazing things with Rsbuild.</p>
</div>
);
};

export default App;
1 change: 1 addition & 0 deletions e2e/projects/fixtures/packages/client/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="@rsbuild/core/types" />
13 changes: 13 additions & 0 deletions e2e/projects/fixtures/packages/client/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';

const rootEl = document.getElementById('root');
if (rootEl) {
const root = ReactDOM.createRoot(rootEl);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>,
);
}
17 changes: 17 additions & 0 deletions e2e/projects/fixtures/packages/client/test/App.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect, test } from '@rstest/core';
import { render, screen } from '@testing-library/react';
import App from '../src/App';

test('should render App correctly', async () => {
render(<App />);

const element = screen.getByText('Rsbuild with React');

expect(element.tagName).toBe('H1');

expect(element.constructor).toBe(document.defaultView?.HTMLHeadingElement);
});

test('should get document correctly', () => {
expect(global.document).toBeDefined();
});
4 changes: 4 additions & 0 deletions e2e/projects/fixtures/packages/client/test/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { expect } from '@rstest/core';
import * as jestDomMatchers from '@testing-library/jest-dom/matchers';

expect.extend(jestDomMatchers);
1 change: 1 addition & 0 deletions e2e/projects/fixtures/packages/client/test/test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="@testing-library/jest-dom" />
1 change: 1 addition & 0 deletions e2e/projects/fixtures/packages/node/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const sayHi = () => 'hi';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Rstest Snapshot v1

exports[`should generate snapshot correctly 1`] = `"hello world"`;
13 changes: 13 additions & 0 deletions e2e/projects/fixtures/packages/node/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { sayHi } from '../src/index';

it('should test source code correctly', () => {
expect(sayHi()).toBe('hi');
});

it('should can not get document', () => {
expect(global.document).toBeUndefined();
});

it('should generate snapshot correctly', () => {
expect('hello world').toMatchSnapshot();
});
7 changes: 7 additions & 0 deletions e2e/projects/fixtures/rstest.404.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from '@rstest/core';

export default defineConfig({
projects: ['packages/*', '404'],
globals: true,
setupFiles: ['./setup.ts'],
});
7 changes: 7 additions & 0 deletions e2e/projects/fixtures/rstest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from '@rstest/core';

export default defineConfig({
projects: ['packages/*'],
globals: true,
setupFiles: ['./setup.ts'],
});
1 change: 1 addition & 0 deletions e2e/projects/fixtures/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw new Error('root setup file error');
117 changes: 117 additions & 0 deletions e2e/projects/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, expect, it } from '@rstest/core';
import { runRstestCli } from '../scripts';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

describe('test projects', () => {
describe('merge configs', () => {
it('should run projects correctly with cli options', async () => {
const { cli, expectExecSuccess } = await runRstestCli({
command: 'rstest',
args: ['run', '--globals'],
options: {
nodeOptions: {
cwd: join(__dirname, 'fixtures'),
},
},
});

await expectExecSuccess();
const logs = cli.stdout.split('\n').filter(Boolean);

// test log print
expect(
logs.find((log) => log.includes('packages/node/test/index.test.ts')),
).toBeTruthy();
expect(
logs.find((log) => log.includes('packages/client/test/App.test.tsx')),
).toBeTruthy();
});

it('should not inherit projects config and run projects failed ', async () => {
const { cli } = await runRstestCli({
command: 'rstest',
args: ['run'],
options: {
nodeOptions: {
cwd: join(__dirname, 'fixtures'),
},
},
});

await cli.exec;
expect(cli.exec.process?.exitCode).toBe(1);
const logs = cli.stdout.split('\n').filter(Boolean);

// test log print
expect(
logs.find((log) => log.includes('it is not defined')),
).toBeTruthy();
});
});

it('should run projects fail when project not found', async () => {
const { cli } = await runRstestCli({
command: 'rstest',
args: ['run', '-c', 'rstest.404.config.ts'],
options: {
nodeOptions: {
cwd: join(__dirname, 'fixtures'),
},
},
});

await cli.exec;
expect(cli.exec.process?.exitCode).toBe(1);
const logs = cli.stdout.split('\n').filter(Boolean);

// test log print
expect(
logs.find((log) => log.includes(`Can't resolve project "404"`)),
).toBeTruthy();
});

it('should run test failed when test file not found', async () => {
const { cli } = await runRstestCli({
command: 'rstest',
args: ['run', '404-file', '--globals'],
options: {
nodeOptions: {
cwd: join(__dirname, 'fixtures'),
},
},
});

await cli.exec;
expect(cli.exec.process?.exitCode).toBe(1);
const logs = cli.stdout.split('\n').filter(Boolean);

// test log print
expect(
logs.find((log) => log.includes('No test files found')),
).toBeTruthy();
});

it('should run test success when test file not found with passWithNoTests flag', async () => {
const { cli, expectExecSuccess } = await runRstestCli({
command: 'rstest',
args: ['run', '404-file', '--passWithNoTests', '--globals'],
options: {
nodeOptions: {
cwd: join(__dirname, 'fixtures'),
},
},
});

await expectExecSuccess();
const logs = cli.stdout.split('\n').filter(Boolean);

// test log print
expect(
logs.find((log) => log.includes('No test files found')),
).toBeTruthy();
});
});
6 changes: 3 additions & 3 deletions e2e/watch/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('watch', () => {
await cli.waitForStdout('Duration');
expect(cli.stdout).toMatch('Tests 1 passed');
expect(cli.stdout).not.toMatch('Test files to re-run:');
expect(cli.stdout).toMatch('Run all tests.');
expect(cli.stdout).toMatch('Run all tests in project');

// create
cli.resetStd();
Expand All @@ -44,7 +44,7 @@ describe('watch', () => {

await cli.waitForStdout('Duration');
expect(cli.stdout).toMatch('Tests 2 passed');
expect(cli.stdout).toMatch(/Test files to re-run:\n.*bar\.test\.ts\n\n/);
expect(cli.stdout).toMatch(/Test files to re-run.*:\n.*bar\.test\.ts\n\n/);

// update
cli.resetStd();
Expand All @@ -55,7 +55,7 @@ describe('watch', () => {
await cli.waitForStdout('Duration');
expect(cli.stdout).toMatch('Test Files 1 failed');
expect(cli.stdout).toMatch('✗ bar > bar should be to bar');
expect(cli.stdout).toMatch(/Test files to re-run:\n.*bar\.test\.ts\n\n/);
expect(cli.stdout).toMatch(/Test files to re-run.*:\n.*bar\.test\.ts\n\n/);

// delete
cli.resetStd();
Expand Down
8 changes: 4 additions & 4 deletions e2e/watch/shortcuts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('CLI shortcuts', () => {
await cli.waitForStdout('Duration');
expect(cli.stdout).toMatch('Tests 1 failed | 1 passed');
await cli.waitForStdout('press h to show help');
expect(cli.stdout).toMatch('Run all tests.');
expect(cli.stdout).toMatch('Run all tests in project');

cli.exec.process!.stdin!.write('h');

Expand All @@ -51,7 +51,7 @@ describe('CLI shortcuts', () => {
cli.exec.process!.stdin!.write('a');
await cli.waitForStdout('Duration');
expect(cli.stdout).toMatch('Tests 1 failed | 1 passed');
expect(cli.stdout).toMatch('Run all tests.');
expect(cli.stdout).toMatch('Run all tests');

cli.exec.kill();
});
Expand Down Expand Up @@ -82,14 +82,14 @@ describe('CLI shortcuts', () => {
await cli.waitForStdout('Duration');
expect(cli.stdout).toMatch('Tests 1 failed | 1 passed');
await cli.waitForStdout('press h to show help');
expect(cli.stdout).toMatch('Run all tests.');
expect(cli.stdout).toMatch('Run all tests in project');
cli.resetStd();

// rerun failed tests
cli.exec.process!.stdin!.write('f');
await cli.waitForStdout('Duration');
expect(cli.stdout).toMatch('Tests 1 failed');
expect(cli.stdout).toMatch('Run filtered tests.');
expect(cli.stdout).toMatch('Run filtered tests');

cli.exec.kill();
});
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"build": "cross-env NX_DAEMON=false nx run-many -t build --exclude @examples/* @rstest/tests-* --parallel=10",
"e2e": "cd e2e && pnpm test",
"test": "rstest",
"test:example": "pnpm --filter @examples/* test",
"change": "changeset",
"changeset": "changeset",
"check-dependency-version": "pnpx check-dependency-version-consistency . && echo",
Expand Down
6 changes: 6 additions & 0 deletions packages/core/rstest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from '@rstest/core';

export default defineConfig({
setupFiles: ['../../scripts/rstest.setup.ts'],
globals: true,
});
Loading
Loading