Skip to content

Commit e616a61

Browse files
authored
test: make test logs clear (#1242)
1 parent de065fa commit e616a61

File tree

8 files changed

+25
-21
lines changed

8 files changed

+25
-21
lines changed

packages/core/tests/__snapshots__/config.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
288288
setup() {}
289289
}
290290
],
291-
logLevel: undefined
291+
logLevel: 'silent'
292292
}"
293293
`;
294294

packages/core/tests/config.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ describe('Should compose create Rsbuild config correctly', () => {
208208
},
209209
},
210210
},
211+
logLevel: 'silent',
211212
};
212213
const composedRsbuildConfig = await composeCreateRsbuildConfig(rslibConfig);
213214
expect(composedRsbuildConfig).toMatchSnapshot();

tests/integration/cli/build-watch/build.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { spawn } from 'node:child_process';
22
import path from 'node:path';
3-
import { after } from 'node:test';
4-
import { describe, expect, test } from '@rstest/core';
3+
import { describe, expect, onTestFinished, test } from '@rstest/core';
54
import fse from 'fs-extra';
65
import {
76
expectFile,
@@ -107,7 +106,7 @@ export default defineConfig({
107106
[rslibBinPath, 'build', '--watch', '-c', tempConfigFile],
108107
{
109108
cwd: __dirname,
110-
stdio: 'inherit',
109+
stdio: 'pipe',
111110
shell: true,
112111
},
113112
);
@@ -144,7 +143,7 @@ export default defineConfig({
144143
"
145144
`);
146145

147-
after(() => {
146+
onTestFinished(() => {
148147
child.kill();
149148
});
150149
});

tests/integration/cli/inspect/inspect.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import path from 'node:path';
2-
import { describe } from 'node:test';
3-
import { expect, test } from '@rstest/core';
2+
import { describe, expect, test } from '@rstest/core';
43
import fse from 'fs-extra';
54
import { globContentJSON, runCliSync } from 'test-helper';
65

tests/integration/cli/log-level/index.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { describe } from 'node:test';
21
import { stripVTControlCharacters as stripAnsi } from 'node:util';
3-
import { expect, test } from '@rstest/core';
2+
import { describe, expect, test } from '@rstest/core';
43
import { runCliSync } from 'test-helper';
54

65
describe('log level', async () => {

tests/integration/cli/mf/mf.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { join } from 'node:path';
2-
import { describe } from 'node:test';
32
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
43
import { startMFDevServer } from '@rslib/core';
5-
import { expect, test } from '@rstest/core';
4+
import { describe, expect, test } from '@rstest/core';
65
import fse from 'fs-extra';
76
import { expectFile, runCli, runCliSync } from 'test-helper';
87

tests/integration/entry/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ test('validate entry and throw errors', async () => {
165165
test('duplicate entry in bundleless mode', async () => {
166166
const { logs, restore } = proxyConsole();
167167
const fixturePath = join(__dirname, 'duplicate');
168-
await buildAndGetResults({ fixturePath });
168+
await buildAndGetResults({ fixturePath, logLevel: 'info' });
169169

170170
const logStrings = logs.map((log) => stripAnsi(log));
171171

tests/scripts/shared.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { fileURLToPath } from 'node:url';
1111
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
1212
import {
1313
type InspectConfigResult,
14+
type LogLevel,
1415
mergeRsbuildConfig as mergeConfig,
1516
} from '@rsbuild/core';
1617
import type { Format, LibConfig, RslibConfig } from '@rslib/core';
@@ -223,14 +224,16 @@ export async function getResults(
223224
};
224225
}
225226

226-
const updateConfigForTest = (rslibConfig: RslibConfig) => {
227-
Object.assign(rslibConfig, {
228-
performance: {
229-
// Do not print file size in tests
230-
printFileSize: false,
231-
},
232-
});
233-
};
227+
const updateConfigForTest =
228+
(logLevel?: LogLevel) => (rslibConfig: RslibConfig) => {
229+
Object.assign(rslibConfig, {
230+
performance: {
231+
// Do not print file size in tests
232+
printFileSize: false,
233+
},
234+
logLevel,
235+
});
236+
};
234237

235238
export async function rslibBuild({
236239
cwd,
@@ -258,6 +261,7 @@ export async function buildAndGetResults(options: {
258261
configPath?: string;
259262
type: 'all';
260263
lib?: string[];
264+
logLevel?: LogLevel;
261265
}): Promise<{
262266
js: BuildResult;
263267
dts: BuildResult;
@@ -268,22 +272,25 @@ export async function buildAndGetResults(options: {
268272
configPath?: string;
269273
type?: 'js' | 'dts' | 'css';
270274
lib?: string[];
275+
logLevel?: LogLevel;
271276
}): Promise<BuildResult>;
272277
export async function buildAndGetResults({
273278
fixturePath,
274279
configPath,
275280
type = 'js',
276281
lib,
282+
logLevel = 'warn',
277283
}: {
278284
fixturePath: string;
279285
configPath?: string;
280286
type?: 'js' | 'dts' | 'css' | 'all';
281287
lib?: string[];
288+
logLevel?: LogLevel;
282289
}) {
283290
const { rsbuildInstance, rslibConfig } = await rslibBuild({
284291
cwd: fixturePath,
285292
path: configPath,
286-
modifyConfig: updateConfigForTest,
293+
modifyConfig: updateConfigForTest(logLevel),
287294
lib,
288295
});
289296
const {

0 commit comments

Comments
 (0)