Skip to content

Commit aaeed91

Browse files
authored
test: stabilize watch environment comments (#1416)
1 parent 58f592b commit aaeed91

2 files changed

Lines changed: 66 additions & 43 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import path from 'node:path';
2+
import { fileURLToPath } from 'node:url';
3+
import { describe, expect, it, rs } from '@rstest/core';
4+
import { prepareFixtures, runRstestCli } from '../scripts';
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
9+
rs.setConfig({
10+
retry: 3,
11+
});
12+
13+
const getRerunSection = (stdout: string): string => {
14+
const match = stdout.match(/Test files to re-run.*?:\n([\s\S]*?)\n\n/);
15+
return match?.[1] ?? '';
16+
};
17+
18+
describe.skipIf(process.platform === 'win32')(
19+
'watch environment comments',
20+
() => {
21+
it('should honor environment comments', async () => {
22+
const fixturesTargetPath = `${__dirname}/fixtures-test-environment-comment${process.env.RSTEST_OUTPUT_MODULE !== 'false' ? '-module' : ''}`;
23+
24+
const { fs } = await prepareFixtures({
25+
fixturesPath: `${__dirname}/fixtures-environment-comment`,
26+
fixturesTargetPath,
27+
});
28+
29+
const { cli } = await runRstestCli({
30+
command: 'rstest',
31+
args: ['watch', '--disableConsoleIntercept'],
32+
options: {
33+
nodeOptions: {
34+
env: { DEBUG: 'rstest' },
35+
cwd: fixturesTargetPath,
36+
},
37+
},
38+
});
39+
40+
await cli.waitForStdout('Tests 2 passed');
41+
expect(cli.stdout).toMatch(
42+
'Run all tests in project(rstest-environment-1).',
43+
);
44+
expect(cli.stdout).toMatch(
45+
'Run all tests in project(rstest-environment-2).',
46+
);
47+
if (!cli.stdout.includes('Waiting for file changes...')) {
48+
await cli.waitForStdout('Waiting for file changes...');
49+
}
50+
51+
cli.resetStd();
52+
fs.update(path.join(fixturesTargetPath, 'src/index.ts'), (content) => {
53+
return content.replace("'initial'", "'initial' as const");
54+
});
55+
56+
await cli.waitForStdout('Test files to re-run');
57+
await cli.waitForStdout('Tests 2 passed');
58+
59+
const rerunSection = getRerunSection(cli.stdout);
60+
expect(rerunSection).toMatch('index.test.ts');
61+
expect(rerunSection).not.toMatch('node.test.ts');
62+
63+
cli.exec.kill();
64+
});
65+
},
66+
);

e2e/watch/index.test.ts

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -39,49 +39,6 @@ const expectRerun = (
3939
// TODO: The following error occurs only on Windows CI. It should appear in the Rspack version range from 1.5.0 to 1.6.0-beta.0.
4040
// Error: EBUSY: resource busy or locked, rmdir 'D:\a\rstest\rstest\e2e\watch\fixtures-test-0'
4141
describe.skipIf(process.platform === 'win32')('watch', () => {
42-
it('should honor environment comments', async () => {
43-
const fixturesTargetPath = `${__dirname}/fixtures-test-environment-comment${process.env.RSTEST_OUTPUT_MODULE !== 'false' ? '-module' : ''}`;
44-
45-
const { fs } = await prepareFixtures({
46-
fixturesPath: `${__dirname}/fixtures-environment-comment`,
47-
fixturesTargetPath,
48-
});
49-
50-
const { cli } = await runRstestCli({
51-
command: 'rstest',
52-
args: ['watch', '--disableConsoleIntercept'],
53-
options: {
54-
nodeOptions: {
55-
env: { DEBUG: 'rstest' },
56-
cwd: fixturesTargetPath,
57-
},
58-
},
59-
});
60-
61-
await cli.waitForStdout('Duration');
62-
expect(cli.stdout).toMatch('Tests 2 passed');
63-
expect(cli.stdout).toMatch(
64-
'Run all tests in project(rstest-environment-1).',
65-
);
66-
expect(cli.stdout).toMatch(
67-
'Run all tests in project(rstest-environment-2).',
68-
);
69-
70-
cli.resetStd();
71-
fs.update(path.join(fixturesTargetPath, 'src/index.ts'), (content) => {
72-
return content.replace("'initial'", "'changed'");
73-
});
74-
75-
await cli.waitForStdout('Duration');
76-
expectRerun(
77-
cli.stdout,
78-
['index.test.ts'],
79-
['index.test.ts', 'node.test.ts'],
80-
);
81-
82-
cli.exec.kill();
83-
});
84-
8542
it('should rerun only affected test files when source changes', async () => {
8643
const fixturesTargetPath = `${__dirname}/fixtures-test-0${process.env.RSTEST_OUTPUT_MODULE !== 'false' ? '-module' : ''}`;
8744

0 commit comments

Comments
 (0)