1
0
Fork 0
fetch-compare/src/platform-deno.ts

32 lines
826 B
TypeScript
Raw Permalink Normal View History

import {platform} from 'os';
2021-09-30 11:18:33 +08:00
import {spawn} from 'child_process';
2021-09-09 23:47:04 +08:00
2021-09-30 11:56:57 +08:00
import {Platform, Context, Result} from './types.js';
2021-09-30 11:18:33 +08:00
2021-09-09 23:47:04 +08:00
export default class PlatformDeno implements Platform {
2021-09-30 11:56:57 +08:00
async run(ctx: Context, file: string): Promise<Result> {
2021-09-30 11:18:33 +08:00
const child = spawn(
platform() === 'win32' ? 'deno.exe' : 'deno',
2021-09-30 11:18:33 +08:00
['run', '--allow-read', '--allow-net=httpbin.org', 'index-deno.js', file],
{cwd: ctx.fixturesPath, stdio: ['pipe', 'pipe', 'inherit']},
2021-09-30 11:18:33 +08:00
);
2021-09-30 11:36:10 +08:00
const stdout = await new Promise<string>((resolve, reject) => {
2021-09-30 11:18:33 +08:00
let stdout = '';
child.stdout.on('data', (data) => {
2022-02-16 18:50:37 +08:00
stdout += data as string;
2021-09-30 11:18:33 +08:00
});
child.once('error', reject);
child.once('exit', (code) => {
if (code !== 0) {
reject(code);
}
2021-09-30 11:56:57 +08:00
2021-09-30 11:18:33 +08:00
resolve(stdout);
});
2021-09-10 00:07:54 +08:00
});
child.kill();
2021-09-30 11:18:33 +08:00
2021-09-30 11:56:57 +08:00
return JSON.parse(stdout) as Result;
2021-09-09 23:47:04 +08:00
}
}