Skip to content

Commit 49fce98

Browse files
stormslowlyCopilot
andauthored
chore(test): show cli test stdout/err when child proceess killed (#12913)
* chore: show stdou/err when killed Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 61c9a4a commit 49fce98

File tree

2 files changed

+93
-41
lines changed

2 files changed

+93
-41
lines changed

packages/rspack-cli/tests/build/basic/basic.test.ts

Lines changed: 65 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,49 @@ import { readFile, run, runWatch } from '../../utils/test-utils';
33

44
describe('build command', () => {
55
it.concurrent('it should work ', async () => {
6-
const { exitCode, stderr, stdout } = await run(__dirname, []);
6+
const { exitCode, stderr, stdout } = await run(__dirname, [], {}, {}, true);
77
expect(exitCode).toBe(0);
88
expect(stderr).toBeFalsy();
99
expect(stdout).toBeTruthy();
1010
});
1111
it.concurrent(
1212
'should work without command and options (default command)',
1313
async () => {
14-
const { exitCode, stderr, stdout } = await run(__dirname, [
15-
'--mode',
16-
'development',
17-
]);
14+
const { exitCode, stderr, stdout } = await run(
15+
__dirname,
16+
['--mode', 'development'],
17+
{},
18+
{},
19+
true,
20+
);
1821

1922
expect(exitCode).toBe(0);
2023
expect(stderr).toBeFalsy();
2124
expect(stdout).toBeTruthy();
2225
},
2326
);
2427
it.concurrent('should work with configuration return function', async () => {
25-
const { exitCode, stderr, stdout } = await run(__dirname, [
26-
'--config',
27-
'./entry.function.js',
28-
]);
28+
const { exitCode, stderr, stdout } = await run(
29+
__dirname,
30+
['--config', './entry.function.js'],
31+
{},
32+
{},
33+
true,
34+
);
2935
expect(exitCode).toBe(0);
3036
expect(stderr).toBeFalsy();
3137
expect(stdout).toBeTruthy();
3238
});
3339
it.concurrent(
3440
'should pass env.RSPACK_BUILD and env.RSPACK_BUNDLE for function configuration on build mode',
3541
async () => {
36-
const { stdout } = await run(__dirname, ['--config', './entry.env.js']);
42+
const { stdout } = await run(
43+
__dirname,
44+
['--config', './entry.env.js'],
45+
{},
46+
{},
47+
true,
48+
);
3749
expect(stdout).toContain('RSPACK_BUILD=true');
3850
expect(stdout).toContain('RSPACK_BUNDLE=true');
3951
expect(stdout).not.toContain('RSPACK_WATCH=true');
@@ -57,32 +69,44 @@ describe('build command', () => {
5769
},
5870
);
5971
it.concurrent('should work with configuration return promise', async () => {
60-
const { exitCode, stderr, stdout } = await run(__dirname, [
61-
'--config',
62-
'./entry.promise.js',
63-
]);
72+
const { exitCode, stderr, stdout } = await run(
73+
__dirname,
74+
['--config', './entry.promise.js'],
75+
{},
76+
{},
77+
true,
78+
);
6479
expect(exitCode).toBe(0);
6580
expect(stderr).toBeFalsy();
6681
expect(stdout).toBeTruthy();
6782
});
6883
it.concurrent('should work with mjs configuration ', async () => {
69-
const { exitCode, stderr, stdout } = await run(__dirname, [
70-
'--config',
71-
'./entry.config.mjs',
72-
]);
84+
const { exitCode, stderr, stdout } = await run(
85+
__dirname,
86+
['--config', './entry.config.mjs'],
87+
{},
88+
{},
89+
true,
90+
);
7391
expect(exitCode).toBe(0);
7492
expect(stderr).toBeFalsy();
7593
expect(stdout).toBeTruthy();
7694
});
7795
it('entry option should have higher priority than config', async () => {
78-
const { exitCode, stderr, stdout } = await run(__dirname, [
79-
'--entry',
80-
'./src/other.js',
81-
'--config',
82-
'./entry.config.js',
83-
'--output-path',
84-
'dist/priority',
85-
]);
96+
const { exitCode, stderr, stdout } = await run(
97+
__dirname,
98+
[
99+
'--entry',
100+
'./src/other.js',
101+
'--config',
102+
'./entry.config.js',
103+
'--output-path',
104+
'dist/priority',
105+
],
106+
{},
107+
{},
108+
true,
109+
);
86110
const mainJs = await readFile(
87111
resolve(__dirname, 'dist/priority/main.js'),
88112
'utf-8',
@@ -98,12 +122,13 @@ describe('build command', () => {
98122
it.each(['-o', '--output-path', '--outputPath'])(
99123
'output-path option %s should have higher priority than config',
100124
async (command) => {
101-
const { exitCode, stderr, stdout } = await run(__dirname, [
102-
command,
103-
'dist/public',
104-
'--config',
105-
'./entry.config.js',
106-
]);
125+
const { exitCode, stderr, stdout } = await run(
126+
__dirname,
127+
[command, 'dist/public', '--config', './entry.config.js'],
128+
{},
129+
{},
130+
true,
131+
);
107132
const mainJs = await readFile(
108133
resolve(__dirname, 'dist/public/main.js'),
109134
'utf-8',
@@ -126,15 +151,16 @@ describe('build command', () => {
126151
])(
127152
'devtool option %s should have higher priority than config',
128153
async (command, option) => {
129-
const { exitCode, stderr, stdout } = await run(__dirname, [
130-
command,
131-
option,
132-
'--config',
133-
'./entry.config.js',
134-
]);
154+
const { exitCode, stderr, stdout } = await run(
155+
__dirname,
156+
[command, option, '--config', './entry.config.js'],
157+
{},
158+
{},
159+
true,
160+
);
135161

136162
const mainJs = await readFile(
137-
resolve(__dirname, 'dist/public/main.js'),
163+
resolve(__dirname, 'dist/main.js'),
138164
'utf-8',
139165
);
140166

packages/rspack-cli/tests/utils/test-utils.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,36 @@ const createProcess = (cwd, args, options, env) => {
8282
* @param {string} cwd The path to folder that contains test
8383
* @param {Array<string>} args Array of arguments
8484
* @param {Object<string, any>} options Options for tests
85+
* @param env
86+
* @param diagnoseKilledProcess
8587
* @returns {Promise}
8688
*/
87-
const run = async (cwd, args: string[] = [], options = {}, env = {}) => {
88-
return createProcess(cwd, args, options, env);
89+
const run = async (
90+
cwd: string,
91+
args: string[] = [],
92+
options: { [s: string]: any } = {},
93+
env: { [s: string]: string } = {},
94+
diagnoseKilledProcess: boolean = false,
95+
): Promise<any> => {
96+
const result = await createProcess(cwd, args, options, env);
97+
98+
if (diagnoseKilledProcess && result.exitCode === undefined && result.signal) {
99+
console.error(
100+
`🔍 DIAGNOSIS: Process(${args.join(' ')}) was killed by signal(${result.signal})`,
101+
);
102+
103+
if (result.stdout) {
104+
console.error('STDOUT:');
105+
console.error(result.stdout);
106+
}
107+
108+
if (result.stderr) {
109+
console.error('STDERR');
110+
console.error(result.stderr);
111+
}
112+
}
113+
114+
return result;
89115
};
90116

91117
/**

0 commit comments

Comments
 (0)