Skip to content

Commit daac19f

Browse files
committed
test: convert new fixtures and tests to ESM
The fixtures and test blocks added in this PR used CommonJS (require / module.exports). After rebasing onto main, which converted the codebase to ESM in #105, they need to use import / export default and the loadJson helper.
1 parent d70e6a4 commit daac19f

4 files changed

Lines changed: 24 additions & 15 deletions

File tree

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
const { resolve } = require("path");
2-
const { readFileSync } = require("fs");
1+
import { readFileSync } from "node:fs";
2+
import { resolve } from "node:path";
3+
import { fileURLToPath } from "node:url";
34

5+
const __dirname = fileURLToPath(new URL(".", import.meta.url));
46
const issueBodyPath = resolve(__dirname, "issue-body.md");
57

6-
module.exports = readFileSync(issueBodyPath, "utf-8")
8+
export default readFileSync(issueBodyPath, "utf-8");
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
const { resolve } = require("path");
2-
const { readFileSync } = require("fs");
1+
import { readFileSync } from "node:fs";
2+
import { resolve } from "node:path";
3+
import { fileURLToPath } from "node:url";
34

5+
const __dirname = fileURLToPath(new URL(".", import.meta.url));
46
const issueBodyPath = resolve(__dirname, "issue-body.md");
57

6-
module.exports = readFileSync(issueBodyPath, "utf-8")
8+
export default readFileSync(issueBodyPath, "utf-8");
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
const { resolve } = require("path");
2-
const { readFileSync } = require("fs");
1+
import { readFileSync } from "node:fs";
2+
import { resolve } from "node:path";
3+
import { fileURLToPath } from "node:url";
34

5+
const __dirname = fileURLToPath(new URL(".", import.meta.url));
46
const issueBodyPath = resolve(__dirname, "issue-body.md");
57

6-
module.exports = readFileSync(issueBodyPath, "utf-8")
8+
export default readFileSync(issueBodyPath, "utf-8");

test.spec.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import readmeExampleIssue from "./fixtures/readme-example/issue.js";
77
import fullExampleIssue from "./fixtures/full-example/issue.js";
88
import mismatchedParsingIssue from "./fixtures/mismatched-parsing/issue.js";
99
import multipleParagraphsIssue from "./fixtures/multiple-paragraphs/issue.js";
10+
import paragraphConfusingHashesIssue from "./fixtures/paragraph-confusing-####/issue.js";
11+
import paragraphIgnoreCodeblockIssue from "./fixtures/paragraph-ignore-```/issue.js";
12+
import paragraphIgnoreCodeblockShIssue from "./fixtures/paragraph-ignore-```sh/issue.js";
1013

1114
function loadJson(path) {
1215
return JSON.parse(readFileSync(path, "utf-8"));
@@ -185,7 +188,7 @@ it("multiple paragraphs", () => {
185188
});
186189

187190
it("paragraph with confusing ####", () => {
188-
const expectedOutput = require("./fixtures/paragraph-confusing-####/expected.json");
191+
const expectedOutput = loadJson("./fixtures/paragraph-confusing-####/expected.json");
189192
const expectedOutputJson = JSON.stringify(expectedOutput, null, 2);
190193

191194
// mock ENV
@@ -194,7 +197,7 @@ it("paragraph with confusing ####", () => {
194197
};
195198

196199
// mock event payload
197-
const eventPayload = require("./fixtures/paragraph-confusing-####/issue");
200+
const eventPayload = paragraphConfusingHashesIssue;
198201

199202
// mock fs
200203
const fs = {
@@ -224,7 +227,7 @@ it("paragraph with confusing ####", () => {
224227
});
225228

226229
it("paragraph with ``` section", () => {
227-
const expectedOutput = require("./fixtures/paragraph-ignore-```/expected.json");
230+
const expectedOutput = loadJson("./fixtures/paragraph-ignore-```/expected.json");
228231
const expectedOutputJson = JSON.stringify(expectedOutput, null, 2);
229232

230233
// mock ENV
@@ -233,7 +236,7 @@ it("paragraph with ``` section", () => {
233236
};
234237

235238
// mock event payload
236-
const eventPayload = require("./fixtures/paragraph-ignore-```/issue");
239+
const eventPayload = paragraphIgnoreCodeblockIssue;
237240

238241
// mock fs
239242
const fs = {
@@ -263,7 +266,7 @@ it("paragraph with ``` section", () => {
263266
});
264267

265268
it("paragraph with ```sh section", () => {
266-
const expectedOutput = require("./fixtures/paragraph-ignore-```sh/expected.json");
269+
const expectedOutput = loadJson("./fixtures/paragraph-ignore-```sh/expected.json");
267270
const expectedOutputJson = JSON.stringify(expectedOutput, null, 2);
268271

269272
// mock ENV
@@ -272,7 +275,7 @@ it("paragraph with ```sh section", () => {
272275
};
273276

274277
// mock event payload
275-
const eventPayload = require("./fixtures/paragraph-ignore-```sh/issue");
278+
const eventPayload = paragraphIgnoreCodeblockShIssue;
276279

277280
// mock fs
278281
const fs = {

0 commit comments

Comments
 (0)