-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrecorded.test.js
55 lines (45 loc) · 1.49 KB
/
recorded.test.js
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
import { readFile, readdir } from "node:fs/promises";
import avaTest from "ava";
import { Octokit } from "@octokit/core";
import GitHubProject from "../index.js";
const OWNER = "github-project-fixtures";
const PROJECT_NUMBER = 2;
runTests(OWNER, PROJECT_NUMBER);
async function runTests(owner, projectNumber) {
const testFolders = await readdir("test/recorded");
for (const testFolder of testFolders) {
if (
[`_lib`, `snapshots`].includes(testFolder) ||
testFolder.endsWith(`.js`)
) {
continue;
}
avaTest.serial(`${testFolder}`, async (t) => {
const { test } = await import(`./recorded/${testFolder}/test.js`);
const fixturesPath = `test/recorded/${testFolder}/fixtures.json`;
const fixtures = JSON.parse(await readFile(fixturesPath, "utf8"));
const octokit = new Octokit();
const project = new GitHubProject({
owner,
number: projectNumber,
octokit,
fields: {
text: "Text",
number: "Number",
date: "Date",
singleSelect: "Single select",
},
});
octokit.hook.wrap("request", async (request, options) => {
console.log("[fixture] %s %s", options.method, options.url);
if (options.url === "/graphql") {
console.log(options.query.trim().split("\n")[0] + " … }");
}
const { response } = fixtures.shift();
return response;
});
const result = await test(project);
t.snapshot(result);
});
}
}