Skip to content

Commit edb4839

Browse files
committed
fix(shared): rewrite test to avoid spawnSync
1 parent c1026de commit edb4839

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

shared/src/docify/template-bundles/docusaurus/package.spec.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { describe, it, expect, afterAll } from 'vitest';
22
import { copyFileSync, mkdtempSync, rmSync } from 'fs';
33
import { join } from 'path';
44
import { tmpdir } from 'os';
5-
import { spawnSync } from 'child_process';
5+
import { spawn } from 'child_process';
66

77
const TEMPLATE_PACKAGE_JSON = join(__dirname, 'package.json');
88

@@ -18,15 +18,17 @@ describe('docusaurus template bundle dependencies', () => {
1818
rmSync(tmpDir, { recursive: true, force: true });
1919
});
2020

21-
it('should resolve without peer dependency conflicts (long running test)', () => {
21+
it('should resolve without peer dependency conflicts (long running test)', async () => {
2222
copyFileSync(TEMPLATE_PACKAGE_JSON, join(tmpDir, 'package.json'));
2323

24-
const result = spawnSync(
25-
'npm',
26-
['install', '--package-lock-only', '--prefix', tmpDir],
27-
{ encoding: 'utf-8' }
28-
);
24+
const exitCode = await new Promise<number>((resolve, reject) => {
25+
const stderr: string[] = [];
26+
const proc = spawn('npm', ['install', '--package-lock-only', '--prefix', tmpDir]);
27+
proc.stderr?.on('data', (chunk: Buffer) => stderr.push(chunk.toString()));
28+
proc.on('close', (code) => resolve(code ?? 1));
29+
proc.on('error', reject);
30+
});
2931

30-
expect(result.status, result.stderr).toBe(0);
31-
}, 180_000);
32+
expect(exitCode).toBe(0);
33+
}, 120_000);
3234
});

0 commit comments

Comments
 (0)