Skip to content

Commit 5b416e0

Browse files
committed
clear
1 parent 24c3bcd commit 5b416e0

File tree

4 files changed

+41
-28
lines changed

4 files changed

+41
-28
lines changed

e2e/watch/index.test.ts

Lines changed: 2 additions & 2 deletions
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.');
31+
expect(cli.stdout).toMatch('Fully run test files for first run.');
3232

3333
// create
3434
cli.resetStd();
@@ -61,7 +61,7 @@ describe('watch', () => {
6161
cli.resetStd();
6262
fs.delete('./fixtures-test-0/bar.test.ts');
6363
await cli.waitForStdout('Duration');
64-
expect(cli.stdout).toMatch('Fully run test files.');
64+
expect(cli.stdout).toMatch('No test files are re-run.');
6565
expect(cli.stdout).toMatch('Test Files 1 passed');
6666

6767
cli.exec.kill();

e2e/watch/shortcuts.test.ts

Lines changed: 4 additions & 3 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.');
40+
expect(cli.stdout).toMatch('Fully run test files for first run.');
4141

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

@@ -51,7 +51,7 @@ describe('CLI shortcuts', () => {
5151
cli.exec.process!.stdin!.write('a');
5252
await cli.waitForStdout('Duration');
5353
expect(cli.stdout).toMatch('Tests 1 failed | 1 passed');
54-
expect(cli.stdout).toMatch('Fully run test files.');
54+
expect(cli.stdout).toMatch('Run all tests.');
5555

5656
cli.exec.kill();
5757
});
@@ -82,13 +82,14 @@ 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.');
85+
expect(cli.stdout).toMatch('Fully run test files for first run.');
8686
cli.resetStd();
8787

8888
// rerun failed tests
8989
cli.exec.process!.stdin!.write('f');
9090
await cli.waitForStdout('Duration');
9191
expect(cli.stdout).toMatch('Tests 1 failed');
92+
expect(cli.stdout).toMatch('Run all tests.');
9293

9394
cli.exec.kill();
9495
});

packages/core/src/core/rsbuild.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import { pluginCacheControl } from './plugins/moduleCacheControl';
2020

2121
type EntryToChunkHashes = {
2222
name: string;
23-
chunks: Record<string, string>; // key is chunk name, value is chunk hash
23+
/** key is chunk name, value is chunk hash */
24+
chunks: Record<string, string>;
2425
}[];
2526

