mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-14 08:35:47 +08:00
Run the frontend services test's compiler and processes off the test worker
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import { execFileSync, spawnSync } from "node:child_process";
|
||||
import { mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { analyze, compile } from "@scriptc/compiler";
|
||||
import { expect, test } from "vitest";
|
||||
import { ts7Executable } from "../../packages/compiler/src/frontend/ts7/rpc-api.js";
|
||||
|
||||
import { npmFetchCases } from "../../packages/compiler/test/npm-fetch-cases.js";
|
||||
import { analyzeInChild, compileInChild } from "./self-hosting-compiler-process.js";
|
||||
import { spawnResult } from "./spawn-result.js";
|
||||
|
||||
const root = join(import.meta.dirname, "../..");
|
||||
const entry = join(root, "tests/fixtures/self-hosting/frontend-services.ts");
|
||||
@@ -69,17 +69,23 @@ for (const backend of ["llvm"] as const) {
|
||||
);
|
||||
try {
|
||||
const object = join(directory, "process.o");
|
||||
execFileSync("clang", [
|
||||
"-std=c11",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
...(sanitize ? ["-fsanitize=address"] : []),
|
||||
"-c",
|
||||
join(nativeSources, "ts7-process.c"),
|
||||
"-o",
|
||||
object,
|
||||
]);
|
||||
const clang = await spawnResult(
|
||||
"clang",
|
||||
[
|
||||
"-std=c11",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
...(sanitize ? ["-fsanitize=address"] : []),
|
||||
"-c",
|
||||
join(nativeSources, "ts7-process.c"),
|
||||
"-o",
|
||||
object,
|
||||
],
|
||||
{ cwd: root, timeout: 120_000 },
|
||||
);
|
||||
expect(clang.error).toBeUndefined();
|
||||
expect(clang.status, clang.stderr.toString()).toBe(0);
|
||||
const profile = join(directory, "ffi.json");
|
||||
writeFileSync(
|
||||
profile,
|
||||
@@ -88,13 +94,13 @@ for (const backend of ["llvm"] as const) {
|
||||
libraries: [object],
|
||||
}),
|
||||
);
|
||||
const { coverage } = analyze(entry, { dynamic: false, ffiProfilePath: profile });
|
||||
const coverage = await analyzeInChild(entry, { dynamic: false, ffiProfilePath: profile });
|
||||
expect(coverage.preflightFailed, JSON.stringify(coverage.diagnostics)).toBe(false);
|
||||
expect(coverage.diagnostics).toEqual([]);
|
||||
expect(coverage.stats.statementsFailed).toBe(0);
|
||||
expect(coverage.stats.statementsIsland).toBe(0);
|
||||
expect(coverage.stats.functionsSkipped).toBe(0);
|
||||
const built = await compile(entry, {
|
||||
const built = await compileInChild(entry, {
|
||||
backend,
|
||||
dynamic: false,
|
||||
optimization: "dev",
|
||||
@@ -108,25 +114,25 @@ for (const backend of ["llvm"] as const) {
|
||||
const request = join(directory, "request.json");
|
||||
writeFileSync(request, JSON.stringify(input(directory)));
|
||||
const expected = join(directory, "node.json");
|
||||
const node = spawnSync(
|
||||
const node = await spawnResult(
|
||||
process.execPath,
|
||||
["--import", "tsx", oracle, ts7Executable(), request, expected],
|
||||
{ encoding: "utf8", timeout: 45_000 },
|
||||
{ cwd: root, timeout: 45_000 },
|
||||
);
|
||||
expect(node.error, node.stderr).toBeUndefined();
|
||||
expect(node.status, node.stderr).toBe(0);
|
||||
expect(node.stdout).toBe("");
|
||||
expect(node.stderr).toBe("");
|
||||
expect(node.error, node.stderr.toString()).toBeUndefined();
|
||||
expect(node.status, node.stderr.toString()).toBe(0);
|
||||
expect(node.stdout.toString()).toBe("");
|
||||
expect(node.stderr.toString()).toBe("");
|
||||
const report = join(directory, "native.json");
|
||||
const run = spawnSync(built.binaryPath, [ts7Executable(), request, report], {
|
||||
encoding: "utf8",
|
||||
const run = await spawnResult(built.binaryPath, [ts7Executable(), request, report], {
|
||||
cwd: root,
|
||||
timeout: 45_000,
|
||||
});
|
||||
expect(run.error, run.stderr).toBeUndefined();
|
||||
expect(run.signal, run.stderr).toBeNull();
|
||||
expect(run.status, run.stderr).toBe(0);
|
||||
expect(run.stdout).toBe(node.stdout);
|
||||
expect(run.stderr).toBe(node.stderr);
|
||||
expect(run.error, run.stderr.toString()).toBeUndefined();
|
||||
expect(run.signal, run.stderr.toString()).toBeNull();
|
||||
expect(run.status, run.stderr.toString()).toBe(0);
|
||||
expect(run.stdout.toString()).toBe(node.stdout.toString());
|
||||
expect(run.stderr.toString()).toBe(node.stderr.toString());
|
||||
const result = JSON.parse(readFileSync(report, "utf8"));
|
||||
expect(result).toEqual(JSON.parse(readFileSync(expected, "utf8")));
|
||||
expect(result.fetch).toEqual(
|
||||
|
||||
Reference in New Issue
Block a user