-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcodeql-cli.test.ts
More file actions
85 lines (72 loc) · 1.96 KB
/
codeql-cli.test.ts
File metadata and controls
85 lines (72 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import fs from "fs";
import { tmpdir } from "os";
import path from "path";
import { rmRF } from "@actions/io";
import {
describe,
expect,
it,
beforeAll,
beforeEach,
afterEach,
afterAll,
} from "vitest";
import { getQueryPackInfo } from "./codeql";
import { CodeqlCli, CodeqlCliServer } from "./codeql-cli";
describe("codeql-cli", () => {
let cli: CodeqlCli;
let tmpDir: string;
beforeAll(() => {
cli = new CodeqlCliServer(process.env.CODEQL_BIN_PATH || "codeql");
});
afterAll(() => {
if (cli && cli instanceof CodeqlCliServer) {
cli.shutdown();
}
});
beforeEach(() => {
tmpDir = path.resolve(fs.mkdtempSync(path.join(tmpdir(), "tmp-")));
});
afterEach(async () => {
if (tmpDir !== undefined) {
await rmRF(tmpDir);
}
});
it(
"creates and bundles a database",
async () => {
const projectDir = path.join(tmpDir, "project");
const dbDir = path.join(tmpDir, "db");
fs.mkdirSync(projectDir);
const testFile = path.join(projectDir, "test.js");
fs.writeFileSync(testFile, "const x = 1;");
await cli.run([
"database",
"create",
"--language=javascript",
`--source-root=${projectDir}`,
dbDir,
]);
const dbZip = path.join(tmpDir, "database.zip");
await cli.run(["database", "bundle", `--output=${dbZip}`, dbDir]);
expect(fs.statSync(dbZip).isFile()).toBe(true);
},
// 5 minute timeout to create and bundle a database
5 * 60 * 1000,
);
it("gets query pack info", async () => {
const queryPackInfo = await getQueryPackInfo(cli, "testdata/test_pack");
const queries = {};
queries[path.resolve("testdata/test_pack/x/query.ql")] = {
name: "Test query",
description: "Test query description",
kind: "table",
id: "test/query/id",
};
expect(queryPackInfo).toEqual({
path: path.resolve("testdata/test_pack"),
name: "codeql/queries",
queries,
});
});
});