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
|
|
|
// @ts-expect-error: Missing types
|
|
|
|
import {binary} from 'deno-prebuilt';
|
|
|
|
|
|
|
|
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(
|
|
|
|
binary,
|
|
|
|
['run', '--allow-read', '--allow-net=httpbin.org', 'index-deno.js', file],
|
|
|
|
{cwd: ctx.fixturesPath},
|
|
|
|
);
|
|
|
|
const stdout = await new Promise((resolve, reject) => {
|
2021-09-10 00:07:54 +08:00
|
|
|
child.once('error', reject);
|
2021-09-10 00:37:10 +08:00
|
|
|
child.once('exit', reject);
|
2021-09-30 11:18:33 +08:00
|
|
|
let stdout = '';
|
|
|
|
child.stdout.on('data', (data) => {
|
|
|
|
stdout += data;
|
|
|
|
});
|
|
|
|
child.once('exit', () => {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|