Skip to content

Commit 34bbcd8

Browse files
authored
test(e2e): isolate build/ rstest spawns to per-fixture cwd (#1247)
1 parent 2708045 commit 34bbcd8

5 files changed

Lines changed: 34 additions & 49 deletions

File tree

.agents/skills/testing/SKILL.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ Important:
7979
- Keep fixtures minimal and representative of the behavior under test
8080
- Don't create near-duplicate fixtures just to add one extra test case
8181

82+
## E2E rstest spawns with persistent `dist/.rstest-temp/`
83+
84+
A fixture that enables `performance.buildCache` (or `dev.writeToDisk: true`) forces rstest to persist the built bundle under `<cwd>/dist/.rstest-temp/`. If sibling test files share that `cwd`, those persistent writes race against any test asserting on the default path. Other disk writers like coverage or blob reporters land in `<cwd>/coverage/` or `<cwd>/.rstest-reports/` — different surfaces, not covered by this rule.
85+
86+
When your fixture enables persistent build output:
87+
88+
- Set `cwd` to the fixture subdirectory, not the parent test directory.
89+
- In that fixture's config, drop any `include` referencing paths outside the fixture (e.g. `'./fixtures/<name>/index.test.ts'`). Fixture-local globs like `'./*.test.ts'` are fine.
90+
- Read `dist/.rstest-temp/` assertions from that isolated fixture dir, not from a shared parent.
91+
8292
## Snapshot policy
8393

8494
- Only update snapshots when the behavioral change is **intentional**

e2e/build/buildCache.test.ts

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ describe('test build cache config', () => {
1111
it('should enable build cache with rstest-aware dependencies and keep warm runs measurable', async ({
1212
onTestFinished,
1313
}) => {
14-
const fixtureName = 'buildCache';
15-
const cacheDir = join(__dirname, '.cache/build-cache-fixture');
16-
const outputDir = join(__dirname, 'dist/.rstest-temp');
14+
const fixtureDir = join(__dirname, 'fixtures/buildCache');
15+
const cacheDir = join(fixtureDir, '.cache/build-cache-fixture');
16+
const outputDir = join(fixtureDir, 'dist/.rstest-temp');
1717
const inspectDir = join(outputDir, '.rsbuild');
1818

1919
fs.rmSync(cacheDir, { recursive: true, force: true });
@@ -23,16 +23,11 @@ describe('test build cache config', () => {
2323
const start = Date.now();
2424
const result = await runRstestCli({
2525
command: 'rstest',
26-
args: [
27-
'run',
28-
`fixtures/${fixtureName}`,
29-
'-c',
30-
`fixtures/${fixtureName}/rstest.config.mts`,
31-
],
26+
args: ['run'],
3227
onTestFinished,
3328
options: {
3429
nodeOptions: {
35-
cwd: __dirname,
30+
cwd: fixtureDir,
3631
env: {
3732
DEBUG: 'rstest',
3833
},
@@ -75,25 +70,20 @@ describe('test build cache config', () => {
7570
it('should collect happy-dom build cache timing data on a non-trivial fixture', async ({
7671
onTestFinished,
7772
}) => {
78-
const fixtureName = 'happyDomBuildCache';
79-
const cacheDir = join(__dirname, '.cache/happy-dom-build-cache');
73+
const fixtureDir = join(__dirname, 'fixtures/happyDomBuildCache');
74+
const cacheDir = join(fixtureDir, '.cache/happy-dom-build-cache');
8075

8176
fs.rmSync(cacheDir, { recursive: true, force: true });
8277

8378
const runWithTiming = async () => {
8479
const start = Date.now();
8580
const result = await runRstestCli({
8681
command: 'rstest',
87-
args: [
88-
'run',
89-
`fixtures/${fixtureName}`,
90-
'-c',
91-
`fixtures/${fixtureName}/rstest.config.mts`,
92-
],
82+
args: ['run'],
9383
onTestFinished,
9484
options: {
9585
nodeOptions: {
96-
cwd: __dirname,
86+
cwd: fixtureDir,
9787
},
9888
},
9989
});
@@ -118,24 +108,19 @@ describe('test build cache config', () => {
118108
it('should keep virtual module mocks stable across cold and warm build cache runs', async ({
119109
onTestFinished,
120110
}) => {
121-
const fixtureName = 'mockBuildCache';
122-
const cacheDir = join(__dirname, '.cache/mock-build-cache');
111+
const fixtureDir = join(__dirname, 'fixtures/mockBuildCache');
112+
const cacheDir = join(fixtureDir, '.cache/mock-build-cache');
123113

124114
fs.rmSync(cacheDir, { recursive: true, force: true });
125115

126116
const runFixture = async () => {
127117
const result = await runRstestCli({
128118
command: 'rstest',
129-
args: [
130-
'run',
131-
`fixtures/${fixtureName}`,
132-
'-c',
133-
`fixtures/${fixtureName}/rstest.config.mts`,
134-
],
119+
args: ['run'],
135120
onTestFinished,
136121
options: {
137122
nodeOptions: {
138-
cwd: __dirname,
123+
cwd: fixtureDir,
139124
},
140125
},
141126
});

e2e/build/fixtures/buildCache/rstest.config.mts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { defineConfig } from '@rstest/core';
22

33
export default defineConfig({
4-
include: ['./fixtures/buildCache/index.test.ts'],
54
performance: {
65
buildCache: {
76
cacheDirectory: '.cache/build-cache-fixture',
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { defineConfig } from '@rstest/core';
22

33
export default defineConfig({
4-
include: ['./fixtures/happyDomBuildCache/index.test.ts'],
54
testEnvironment: 'happy-dom',
65
performance: {
76
buildCache: {
87
cacheDirectory: '.cache/happy-dom-build-cache',
98
cacheDigest: ['happy-dom-fixture'],
10-
buildDependencies: ['./fixtures/happyDomBuildCache/rstest.config.mts'],
119
},
1210
},
1311
});

e2e/build/index.test.ts

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,16 @@ describe('test build config', () => {
1717
])(
1818
'$name config should work correctly',
1919
async ({ name }, { onTestFinished }) => {
20+
// Run each fixture inside its own directory so the default output path
21+
// (dist/.rstest-temp) is scoped to that fixture and never collides with
22+
// sibling test files that also spawn rstest under e2e/build/.
2023
const { expectExecSuccess } = await runRstestCli({
2124
command: 'rstest',
22-
args: [
23-
'run',
24-
`fixtures/${name}`,
25-
'-c',
26-
`fixtures/${name}/rstest.config.mts`,
27-
],
25+
args: ['run'],
2826
onTestFinished,
2927
options: {
3028
nodeOptions: {
31-
cwd: __dirname,
29+
cwd: join(__dirname, 'fixtures', name),
3230
},
3331
},
3432
});
@@ -40,28 +38,23 @@ describe('test build config', () => {
4038
it('should write output to customized distPath.root', async ({
4139
onTestFinished,
4240
}) => {
43-
const defaultOutputPath = join(__dirname, 'dist/.rstest-temp');
44-
const customOutputPath = join(__dirname, 'custom/.rstest-temp');
41+
const fixtureDir = join(__dirname, 'fixtures/customOutput');
42+
const defaultOutputPath = join(fixtureDir, 'dist/.rstest-temp');
43+
const customOutputPath = join(fixtureDir, 'custom/.rstest-temp');
4544

4645
fs.rmSync(defaultOutputPath, { recursive: true, force: true });
47-
fs.rmSync(join(__dirname, 'custom'), {
46+
fs.rmSync(join(fixtureDir, 'custom'), {
4847
recursive: true,
4948
force: true,
5049
});
51-
fs.rmSync(join(defaultOutputPath, 'rstest-manifest.json'), { force: true });
5250

5351
const { expectExecSuccess } = await runRstestCli({
5452
command: 'rstest',
55-
args: [
56-
'run',
57-
'fixtures/customOutput',
58-
'-c',
59-
'fixtures/customOutput/rstest.config.mts',
60-
],
53+
args: ['run'],
6154
onTestFinished,
6255
options: {
6356
nodeOptions: {
64-
cwd: __dirname,
57+
cwd: fixtureDir,
6558
},
6659
},
6760
});

0 commit comments

Comments
 (0)