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

34 lines
873 B
TypeScript
Raw Normal View History

import {platform} from 'os';
2021-09-30 11:18:33 +08:00
import {spawn} from 'child_process';
import logger from '@wdio/logger';
2021-09-09 23:47:04 +08:00
import {Platform, Result} from './types.js';
2021-09-30 11:18:33 +08:00
const log = logger('fetch-compare');
2021-09-09 23:47:04 +08:00
export default class PlatformDeno implements Platform {
2021-09-30 11:18:33 +08:00
async run(ctx: Record<string, any>, file: string): Promise<Result> {
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
);
const stdout = await new Promise((resolve, reject) => {
let stdout = '';
child.stdout.on('data', (data) => {
stdout += data;
});
child.once('error', reject);
child.once('exit', (code) => {
if (code !== 0) {
reject(code);
}
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
return JSON.parse(stdout);
2021-09-09 23:47:04 +08:00
}
}