Skip to content

Commit ce83d1d

Browse files
committed
Replace tmp package for modeled-method-fs.test.ts
1 parent d63b756 commit ce83d1d

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

extensions/ql-vscode/test/vscode-tests/cli-integration/model-editor/modeled-method-fs.test.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Uri, workspace } from "vscode";
2-
import * as tmp from "tmp";
32
import { CodeQLCliServer } from "../../../../src/codeql-cli/cli";
43
import { getActivatedExtension } from "../../global.helper";
54
import { mkdirSync, writeFileSync } from "fs";
@@ -10,7 +9,9 @@ import {
109
import { ExtensionPack } from "../../../../src/model-editor/shared/extension-pack";
1110
import { join } from "path";
1211
import { extLogger } from "../../../../src/common/logging/vscode";
13-
import { homedir } from "os";
12+
import { homedir, tmpdir } from "os";
13+
import { mkdir, rm } from "fs-extra";
14+
import { nanoid } from "nanoid";
1415
import { QueryLanguage } from "../../../../src/common/query-language";
1516

1617
const dummyExtensionPackContents = `
@@ -49,22 +50,23 @@ extensions:
4950

5051
describe("modeled-method-fs", () => {
5152
let tmpDir: string;
52-
let tmpDirRemoveCallback: (() => void) | undefined;
53+
let tmpDirRemoveCallback: (() => Promise<void>) | undefined;
5354
let workspacePath: string;
5455
let cli: CodeQLCliServer;
5556

5657
beforeEach(async () => {
5758
// On windows, make sure to use a temp directory that isn't an alias and therefore won't be canonicalised by CodeQL.
59+
// The tmp package doesn't support this, so we have to do it manually.
5860
// See https://github.com/github/vscode-codeql/pull/2605 for more context.
59-
const t = tmp.dirSync({
60-
dir:
61-
process.platform === "win32"
62-
? join(homedir(), "AppData", "Local", "Temp")
63-
: undefined,
64-
unsafeCleanup: true,
65-
});
66-
tmpDir = t.name;
67-
tmpDirRemoveCallback = t.removeCallback;
61+
const systemTmpDir =
62+
process.platform === "win32"
63+
? join(homedir(), "AppData", "Local", "Temp")
64+
: tmpdir();
65+
tmpDir = join(systemTmpDir, `codeql-vscode-test-${nanoid(8)}`);
66+
await mkdir(tmpDir, { recursive: true });
67+
tmpDirRemoveCallback = async () => {
68+
await rm(tmpDir, { recursive: true });
69+
};
6870

6971
const workspaceFolder = {
7072
uri: Uri.file(join(tmpDir, "workspace")),
@@ -90,8 +92,8 @@ describe("modeled-method-fs", () => {
9092
await cli.packInstall(packUsingExtensionsPath);
9193
});
9294

93-
afterEach(() => {
94-
tmpDirRemoveCallback?.();
95+
afterEach(async () => {
96+
await tmpDirRemoveCallback?.();
9597
});
9698

9799
function writeExtensionPackFiles(

0 commit comments

Comments
 (0)