Skip to content

Commit 9912722

Browse files
committed
chore: convert to esm
1 parent b12f3f9 commit 9912722

3 files changed

Lines changed: 19 additions & 25 deletions

File tree

test/e2e/api-plugin.test.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
"use strict";
2-
3-
const os = require("node:os");
4-
const path = require("node:path");
5-
const { describe, it } = require("node:test");
6-
const { expect } = require("expect");
7-
const { spyOn } = require("jest-mock");
8-
const webpack = require("webpack");
9-
const WebSocket = require("ws");
10-
const Server = require("../../lib/Server");
11-
const config = require("../fixtures/client-config/webpack.config");
12-
const multiCompilerConfig = require("../fixtures/multi-compiler-two-configurations/webpack.config");
13-
const compile = require("../helpers/compile");
14-
const runBrowser = require("../helpers/run-browser");
15-
const port = require("../ports-map")["api-plugin"];
16-
const [portA, portB] = require("../ports-map")["api-plugin-multi"];
1+
import os from "node:os";
2+
import path from "node:path";
3+
import { describe, it } from "node:test";
4+
import { expect } from "expect";
5+
import { spyOn } from "jest-mock";
6+
import webpack from "webpack";
7+
import WebSocket from "ws";
8+
import Server from "../../lib/Server.js";
9+
import config from "../fixtures/client-config/webpack.config.js";
10+
import multiCompilerConfig from "../fixtures/multi-compiler-two-configurations/webpack.config.js";
11+
import compile from "../helpers/compile.js";
12+
import runBrowser from "../helpers/run-browser.js";
13+
import portsMap from "../ports-map.js";
14+
15+
const port = portsMap["api-plugin"];
16+
const [portA, portB] = portsMap["api-plugin-multi"];
1717

1818
describe("API (plugin)", () => {
1919
it("should work with plugin API", async (t) => {

test/e2e/logging.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import fs from "graceful-fs";
66
import webpack from "webpack";
77
import Server from "../../lib/Server.js";
88
import config from "../fixtures/client-config/webpack.config.js";
9+
import compile from "../helpers/compile.js";
910
import HTMLGeneratorPlugin from "../helpers/html-generator-plugin.js";
1011
import runBrowser from "../helpers/run-browser.js";
1112
import portsMap from "../ports-map.js";

test/helpers/compile.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
"use strict";
2-
3-
// Helper function to check if server is ready using fetch
41
const waitForServer = async (port, timeout = 10000) => {
52
const start = Date.now();
63

74
while (Date.now() - start < timeout) {
85
try {
9-
// eslint-disable-next-line n/no-unsupported-features/node-builtins
106
await fetch(`http://127.0.0.1:${port}/`);
11-
return; // Server is ready
7+
return;
128
} catch {
13-
// Server not ready yet, wait and retry
149
await new Promise((resolve) => {
1510
setTimeout(resolve, 100);
1611
});
@@ -20,15 +15,14 @@ const waitForServer = async (port, timeout = 10000) => {
2015
throw new Error(`Server on port ${port} not ready after ${timeout}ms`);
2116
};
2217

23-
module.exports = (compiler, port = null) =>
18+
export default (compiler, port = null) =>
2419
new Promise((resolve, reject) => {
2520
const watching = compiler.watch({}, async (error, stats) => {
2621
if (error) {
2722
watching.close();
2823
return reject(error);
2924
}
3025

31-
// If a port is provided, wait for the server to be ready
3226
if (port) {
3327
try {
3428
await waitForServer(port);
@@ -38,7 +32,6 @@ module.exports = (compiler, port = null) =>
3832
}
3933
}
4034

41-
// Return both stats and watching for caller to manage
4235
resolve({ stats, watching });
4336
});
4437
});

0 commit comments

Comments
 (0)