2627
function parseInlineSourceMap(code: string) {
@@ -123,13 +124,14 @@ export const calcEntriesToRerun = (
123124
chunks: Rspack.StatsChunk[] | undefined,
124125
buildData: { entryToChunkHashes?: EntryToChunkHashes },
125126
): {
126-
affectedEntries: EntryInfo[] | undefined;
127-
deletedEntries: string[] | undefined;
127+
affectedEntries: EntryInfo[];
128+
deletedEntries: string[];
128129
} => {
129130
const entryToChunkHashes: EntryToChunkHashes = [];
130131

131132
for (const entry of entries || []) {
132133
for (const chunkName of entry.chunks || []) {
134+
// Treat runtime chunk as invariant, sometimes it will change but we don't care.
133135
if (chunkName === 'runtime') {
134136
continue;
135137
}
@@ -155,14 +157,15 @@ export const calcEntriesToRerun = (
155157
}
156158
}
157159

158-
let affectedEntries: EntryInfo[] | undefined;
159-
let deletedEntries: string[] | undefined;
160+
let affectedEntries: EntryInfo[] = [];
161+
let deletedEntries: string[] = [];
160162
if (buildData.entryToChunkHashes) {
161163
const prev = buildData.entryToChunkHashes;
162164
const deleted = prev?.filter(
163165
(p) => !entryToChunkHashes.find((e) => e.name === p.name),
164166
);
165167

168+
// deleted
166169
if (deleted.length) {
167170
deletedEntries = deleted.map((entry) => entry.name);
168171
}
@@ -197,7 +200,7 @@ export const calcEntriesToRerun = (
197200
}
198201

199202
buildData.entryToChunkHashes = entryToChunkHashes;
200-
let dedupeAffectedEntries: EntryInfo[] | undefined;
203+
let dedupeAffectedEntries: EntryInfo[] = [];
201204

202205
if (affectedEntries) {
203206
dedupeAffectedEntries = [];
@@ -233,8 +236,9 @@ export const createRsbuildServer = async ({
233236
assetFiles: Record<string, string>;
234237
sourceMaps: Record<string, SourceMapInput>;
235238
getSourcemap: (sourcePath: string) => SourceMapInput | null;
236-
affectedEntries?: EntryInfo[]; // undefined means use full entries
237-
deletedEntries?: string[]; // undefined means use full entries
239+
isFirstRun: boolean;
240+
affectedEntries: EntryInfo[];
241+
deletedEntries: string[];
238242
}>;
239243
closeServer: () => Promise<void>;
240244
}> => {
@@ -282,11 +286,13 @@ export const createRsbuildServer = async ({
282286
);
283287
}
284288

289+
let runCount = 0;
285290
const buildData: { entryToChunkHashes?: EntryToChunkHashes } = {};
286291

287292
const getRsbuildStats = async ({
288293
fileFilters,
289294
}: { fileFilters?: string[] } | undefined = {}) => {
295+
runCount++;
290296
const stats = await devServer.environments[name]!.getStats();
291297

292298
const manifest = devServer.environments[name]!.context
@@ -412,6 +418,7 @@ export const createRsbuildServer = async ({
412418
return {
413419
affectedEntries,
414420
deletedEntries,
421+
isFirstRun: runCount === 1,
415422
hash,
416423
entries,
417424
setupEntries,

packages/core/src/core/runTests.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ export async function runTests(context: Rstest): Promise<void> {
106106

107107
let buildHash: string | undefined;
108108

109-
type RunMode = 'all-failed' | 'all' | 'on-demand';
109+
type Mode = 'all' | 'on-demand';
110110
const run = async ({
111111
fileFilters,
112-
mode: runMode = 'all',
112+
mode = 'all',
113113
}: {
114114
fileFilters?: string[];
115-
mode?: RunMode;
115+
mode?: Mode;
116116
} = {}) => {
117117
const {
118118
entries,
@@ -122,25 +122,30 @@ export async function runTests(context: Rstest): Promise<void> {
122122
getSourcemap,
123123
buildTime,
124124
hash,
125+
isFirstRun,
125126
affectedEntries,
126127
deletedEntries,
127128
} = await getRsbuildStats({ fileFilters });
128129
const testStart = Date.now();
129130

130131
let finalEntries: EntryInfo[] = entries;
131-
if (runMode === 'on-demand') {
132-
if (affectedEntries?.length) {
133-
logger.debug(
134-
color.yellow('Test files to re-run:\n') +
135-
affectedEntries.map((e) => e.testPath).join('\n') +
136-
'\n',
137-
);
138-
} else if (affectedEntries?.length === 0) {
139-
logger.debug(color.yellow('No test files are re-run.'));
132+
if (mode === 'on-demand') {
133+
if (isFirstRun) {
134+
logger.debug(color.yellow('Fully run test files for first run.\n'));
140135
} else {
141-
logger.debug(color.yellow('Fully run test files.\n'));
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;
142146
}
143-
finalEntries = affectedEntries ?? entries;
147+
} else {
148+
logger.debug(color.yellow('Run all tests.\n'));
144149
}
145150

146151
const { results, testResults } = await pool.runTests({
@@ -295,7 +300,7 @@ export async function runTests(context: Rstest): Promise<void> {
295300

296301
snapshotManager.clear();
297302

298-
await run({ fileFilters: failedTests, mode: 'all-failed' });
303+
await run({ fileFilters: failedTests, mode: 'all' });
299304
afterTestsWatchRun();
300305
},
301306
updateSnapshot: async () => {

0 commit comments

Comments
 (0)