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

21 lines
549 B
TypeScript
Raw Normal View History

2021-09-30 11:18:33 +08:00
import {fork} from 'child_process';
2021-09-10 00:22:43 +08:00
import path from 'path';
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-09 23:47:04 +08:00
export default class PlatformNode 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 = fork(path.join(ctx.fixturesPath, 'index-node.js'), [file], {
cwd: ctx.fixturesPath,
});
2021-09-09 23:47:04 +08:00
const result: Result = await new Promise((resolve, reject) => {
child.once('error', reject);
2021-09-10 00:37:10 +08:00
child.once('exit', reject);
2021-09-09 23:47:04 +08:00
child.once('message', resolve);
});
child.kill();
return result;
}
}