Skip to content

Commit 4e6e2f1

Browse files
committed
test: do not display error logs in terminal during testing
1 parent bc1ff1a commit 4e6e2f1

File tree

1 file changed

+38
-35
lines changed

1 file changed

+38
-35
lines changed

tests/integration/dts/index.test.ts

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { spawnSync } from 'node:child_process';
12
import { existsSync } from 'node:fs';
23
import { join, normalize } from 'node:path';
34
import stripAnsi from 'strip-ansi';
@@ -75,15 +76,15 @@ describe('dts when bundle: false', () => {
7576
});
7677

7778
test('abortOnError: false', async () => {
78-
const { restore } = proxyConsole();
7979
const fixturePath = join(__dirname, 'bundle-false', 'abort-on-error');
80-
const { isSuccess } = await buildAndGetResults({
81-
fixturePath,
82-
type: 'dts',
80+
81+
const result = spawnSync('npx', ['rslib', 'build'], {
82+
cwd: fixturePath,
83+
// do not show output in test console
84+
stdio: 'ignore',
8385
});
84-
restore();
8586

86-
expect(isSuccess).toBe(true);
87+
expect(result.status).toBe(0);
8788
});
8889

8990
test('autoExtension: true', async () => {
@@ -249,14 +250,14 @@ describe('dts when bundle: true', () => {
249250

250251
test('abortOnError: false', async () => {
251252
const fixturePath = join(__dirname, 'bundle', 'abort-on-error');
252-
const { restore } = proxyConsole();
253-
const { isSuccess } = await buildAndGetResults({
254-
fixturePath,
255-
type: 'dts',
253+
254+
const result = spawnSync('npx', ['rslib', 'build'], {
255+
cwd: fixturePath,
256+
// do not show output in test console
257+
stdio: 'ignore',
256258
});
257-
restore();
258259

259-
expect(isSuccess).toBe(true);
260+
expect(result.status).toBe(0);
260261
});
261262

262263
test('autoExtension: true', async () => {
@@ -513,32 +514,34 @@ describe('dts when build: true', () => {
513514

514515
test('abortOnError: false', async () => {
515516
const fixturePath = join(__dirname, 'build', 'abort-on-error');
516-
const { restore } = proxyConsole();
517-
const { isSuccess } = await buildAndGetResults({
518-
fixturePath,
519-
type: 'dts',
517+
518+
const result = spawnSync('npx', ['rslib', 'build'], {
519+
cwd: fixturePath,
520+
// do not show output in test console
521+
stdio: 'ignore',
520522
});
521-
restore();
522523

523-
expect(isSuccess).toBe(true);
524+
expect(result.status).toBe(0);
524525

525526
const buildInfoPath = join(fixturePath, 'tsconfig.tsbuildinfo');
526527
expect(existsSync(buildInfoPath)).toBeTruthy();
527528
});
528529

529530
test('tsconfig missing some fields - declarationDir or outDir', async () => {
530531
const fixturePath = join(__dirname, 'build', 'tsconfig');
531-
try {
532-
await buildAndGetResults({
533-
fixturePath,
534-
type: 'dts',
535-
});
536-
} catch (err: any) {
537-
// not easy to proxy child process stdout
538-
expect(err.message).toBe(
539-
'Error occurred in esm declaration files generation.',
540-
);
541-
}
532+
533+
const result = spawnSync('npx', ['rslib', 'build'], {
534+
cwd: fixturePath,
535+
// do not show output in test console
536+
stdio: 'pipe',
537+
});
538+
539+
const stdoutOutput = result.stdout ? result.stdout.toString() : '';
540+
541+
expect(result.status).toBe(1);
542+
expect(stdoutOutput).toContain(
543+
'Please set declarationDir: "./dist/esm" in /Users/bytedance/codes/rslib/tests/integration/dts/build/tsconfig/tsconfig.json to keep it same as "dts.distPath" or "output.distPath.root" field in lib config.',
544+
);
542545
});
543546

544547
test('should clean dts dist files', async () => {
@@ -603,14 +606,14 @@ describe('dts when composite: true', () => {
603606

604607
test('abortOnError: false', async () => {
605608
const fixturePath = join(__dirname, 'composite', 'abort-on-error');
606-
const { restore } = proxyConsole();
607-
const { isSuccess } = await buildAndGetResults({
608-
fixturePath,
609-
type: 'dts',
609+
610+
const result = spawnSync('npx', ['rslib', 'build'], {
611+
cwd: fixturePath,
612+
// do not show output in test console
613+
stdio: 'ignore',
610614
});
611-
restore();
612615

613-
expect(isSuccess).toBe(true);
616+
expect(result.status).toBe(0);
614617

615618
const buildInfoPath = join(fixturePath, 'tsconfig.tsbuildinfo');
616619
expect(existsSync(buildInfoPath)).toBeTruthy();

0 commit comments

Comments
 (0)