|
| 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,16 @@ 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', |
| 85 | + shell: true, |
83 | 86 | }); |
84 | | - restore(); |
85 | 87 |
|
86 | | - expect(isSuccess).toBe(true); |
| 88 | + expect(result.status).toBe(0); |
87 | 89 | }); |
88 | 90 |
|
89 | 91 | test('autoExtension: true', async () => { |
@@ -243,14 +245,15 @@ describe('dts when bundle: true', () => { |
243 | 245 |
|
244 | 246 | test('abortOnError: false', async () => { |
245 | 247 | 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, |
250 | 254 | }); |
251 | | - restore(); |
252 | 255 |
|
253 | | - expect(isSuccess).toBe(true); |
| 256 | + expect(result.status).toBe(0); |
254 | 257 | }); |
255 | 258 |
|
256 | 259 | test('autoExtension: true', async () => { |
@@ -507,32 +510,34 @@ describe('dts when build: true', () => { |
507 | 510 |
|
508 | 511 | test('abortOnError: false', async () => { |
509 | 512 | 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, |
514 | 519 | }); |
515 | | - restore(); |
516 | 520 |
|
517 | | - expect(isSuccess).toBe(true); |
| 521 | + expect(result.status).toBe(0); |
518 | 522 |
|
519 | 523 | const buildInfoPath = join(fixturePath, 'tsconfig.tsbuildinfo'); |
520 | 524 | expect(existsSync(buildInfoPath)).toBeTruthy(); |
521 | 525 | }); |
522 | 526 |
|
523 | 527 | test('tsconfig missing some fields - declarationDir or outDir', async () => { |
524 | 528 | 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"'); |
536 | 541 | }); |
537 | 542 |
|
538 | 543 | test('should clean dts dist files', async () => { |
@@ -597,14 +602,15 @@ describe('dts when composite: true', () => { |
597 | 602 |
|
598 | 603 | test('abortOnError: false', async () => { |
599 | 604 | 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, |
604 | 611 | }); |
605 | | - restore(); |
606 | 612 |
|
607 | | - expect(isSuccess).toBe(true); |
| 613 | + expect(result.status).toBe(0); |
608 | 614 |
|
609 | 615 | const buildInfoPath = join(fixturePath, 'tsconfig.tsbuildinfo'); |
610 | 616 | expect(existsSync(buildInfoPath)).toBeTruthy(); |
|
0 commit comments