Add tests for getQlPackPath
This commit is contained in:
48
extensions/ql-vscode/test/unit-tests/pure/ql.test.ts
Normal file
48
extensions/ql-vscode/test/unit-tests/pure/ql.test.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { join } from "path";
|
||||
import { dirSync } from "tmp-promise";
|
||||
import { DirResult } from "tmp";
|
||||
import { writeFile } from "fs-extra";
|
||||
import { getQlPackPath } from "../../../src/pure/ql";
|
||||
|
||||
describe("getQlPackPath", () => {
|
||||
let tmpDir: DirResult;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = dirSync({
|
||||
prefix: "queries_",
|
||||
keep: false,
|
||||
unsafeCleanup: true,
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
tmpDir.removeCallback();
|
||||
});
|
||||
|
||||
it("should find a qlpack.yml when it exists", async () => {
|
||||
await writeFile(join(tmpDir.name, "qlpack.yml"), "name: test");
|
||||
|
||||
const result = await getQlPackPath(tmpDir.name);
|
||||
expect(result).toEqual(join(tmpDir.name, "qlpack.yml"));
|
||||
});
|
||||
|
||||
it("should find a codeql-pack.yml when it exists", async () => {
|
||||
await writeFile(join(tmpDir.name, "codeql-pack.yml"), "name: test");
|
||||
|
||||
const result = await getQlPackPath(tmpDir.name);
|
||||
expect(result).toEqual(join(tmpDir.name, "codeql-pack.yml"));
|
||||
});
|
||||
|
||||
it("should find a qlpack.yml when both exist", async () => {
|
||||
await writeFile(join(tmpDir.name, "qlpack.yml"), "name: test");
|
||||
await writeFile(join(tmpDir.name, "codeql-pack.yml"), "name: test");
|
||||
|
||||
const result = await getQlPackPath(tmpDir.name);
|
||||
expect(result).toEqual(join(tmpDir.name, "qlpack.yml"));
|
||||
});
|
||||
|
||||
it("should find nothing when it doesn't exist", async () => {
|
||||
const result = await getQlPackPath(tmpDir.name);
|
||||
expect(result).toEqual(undefined);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user