-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathcodegen-entrypoints.test.mjs
More file actions
41 lines (38 loc) · 2.09 KB
/
Copy pathcodegen-entrypoints.test.mjs
File metadata and controls
41 lines (38 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { mkdtempSync, rmSync, symlinkSync } from "node:fs";
import { createRequire } from "node:module";
import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
import { fileURLToPath, pathToFileURL } from "node:url";
const codegenRoot = fileURLToPath(new URL("../codegen/", import.meta.url));
const loader = createRequire(new URL("../codegen/package.json", import.meta.url)).resolve("tsx");
for (const language of ["python", "go", "csharp"]) {
test(`runs the ${language} generator through a Bazel-style symlink`, (t) => {
const directory = mkdtempSync(join(tmpdir(), "codegen-entrypoint-"));
t.after(() => rmSync(directory, { recursive: true, force: true }));
const entry = join(directory, `${language}.ts`);
symlinkSync(join(codegenRoot, `${language}.ts`), entry);
const missingSchema = join(directory, "missing-schema.json");
// Supplying both schema paths prevents standalone generators from acquiring a published runtime.
const result = spawnSync(
process.execPath,
["--import", pathToFileURL(loader).href, entry, missingSchema, missingSchema],
{
cwd: directory,
encoding: "utf8",
windowsHide: true,
timeout: process.platform === "win32" ? 60_000 : 30_000,
env: { ...process.env, COPILOT_CODEGEN_OUTPUT_ROOT: join(directory, "output") },
},
);
const diagnostics = `${result.stdout}\n${result.stderr}`;
assert.ifError(result.error);
assert.notEqual(result.status, 0, `Expected ${language} to reject the missing local schemas.\n${diagnostics}`);
assert.match(result.stderr, /missing-schema\.json/, diagnostics);
});
}