From ccd0737d2ba3b8b6548dd97e2143fac0dd5ba268 Mon Sep 17 00:00:00 2001 From: Don McCurdy Date: Wed, 1 Jan 2025 14:32:27 -0500 Subject: [PATCH] chore(tests): Fix broken validation script --- scripts/spawn-async.ts | 24 ------------------------ test/validate.ts | 30 ++++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 26 deletions(-) delete mode 100644 scripts/spawn-async.ts diff --git a/scripts/spawn-async.ts b/scripts/spawn-async.ts deleted file mode 100644 index b8eb652..0000000 --- a/scripts/spawn-async.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { spawn } from 'node:child_process'; - -export type SpawnResult = { code: number; stdout: string; stderr: string }; - -export function spawnAsync(command: string, args: string[]): Promise { - return new Promise((resolve) => { - const p = spawn(command, args); - - let stdout = ''; - let stderr = ''; - - p.stdout.on('data', (x) => { - stdout += x.toString(); - }); - - p.stderr.on('data', (x) => { - stderr += x.toString(); - }); - - p.on('exit', (code) => { - resolve({ code: code ?? 0, stdout, stderr }); - }); - }); -} diff --git a/test/validate.ts b/test/validate.ts index a123123..26b5f51 100644 --- a/test/validate.ts +++ b/test/validate.ts @@ -1,9 +1,9 @@ import { glob, mkdtemp, readFile, writeFile } from 'node:fs/promises'; -import { tmpdir } from 'node:os'; +import { spawn } from 'node:child_process'; import { basename, join, sep } from 'node:path'; +import { tmpdir } from 'node:os'; import test from 'ava'; import { read, write } from 'ktx-parse'; -import { type SpawnResult, spawnAsync } from '../scripts/spawn-async.js'; const tmpDir = await mkdtemp(`${tmpdir()}${sep}`); @@ -25,3 +25,29 @@ for await (const srcPath of glob(join('test', 'data', 'reference', '*.ktx2'))) { t.pass('ok'); }); } + +/////////////////////////////////////////////////////////////////////////////// +// UTILITIES + +type SpawnResult = { code: number; stdout: string; stderr: string }; + +function spawnAsync(command: string, args: string[]): Promise { + return new Promise((resolve) => { + const p = spawn(command, args); + + let stdout = ''; + let stderr = ''; + + p.stdout.on('data', (x) => { + stdout += x.toString(); + }); + + p.stderr.on('data', (x) => { + stderr += x.toString(); + }); + + p.on('exit', (code) => { + resolve({ code: code ?? 0, stdout, stderr }); + }); + }); +}