Repository navigation
Expand file tree
/
Copy pathrun-dotnet-tests.test.mjs
More file actions
95 lines (84 loc) · 3.74 KB
/
Copy pathrun-dotnet-tests.test.mjs
File metadata and controls
95 lines (84 loc) · 3.74 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
/** Verifies .NET test shard selection and filter composition. */
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import test from "node:test";
import { fileURLToPath } from "node:url";
const script = fileURLToPath(new URL("./run-dotnet-tests.sh", import.meta.url));
await test("constructs a focused filter for named .NET shards", (t) => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "sdk-dotnet-shard-"));
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
const argumentsPath = path.join(root, "arguments");
const workingDirectoryPath = path.join(root, "working-directory");
const fakeDotnet = path.join(root, "dotnet");
fs.writeFileSync(
fakeDotnet,
`#!/usr/bin/env bash\nprintf '%s\\n' "$@" > "$ARGUMENTS_PATH"\nprintf '%s\\n' "$PWD" > "$WORKING_DIRECTORY_PATH"\n`,
);
fs.chmodSync(fakeDotnet, 0o755);
const result = spawnSync("bash", [script], {
encoding: "utf8",
env: {
...process.env,
ARGUMENTS_PATH: argumentsPath,
DOTNET_TEST_FILTER: "E2EBackend!=CapiOnly",
DOTNET_TEST_SHARD: "2b-rpc-agent",
PATH: `${root}${path.delimiter}${process.env.PATH ?? ""}`,
WORKING_DIRECTORY_PATH: workingDirectoryPath,
},
});
assert.equal(result.status, 0, result.stderr);
assert.equal(
fs.realpathSync(fs.readFileSync(workingDirectoryPath, "utf8").trim()),
fs.realpathSync(fileURLToPath(new URL("../../dotnet", import.meta.url))),
);
const arguments_ = fs.readFileSync(argumentsPath, "utf8").trim().split("\n");
assert.deepEqual(arguments_.slice(0, 3), [
"test",
"test/GitHub.Copilot.SDK.Test.csproj",
"--no-build",
]);
const filterIndex = arguments_.indexOf("--filter");
assert.notEqual(filterIndex, -1);
assert.equal(
arguments_[filterIndex + 1],
"(E2EBackend!=CapiOnly)&(FullyQualifiedName~GitHub.Copilot.Test.E2E.RpcAgentE2ETests)",
);
});
await test("rejects unknown .NET shards before invoking dotnet", () => {
const result = spawnSync("bash", [script], {
encoding: "utf8",
env: { ...process.env, DOTNET_TEST_SHARD: "unknown" },
});
assert.equal(result.status, 2);
assert.match(result.stderr, /Unknown \.NET test shard: unknown/);
});
await test("constructs the extensions shard without initial buckets", (t) => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "sdk-dotnet-extensions-"));
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
const argumentsPath = path.join(root, "arguments");
const fakeDotnet = path.join(root, "dotnet");
fs.writeFileSync(fakeDotnet, `#!/usr/bin/env bash\nprintf '%s\\n' "$@" > "$ARGUMENTS_PATH"\n`);
fs.chmodSync(fakeDotnet, 0o755);
const result = spawnSync("bash", [script], {
encoding: "utf8",
env: {
...process.env,
ARGUMENTS_PATH: argumentsPath,
DOTNET_TEST_SHARD: "extensions",
PATH: `${root}${path.delimiter}${process.env.PATH ?? ""}`,
},
});
assert.equal(result.status, 0, result.stderr);
const arguments_ = fs.readFileSync(argumentsPath, "utf8").trim().split("\n");
const filterIndex = arguments_.indexOf("--filter");
assert.equal(
arguments_[filterIndex + 1],
"(FullyQualifiedName~GitHub.Copilot.Test.E2E.RpcExtensionsLoadedE2ETests)",
);
});