Skip to content

Commit bed5097

Browse files
authored
chore: use isFirstCompile instead of isFirstRun (#506)
1 parent 29967cb commit bed5097

File tree

4 files changed

+12
-24
lines changed

4 files changed

+12
-24
lines changed

e2e/watch/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('watch', () => {
2828
await cli.waitForStdout('Duration');
2929
expect(cli.stdout).toMatch('Tests 1 passed');
3030
expect(cli.stdout).not.toMatch('Test files to re-run:');
31-
expect(cli.stdout).toMatch('Fully run test files for first run.');
31+
expect(cli.stdout).toMatch('Run all tests.');
3232

3333
// create
3434
cli.resetStd();

e2e/watch/shortcuts.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('CLI shortcuts', () => {
3737
await cli.waitForStdout('Duration');
3838
expect(cli.stdout).toMatch('Tests 1 failed | 1 passed');
3939
await cli.waitForStdout('press h to show help');
40-
expect(cli.stdout).toMatch('Fully run test files for first run.');
40+
expect(cli.stdout).toMatch('Run all tests.');
4141

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

@@ -82,7 +82,7 @@ describe('CLI shortcuts', () => {
8282
await cli.waitForStdout('Duration');
8383
expect(cli.stdout).toMatch('Tests 1 failed | 1 passed');
8484
await cli.waitForStdout('press h to show help');
85-
expect(cli.stdout).toMatch('Fully run test files for first run.');
85+
expect(cli.stdout).toMatch('Run all tests.');
8686
cli.resetStd();
8787

8888
// rerun failed tests

packages/core/src/core/rsbuild.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,13 @@ export const createRsbuildServer = async ({
228228
assetFiles: Record<string, string>;
229229
sourceMaps: Record<string, SourceMapInput>;
230230
getSourcemap: (sourcePath: string) => SourceMapInput | null;
231-
isFirstRun: boolean;
232231
affectedEntries: EntryInfo[];
233232
deletedEntries: string[];
234233
}>;
235234
closeServer: () => Promise<void>;
236235
}> => {
237236
// Read files from memory via `rspackCompiler.outputFileSystem`
238237
let rspackCompiler: Rspack.Compiler | Rspack.MultiCompiler | undefined;
239-
let isFirstCompile = false;
240238

241239
const rstestCompilerPlugin: RsbuildPlugin = {
242240
name: 'rstest:compiler',
@@ -245,10 +243,6 @@ export const createRsbuildServer = async ({
245243
// outputFileSystem to be updated later by `rsbuild-dev-middleware`
246244
rspackCompiler = compiler;
247245
});
248-
249-
api.onAfterDevCompile(({ isFirstCompile: _isFirstCompile }) => {
250-
isFirstCompile = _isFirstCompile;
251-
});
252246
},
253247
};
254248

@@ -410,7 +404,6 @@ export const createRsbuildServer = async ({
410404
return {
411405
affectedEntries,
412406
deletedEntries,
413-
isFirstRun: isFirstCompile,
414407
hash,
415408
entries,
416409
setupEntries,

packages/core/src/core/runTests.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,28 +122,23 @@ export async function runTests(context: Rstest): Promise<void> {
122122
getSourcemap,
123123
buildTime,
124124
hash,
125-
isFirstRun,
126125
affectedEntries,
127126
deletedEntries,
128127
} = await getRsbuildStats({ fileFilters });
129128
const testStart = Date.now();
130129

131130
let finalEntries: EntryInfo[] = entries;
132131
if (mode === 'on-demand') {
133-
if (isFirstRun) {
134-
logger.debug(color.yellow('Fully run test files for first run.\n'));
132+
if (affectedEntries.length === 0) {
133+
logger.debug(color.yellow('No test files are re-run.'));
135134
} else {
136-
if (affectedEntries.length === 0) {
137-
logger.debug(color.yellow('No test files are re-run.'));
138-
} else {
139-
logger.debug(
140-
color.yellow('Test files to re-run:\n') +
141-
affectedEntries.map((e) => e.testPath).join('\n') +
142-
'\n',
143-
);
144-
}
145-
finalEntries = affectedEntries;
135+
logger.debug(
136+
color.yellow('Test files to re-run:\n') +
137+
affectedEntries.map((e) => e.testPath).join('\n') +
138+
'\n',
139+
);
146140
}
141+
finalEntries = affectedEntries;
147142
} else {
148143
logger.debug(
149144
color.yellow(
@@ -228,7 +223,7 @@ export async function runTests(context: Rstest): Promise<void> {
228223

229224
rsbuildInstance.onAfterDevCompile(async ({ isFirstCompile }) => {
230225
snapshotManager.clear();
231-
await run({ mode: 'on-demand' });
226+
await run({ mode: isFirstCompile ? 'all' : 'on-demand' });
232227

233228
if (isFirstCompile && enableCliShortcuts) {
234229
const closeCliShortcuts = await setupCliShortcuts({

0 commit comments

Comments
 (0)