|
| 1 | +import { join } from "path"; |
| 2 | +import { dirSync } from "tmp-promise"; |
| 3 | +import { DirResult } from "tmp"; |
| 4 | +import { writeFile } from "fs-extra"; |
| 5 | +import { getQlPackPath } from "../../../src/pure/ql"; |
| 6 | + |
| 7 | +describe("getQlPackPath", () => { |
| 8 | + let tmpDir: DirResult; |
| 9 | + |
| 10 | + beforeEach(() => { |
| 11 | + tmpDir = dirSync({ |
| 12 | + prefix: "queries_", |
| 13 | + keep: false, |
| 14 | + unsafeCleanup: true, |
| 15 | + }); |
| 16 | + }); |
| 17 | + |
| 18 | + afterEach(() => { |
| 19 | + tmpDir.removeCallback(); |
| 20 | + }); |
| 21 | + |
| 22 | + it("should find a qlpack.yml when it exists", async () => { |
| 23 | + await writeFile(join(tmpDir.name, "qlpack.yml"), "name: test"); |
| 24 | + |
| 25 | + const result = await getQlPackPath(tmpDir.name); |
| 26 | + expect(result).toEqual(join(tmpDir.name, "qlpack.yml")); |
| 27 | + }); |
| 28 | + |
| 29 | + it("should find a codeql-pack.yml when it exists", async () => { |
| 30 | + await writeFile(join(tmpDir.name, "codeql-pack.yml"), "name: test"); |
| 31 | + |
| 32 | + const result = await getQlPackPath(tmpDir.name); |
| 33 | + expect(result).toEqual(join(tmpDir.name, "codeql-pack.yml")); |
| 34 | + }); |
| 35 | + |
| 36 | + it("should find a qlpack.yml when both exist", async () => { |
| 37 | + await writeFile(join(tmpDir.name, "qlpack.yml"), "name: test"); |
| 38 | + await writeFile(join(tmpDir.name, "codeql-pack.yml"), "name: test"); |
| 39 | + |
| 40 | + const result = await getQlPackPath(tmpDir.name); |
| 41 | + expect(result).toEqual(join(tmpDir.name, "qlpack.yml")); |
| 42 | + }); |
| 43 | + |
| 44 | + it("should find nothing when it doesn't exist", async () => { |
| 45 | + const result = await getQlPackPath(tmpDir.name); |
| 46 | + expect(result).toEqual(undefined); |
| 47 | + }); |
| 48 | +}); |
0 commit comments