Skip to content

Commit 7745e13

Browse files
committed
Fix fixture path resolution and removed the @test alias
1 parent b326904 commit 7745e13

File tree

10 files changed

+29
-47
lines changed

10 files changed

+29
-47
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"settings": {
2929
"import/resolver": {
3030
"typescript": {
31-
// In tests, resolve using the test tsconfig (has @test/* mapping)
31+
// In tests, resolve using the test tsconfig
3232
"project": "test/tsconfig.json"
3333
}
3434
}

test/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
"compilerOptions": {
44
"baseUrl": "..",
55
"paths": {
6-
"@/*": ["src/*"],
7-
"@test/*": ["test/*"]
6+
"@/*": ["src/*"]
87
}
98
},
109
"include": ["**/*", "../src/**/*"]

test/unit/core/cliManager.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
MockConfigurationProvider,
2020
MockProgressReporter,
2121
MockUserInteraction,
22-
} from "@test/mocks/testHelpers";
22+
} from "../../mocks/testHelpers";
2323

2424
vi.mock("os");
2525
vi.mock("axios");

test/unit/core/cliUtils.test.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { beforeAll, describe, expect, it } from "vitest";
55

66
import * as cliUtils from "@/core/cliUtils";
77

8+
import { getFixturePath } from "../../utils/fixtures";
9+
810
describe("CliUtils", () => {
911
const tmp = path.join(os.tmpdir(), "vscode-coder-tests");
1012

@@ -31,10 +33,7 @@ describe("CliUtils", () => {
3133
const binPath = path.join(tmp, "version");
3234
await expect(cliUtils.version(binPath)).rejects.toThrow("ENOENT");
3335

34-
const binTmpl = await fs.readFile(
35-
path.join(__dirname, "../../fixtures/bin.bash"),
36-
"utf8",
37-
);
36+
const binTmpl = await fs.readFile(getFixturePath("bin.bash"), "utf8");
3837
await fs.writeFile(binPath, binTmpl.replace("$ECHO", "hello"));
3938
await expect(cliUtils.version(binPath)).rejects.toThrow("EACCES");
4039

@@ -57,10 +56,7 @@ describe("CliUtils", () => {
5756
);
5857
expect(await cliUtils.version(binPath)).toBe("v0.0.0");
5958

60-
const oldTmpl = await fs.readFile(
61-
path.join(__dirname, "../../fixtures/bin.old.bash"),
62-
"utf8",
63-
);
59+
const oldTmpl = await fs.readFile(getFixturePath("bin.old.bash"), "utf8");
6460
const old = (stderr: string, stdout: string): string => {
6561
return oldTmpl.replace("$STDERR", stderr).replace("$STDOUT", stdout);
6662
};

test/unit/core/mementoManager.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { beforeEach, describe, expect, it } from "vitest";
22

33
import { MementoManager } from "@/core/mementoManager";
44

5-
import { InMemoryMemento } from "@test/mocks/testHelpers";
5+
import { InMemoryMemento } from "../../mocks/testHelpers";
66

77
describe("MementoManager", () => {
88
let memento: InMemoryMemento;

test/unit/core/secretsManager.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { beforeEach, describe, expect, it } from "vitest";
22

33
import { SecretsManager } from "@/core/secretsManager";
44

5-
import { InMemorySecretStorage } from "@test/mocks/testHelpers";
5+
import { InMemorySecretStorage } from "../../mocks/testHelpers";
66

77
describe("SecretsManager", () => {
88
let secretStorage: InMemorySecretStorage;

test/unit/error.test.ts

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import axios from "axios";
22
import * as fs from "fs/promises";
33
import https from "https";
4-
import * as path from "path";
54
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
65

76
import { CertificateError, X509_ERR, X509_ERR_CODE } from "@/error";
87
import { type Logger } from "@/logging/logger";
98

9+
import { getFixturePath } from "../utils/fixtures";
10+
1011
describe("Certificate errors", () => {
1112
// Before each test we make a request to sanity check that we really get the
1213
// error we are expecting, then we run it through CertificateError.
@@ -46,12 +47,8 @@ describe("Certificate errors", () => {
4647
async function startServer(certName: string): Promise<string> {
4748
const server = https.createServer(
4849
{
49-
key: await fs.readFile(
50-
path.join(__dirname, `../fixtures/tls/${certName}.key`),
51-
),
52-
cert: await fs.readFile(
53-
path.join(__dirname, `../fixtures/tls/${certName}.crt`),
54-
),
50+
key: await fs.readFile(getFixturePath("tls", `${certName}.key`)),
51+
cert: await fs.readFile(getFixturePath("tls", `${certName}.crt`)),
5552
},
5653
(req, res) => {
5754
if (req.url?.endsWith("/error")) {
@@ -88,9 +85,7 @@ describe("Certificate errors", () => {
8885
const address = await startServer("chain-leaf");
8986
const request = axios.get(address, {
9087
httpsAgent: new https.Agent({
91-
ca: await fs.readFile(
92-
path.join(__dirname, "../fixtures/tls/chain-leaf.crt"),
93-
),
88+
ca: await fs.readFile(getFixturePath("tls", "chain-leaf.crt")),
9489
}),
9590
});
9691
await expect(request).rejects.toHaveProperty(
@@ -125,9 +120,7 @@ describe("Certificate errors", () => {
125120
const address = await startServer("no-signing");
126121
const request = axios.get(address, {
127122
httpsAgent: new https.Agent({
128-
ca: await fs.readFile(
129-
path.join(__dirname, "../fixtures/tls/no-signing.crt"),
130-
),
123+
ca: await fs.readFile(getFixturePath("tls", "no-signing.crt")),
131124
servername: "localhost",
132125
}),
133126
});
@@ -190,9 +183,7 @@ describe("Certificate errors", () => {
190183
const address = await startServer("self-signed");
191184
const request = axios.get(address, {
192185
httpsAgent: new https.Agent({
193-
ca: await fs.readFile(
194-
path.join(__dirname, "../fixtures/tls/self-signed.crt"),
195-
),
186+
ca: await fs.readFile(getFixturePath("tls", "self-signed.crt")),
196187
servername: "localhost",
197188
}),
198189
});
@@ -235,9 +226,7 @@ describe("Certificate errors", () => {
235226
const address = await startServer("chain");
236227
const request = axios.get(address, {
237228
httpsAgent: new https.Agent({
238-
ca: await fs.readFile(
239-
path.join(__dirname, "../fixtures/tls/chain-root.crt"),
240-
),
229+
ca: await fs.readFile(getFixturePath("tls", "chain-root.crt")),
241230
servername: "localhost",
242231
}),
243232
});
@@ -258,9 +247,7 @@ describe("Certificate errors", () => {
258247
const address = await startServer("chain");
259248
const request = axios.get(address + "/error", {
260249
httpsAgent: new https.Agent({
261-
ca: await fs.readFile(
262-
path.join(__dirname, "../fixtures/tls/chain-root.crt"),
263-
),
250+
ca: await fs.readFile(getFixturePath("tls", "chain-root.crt")),
264251
servername: "localhost",
265252
}),
266253
});

test/unit/pgp.test.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,16 @@ import { describe, expect, it } from "vitest";
55

66
import * as pgp from "@/pgp";
77

8+
import { getFixturePath } from "../utils/fixtures";
9+
810
describe("pgp", () => {
911
// This contains two keys, like Coder's.
10-
const publicKeysPath = path.join(__dirname, "../fixtures/pgp/public.pgp");
12+
const publicKeysPath = getFixturePath("pgp", "public.pgp");
1113
// Just a text file, not an actual binary.
12-
const cliPath = path.join(__dirname, "../fixtures/pgp/cli");
13-
const invalidSignaturePath = path.join(
14-
__dirname,
15-
"../fixtures/pgp/cli.invalid.asc",
16-
);
14+
const cliPath = getFixturePath("pgp", "cli");
15+
const invalidSignaturePath = getFixturePath("pgp", "cli.invalid.asc");
1716
// This is signed with the second key, like Coder's.
18-
const validSignaturePath = path.join(
19-
__dirname,
20-
"../fixtures/pgp/cli.valid.asc",
21-
);
17+
const validSignaturePath = getFixturePath("pgp", "cli.valid.asc");
2218

2319
it("reads bundled public keys", async () => {
2420
const keys = await pgp.readPublicKeys();

test/utils/fixtures.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import path from "path";
2+
3+
const testDir = path.join(__dirname, "..");
4+
export const getFixturePath = (...parts: string[]) =>
5+
path.join(testDir, "fixtures", ...parts);

vitest.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export default defineConfig({
2121
resolve: {
2222
alias: {
2323
"@": path.resolve(__dirname, "src"),
24-
"@test": path.resolve(__dirname, "test"),
2524
vscode: path.resolve(__dirname, "test/mocks/vscode.runtime.ts"),
2625
},
2726
},

0 commit comments

Comments
 (0)