Skip to content

Commit 6638358

Browse files
authored
test: do not display expected error logs in terminal during testing (#1054)
1 parent 610c241 commit 6638358

File tree

1 file changed

+41
-35
lines changed

1 file changed

+41
-35
lines changed

tests/integration/dts/index.test.ts

Lines changed: 41 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,16 @@ 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',
85+
shell: true,
8386
});
84-
restore();
8587

86-
expect(isSuccess).toBe(true);
88+
expect(result.status).toBe(0);
8789
});
8890

8991
test('autoExtension: true', async () => {
@@ -243,14 +245,15 @@ describe('dts when bundle: true', () => {
243245

244246
test('abortOnError: false', async () => {
245247
const fixturePath = join(__dirname, 'bundle', 'abort-on-error');
246-
const { restore } = proxyConsole();
247-
const { isSuccess } = await buildAndGetResults({
248-
fixturePath,
249-
type: 'dts',
248+
249+
const result = spawnSync('npx', ['rslib', 'build'], {
250+
cwd: fixturePath,
251+
// do not show output in test console
252+
stdio: 'ignore',
253+
shell: true,
250254
});
251-
restore();
252255

253-
expect(isSuccess).toBe(true);
256+
expect(result.status).toBe(0);
254257
});
255258

256259
test('autoExtension: true', async () => {
@@ -507,32 +510,34 @@ describe('dts when build: true', () => {
507510

508511
test('abortOnError: false', async () => {
509512
const fixturePath = join(__dirname, 'build', 'abort-on-error');
510-
const { restore } = proxyConsole();
511-
const { isSuccess } = await buildAndGetResults({
512-
fixturePath,
513-
type: 'dts',
513+
514+
const result = spawnSync('npx', ['rslib', 'build'], {
515+
cwd: fixturePath,
516+
// do not show output in test console
517+
stdio: 'ignore',
518+
shell: true,
514519
});
515-
restore();
516520

517-
expect(isSuccess).toBe(true);
521+
expect(result.status).toBe(0);
518522

519523
const buildInfoPath = join(fixturePath, 'tsconfig.tsbuildinfo');
520524
expect(existsSync(buildInfoPath)).toBeTruthy();
521525
});
522526

523527
test('tsconfig missing some fields - declarationDir or outDir', async () => {
524528
const fixturePath = join(__dirname, 'build', 'tsconfig');
525-
try {
526-
await buildAndGetResults({
527-
fixturePath,
528-
type: 'dts',
529-
});
530-
} catch (err: any) {
531-
// not easy to proxy child process stdout
532-
expect(err.message).toBe(
533-
'Error occurred in esm declaration files generation.',
534-
);
535-
}
529+
530+
const result = spawnSync('npx', ['rslib', 'build'], {
531+
cwd: fixturePath,
532+
// do not show output in test console
533+
stdio: 'pipe',
534+
shell: true,
535+
});
536+
537+
const stdoutOutput = result.stdout ? result.stdout.toString() : '';
538+
539+
expect(result.status).toBe(1);
540+
expect(stdoutOutput).toContain('Please set declarationDir: "./dist/esm"');
536541
});
537542

538543
test('should clean dts dist files', async () => {
@@ -597,14 +602,15 @@ describe('dts when composite: true', () => {
597602

598603
test('abortOnError: false', async () => {
599604
const fixturePath = join(__dirname, 'composite', 'abort-on-error');
600-
const { restore } = proxyConsole();
601-
const { isSuccess } = await buildAndGetResults({
602-
fixturePath,
603-
type: 'dts',
605+
606+
const result = spawnSync('npx', ['rslib', 'build'], {
607+
cwd: fixturePath,
608+
// do not show output in test console
609+
stdio: 'ignore',
610+
shell: true,
604611
});
605-
restore();
606612

607-
expect(isSuccess).toBe(true);
613+
expect(result.status).toBe(0);
608614

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

0 commit comments

Comments
 (0)