Skip to content

Commit a9c2e64

Browse files
committed
refactor: migrate helper files to ES module syntax
1 parent 99b28fb commit a9c2e64

13 files changed

Lines changed: 86 additions & 147 deletions

test/helpers/ExitOnDonePlugin.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"use strict";
2-
3-
module.exports = class ExitOnDonePlugin {
1+
export default class ExitOnDonePlugin {
42
apply(compiler) {
53
compiler.hooks.afterDone.tap("webpack-dev-server", (stats) => {
64
let exitCode = 0;
@@ -15,4 +13,4 @@ module.exports = class ExitOnDonePlugin {
1513
});
1614
});
1715
}
18-
};
16+
}

test/helpers/conditional-test.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
"use strict";
2-
3-
const { test } = require("node:test");
1+
import { test } from "node:test";
42

53
const isWindows = process.platform === "win32";
64

75
/**
86
* @param {string} reason reason
97
* @returns {boolean} true when it is windows, otherwise false
108
*/
11-
function skipTestOnWindows(reason) {
9+
export function skipTestOnWindows(reason) {
1210
if (isWindows) {
1311
test.skip(reason, () => {});
1412
}
1513

1614
return isWindows;
1715
}
18-
19-
module.exports.skipTestOnWindows = skipTestOnWindows;

test/helpers/custom-http.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
"use strict";
2-
3-
const customHTTP = require("node:http");
4-
5-
module.exports = customHTTP;
1+
export { default } from "node:http";

test/helpers/html-generator-plugin.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use strict";
2-
31
const HTMLContentForIndex = `
42
<!DOCTYPE html>
53
<html>
@@ -41,7 +39,7 @@ const HTMLContentForTest = `
4139
</html>
4240
`;
4341

44-
module.exports = class HTMLGeneratorPlugin {
42+
export default class HTMLGeneratorPlugin {
4543
apply(compiler) {
4644
const pluginName = "html-generator-plugin";
4745

@@ -79,4 +77,4 @@ module.exports = class HTMLGeneratorPlugin {
7977
);
8078
});
8179
}
82-
};
80+
}

test/helpers/jsdom-setup.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"use strict";
2-
3-
const { JSDOM } = require("jsdom");
1+
import { JSDOM } from "jsdom";
42

53
const dom = new JSDOM("<!DOCTYPE html><html><body></body></html>", {
64
url: "http://localhost/",

test/helpers/normalize-options.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use strict";
2-
31
/**
42
* @param {import("https").ServerOptions} options server options
53
* @returns {Record<string, string | string[] | boolean>} normalized server options
@@ -38,4 +36,4 @@ function normalizeOptions(options) {
3836
return normalizedOptions;
3937
}
4038

41-
module.exports = normalizeOptions;
39+
export default normalizeOptions;
Lines changed: 49 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,49 @@
1-
"use strict";
2-
3-
module.exports = {
4-
reloadReadyDelay: 5000,
5-
completeReloadDelay: 10000,
6-
initConsoleDelay: 3000,
7-
awaitServerCloseDelay: 1000,
8-
beforeBrowserCloseDelay: 3000,
9-
puppeteerArgs: [
10-
"--disable-background-timer-throttling",
11-
"--disable-breakpad",
12-
"--disable-client-side-phishing-detection",
13-
"--disable-cloud-import",
14-
"--disable-default-apps",
15-
"--disable-dev-shm-usage",
16-
"--disable-extensions",
17-
"--disable-gesture-typing",
18-
"--disable-hang-monitor",
19-
"--disable-infobars",
20-
"--disable-notifications",
21-
"--disable-offer-store-unmasked-wallet-cards",
22-
"--disable-offer-upload-credit-cards",
23-
"--disable-popup-blocking",
24-
"--disable-print-preview",
25-
"--disable-prompt-on-repost",
26-
"--disable-setuid-sandbox",
27-
"--disable-speech-api",
28-
"--disable-sync",
29-
"--disable-tab-for-desktop-share",
30-
"--disable-translate",
31-
"--disable-voice-input",
32-
"--disable-wake-on-wifi",
33-
"--enable-async-dns",
34-
"--enable-simple-cache-backend",
35-
"--enable-tcp-fast-open",
36-
"--enable-webgl",
37-
"--hide-scrollbars",
38-
"--ignore-gpu-blacklist",
39-
"--media-cache-size=33554432",
40-
"--metrics-recording-only",
41-
"--mute-audio",
42-
"--no-default-browser-check",
43-
"--no-first-run",
44-
"--no-pings",
45-
"--no-sandbox",
46-
"--no-zygote",
47-
"--password-store=basic",
48-
"--prerender-from-omnibox=disabled",
49-
"--use-gl=swiftshader",
50-
"--use-mock-keychain",
51-
"--disable-field-trial-config",
52-
],
53-
};
1+
export const reloadReadyDelay = 5000;
2+
export const completeReloadDelay = 10000;
3+
export const initConsoleDelay = 3000;
4+
export const awaitServerCloseDelay = 1000;
5+
export const beforeBrowserCloseDelay = 3000;
6+
export const puppeteerArgs = [
7+
"--disable-background-timer-throttling",
8+
"--disable-breakpad",
9+
"--disable-client-side-phishing-detection",
10+
"--disable-cloud-import",
11+
"--disable-default-apps",
12+
"--disable-dev-shm-usage",
13+
"--disable-extensions",
14+
"--disable-gesture-typing",
15+
"--disable-hang-monitor",
16+
"--disable-infobars",
17+
"--disable-notifications",
18+
"--disable-offer-store-unmasked-wallet-cards",
19+
"--disable-offer-upload-credit-cards",
20+
"--disable-popup-blocking",
21+
"--disable-print-preview",
22+
"--disable-prompt-on-repost",
23+
"--disable-setuid-sandbox",
24+
"--disable-speech-api",
25+
"--disable-sync",
26+
"--disable-tab-for-desktop-share",
27+
"--disable-translate",
28+
"--disable-voice-input",
29+
"--disable-wake-on-wifi",
30+
"--enable-async-dns",
31+
"--enable-simple-cache-backend",
32+
"--enable-tcp-fast-open",
33+
"--enable-webgl",
34+
"--hide-scrollbars",
35+
"--ignore-gpu-blacklist",
36+
"--media-cache-size=33554432",
37+
"--metrics-recording-only",
38+
"--mute-audio",
39+
"--no-default-browser-check",
40+
"--no-first-run",
41+
"--no-pings",
42+
"--no-sandbox",
43+
"--no-zygote",
44+
"--password-store=basic",
45+
"--prerender-from-omnibox=disabled",
46+
"--use-gl=swiftshader",
47+
"--use-mock-keychain",
48+
"--disable-field-trial-config",
49+
];

test/helpers/run-browser.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
"use strict";
2-
3-
const puppeteer = require("puppeteer");
4-
const { puppeteerArgs } = require("./puppeteer-constants");
1+
import { launch } from "puppeteer";
2+
import { puppeteerArgs } from "./puppeteer-constants.js";
53

64
/** @typedef {import('puppeteer').Browser} Browser */
75
/** @typedef {import('puppeteer').Page} Page */
@@ -18,7 +16,7 @@ const { puppeteerArgs } = require("./puppeteer-constants");
1816
* @param {Device} device config
1917
* @returns {Promise<Page>} page
2018
*/
21-
function runPage(browser, device) {
19+
export function runPage(browser, device) {
2220
/**
2321
* @type {Page}
2422
*/
@@ -77,14 +75,13 @@ function runBrowser(device) {
7775
*/
7876
let browser;
7977

80-
puppeteer
81-
.launch({
82-
headless: "new",
83-
// because of invalid localhost certificate
84-
acceptInsecureCerts: true,
85-
// args come from: https://github.com/alixaxel/chrome-aws-lambda/blob/master/source/index.js
86-
args: puppeteerArgs,
87-
})
78+
launch({
79+
headless: "new",
80+
// because of invalid localhost certificate
81+
acceptInsecureCerts: true,
82+
// args come from: https://github.com/alixaxel/chrome-aws-lambda/blob/master/source/index.js
83+
args: puppeteerArgs,
84+
})
8885
.then((launchedBrowser) => {
8986
browser = launchedBrowser;
9087

@@ -99,5 +96,4 @@ function runBrowser(device) {
9996
});
10097
}
10198

102-
module.exports = runBrowser;
103-
module.exports.runPage = runPage;
99+
export default runBrowser;

test/helpers/session-subscribe.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
"use strict";
2-
3-
module.exports = async function sessionSubscribe(session) {
1+
export default async function sessionSubscribe(session) {
42
session.on("sessionattached", (attachedSession) => {
53
sessionSubscribe(attachedSession);
64
});
75
await session.send("Network.enable");
86
await session.send("Runtime.runIfWaitingForDebugger");
9-
};
7+
}

test/helpers/snapshotResolver.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)