Use temporary directory for generator tests
This will hopefully work with Windows tests as well.
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { existsSync, rmSync } from "fs";
|
import { existsSync } from "fs";
|
||||||
import { QlPackGenerator, QueryLanguage } from "../../../src/qlpack-generator";
|
import { QlPackGenerator, QueryLanguage } from "../../../src/qlpack-generator";
|
||||||
import { CodeQLCliServer } from "../../../src/cli";
|
import { CodeQLCliServer } from "../../../src/cli";
|
||||||
import { isFolderAlreadyInWorkspace } from "../../../src/helpers";
|
import { isFolderAlreadyInWorkspace } from "../../../src/helpers";
|
||||||
import { workspace } from "vscode";
|
import { workspace } from "vscode";
|
||||||
import { getErrorMessage } from "../../../src/pure/helpers-pure";
|
import { getErrorMessage } from "../../../src/pure/helpers-pure";
|
||||||
|
import * as tmp from "tmp";
|
||||||
|
|
||||||
describe("QlPackGenerator", () => {
|
describe("QlPackGenerator", () => {
|
||||||
let packFolderName: string;
|
let packFolderName: string;
|
||||||
@@ -14,11 +15,14 @@ describe("QlPackGenerator", () => {
|
|||||||
let language: string;
|
let language: string;
|
||||||
let generator: QlPackGenerator;
|
let generator: QlPackGenerator;
|
||||||
let packAddSpy: jest.SpyInstance;
|
let packAddSpy: jest.SpyInstance;
|
||||||
|
let dir: tmp.DirResult;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
dir = tmp.dirSync();
|
||||||
|
|
||||||
language = "ruby";
|
language = "ruby";
|
||||||
packFolderName = `test-ql-pack-${language}`;
|
packFolderName = `test-ql-pack-${language}`;
|
||||||
packFolderPath = join(__dirname, packFolderName);
|
packFolderPath = join(dir.name, packFolderName);
|
||||||
|
|
||||||
qlPackYamlFilePath = join(packFolderPath, "qlpack.yml");
|
qlPackYamlFilePath = join(packFolderPath, "qlpack.yml");
|
||||||
exampleQlFilePath = join(packFolderPath, "example.ql");
|
exampleQlFilePath = join(packFolderPath, "example.ql");
|
||||||
@@ -32,13 +36,13 @@ describe("QlPackGenerator", () => {
|
|||||||
packFolderName,
|
packFolderName,
|
||||||
language as QueryLanguage,
|
language as QueryLanguage,
|
||||||
mockCli,
|
mockCli,
|
||||||
__dirname,
|
dir.name,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
try {
|
try {
|
||||||
rmSync(packFolderPath, { recursive: true });
|
dir.removeCallback();
|
||||||
|
|
||||||
const end = (workspace.workspaceFolders || []).length;
|
const end = (workspace.workspaceFolders || []).length;
|
||||||
workspace.updateWorkspaceFolders(end - 1, 1);
|
workspace.updateWorkspaceFolders(end - 1, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user