|
| 1 | +import { spawnSync } from 'node:child_process'; |
1 | 2 | import { existsSync } from 'node:fs'; |
2 | 3 | import { join, normalize } from 'node:path'; |
3 | 4 | import stripAnsi from 'strip-ansi'; |
@@ -75,15 +76,15 @@ describe('dts when bundle: false', () => { |
75 | 76 | }); |
76 | 77 |
|
77 | 78 | test('abortOnError: false', async () => { |
78 | | - const { restore } = proxyConsole(); |
79 | 79 | 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', |
83 | 85 | }); |
84 | | - restore(); |
85 | 86 |
|
86 | | - expect(isSuccess).toBe(true); |
| 87 | + expect(result.status).toBe(0); |
87 | 88 | }); |
88 | 89 |
|
89 | 90 | test('autoExtension: true', async () => { |
@@ -249,14 +250,14 @@ describe('dts when bundle: true', () => { |
249 | 250 |
|
250 | 251 | test('abortOnError: false', async () => { |
251 | 252 | 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', |
256 | 258 | }); |
257 | | - restore(); |
258 | 259 |
|
259 | | - expect(isSuccess).toBe(true); |
| 260 | + expect(result.status).toBe(0); |
260 | 261 | }); |
261 | 262 |
|
262 | 263 | test('autoExtension: true', async () => { |
@@ -513,32 +514,34 @@ describe('dts when build: true', () => { |
513 | 514 |
|
514 | 515 | test('abortOnError: false', async () => { |
515 | 516 | 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', |
520 | 522 | }); |
521 | | - restore(); |
522 | 523 |
|
523 | | - expect(isSuccess).toBe(true); |
| 524 | + expect(result.status).toBe(0); |
524 | 525 |
|
525 | 526 | const buildInfoPath = join(fixturePath, 'tsconfig.tsbuildinfo'); |
526 | 527 | expect(existsSync(buildInfoPath)).toBeTruthy(); |
527 | 528 | }); |
528 | 529 |
|
529 | 530 | test('tsconfig missing some fields - declarationDir or outDir', async () => { |
530 | 531 | 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 | + ); |
542 | 545 | }); |
543 | 546 |
|
544 | 547 | test('should clean dts dist files', async () => { |
@@ -603,14 +606,14 @@ describe('dts when composite: true', () => { |
603 | 606 |
|
604 | 607 | test('abortOnError: false', async () => { |
605 | 608 | 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', |
610 | 614 | }); |
611 | | - restore(); |
612 | 615 |
|
613 | | - expect(isSuccess).toBe(true); |
| 616 | + expect(result.status).toBe(0); |
614 | 617 |
|
615 | 618 | const buildInfoPath = join(fixturePath, 'tsconfig.tsbuildinfo'); |
616 | 619 | expect(existsSync(buildInfoPath)).toBeTruthy(); |
|
0 commit comments