Skip to content

Commit 4ad1a8d

Browse files
test: stability
1 parent f9a19c5 commit 4ad1a8d

2 files changed

Lines changed: 79 additions & 75 deletions

File tree

src/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ wdm.hapiWrapper = hapiWrapper;
401401
* @returns {(ctx: EXPECTED_ANY, next: EXPECTED_FUNCTION) => Promise<void> | void} kow wrapper
402402
*/
403403
function koaWrapper(compiler, options, usePlugin) {
404+
const { finished } = require("node:stream");
405+
404406
const devMiddleware = wdm(compiler, options, usePlugin);
405407

406408
/**
@@ -445,9 +447,15 @@ function koaWrapper(compiler, options, usePlugin) {
445447
res.stream = (stream) => {
446448
ctx.body = stream;
447449

448-
isFinished = true;
450+
finished(stream, (err) => {
451+
isFinished = true;
449452

450-
resolve();
453+
if (err) {
454+
reject(err);
455+
} else {
456+
resolve();
457+
}
458+
});
451459
};
452460
/**
453461
* @param {string | Buffer} data data

test/middleware.test.js

Lines changed: 69 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -3771,10 +3771,11 @@ describe.each([
37713771

37723772
expect(response.statusCode).toBe(500);
37733773

3774-
if (name !== "hapi") {
3775-
expect(nextWasCalled).toBe(true);
3776-
} else {
3774+
// hapi and hono don't support passthrough errors
3775+
if (name === "hapi" || name === "hono") {
37773776
expect(nextWasCalled).toBe(false);
3777+
} else {
3778+
expect(nextWasCalled).toBe(true);
37783779
}
37793780
});
37803781

@@ -4232,87 +4233,83 @@ describe.each([
42324233
});
42334234

42344235
describe("writeToDisk option", () => {
4235-
(name === "hono" ? describe.skip : describe)(
4236-
'should work with "true" value',
4237-
() => {
4238-
let compiler;
4239-
4240-
const outputPath = path.resolve(
4241-
__dirname,
4242-
"./outputs/write-to-disk-true",
4243-
);
4236+
describe('should work with "true" value', () => {
4237+
let compiler;
42444238

4245-
beforeAll(async () => {
4246-
compiler = getCompiler({
4247-
...webpackConfig,
4248-
output: {
4249-
filename: "bundle.js",
4250-
path: outputPath,
4251-
publicPath: "/public/",
4252-
},
4253-
});
4239+
const outputPath = path.resolve(
4240+
__dirname,
4241+
"./outputs/write-to-disk-true",
4242+
);
42544243

4255-
[server, req, instance] = await frameworkFactory(
4256-
name,
4257-
framework,
4258-
compiler,
4259-
{ writeToDisk: true },
4260-
);
4244+
beforeAll(async () => {
4245+
compiler = getCompiler({
4246+
...webpackConfig,
4247+
output: {
4248+
filename: "bundle.js",
4249+
path: outputPath,
4250+
publicPath: "/public/",
4251+
},
42614252
});
42624253

4263-
afterAll(async () => {
4264-
await fs.promises.rm(outputPath, {
4265-
recursive: true,
4266-
force: true,
4267-
});
4268-
await close(server, instance);
4254+
[server, req, instance] = await frameworkFactory(
4255+
name,
4256+
framework,
4257+
compiler,
4258+
{ writeToDisk: true },
4259+
);
4260+
});
4261+
4262+
afterAll(async () => {
4263+
await fs.promises.rm(outputPath, {
4264+
recursive: true,
4265+
force: true,
42694266
});
4267+
await close(server, instance);
4268+
});
42704269

4271-
it("should find the bundle file on disk", (done) => {
4272-
req.get("/public/bundle.js").expect(200, (error) => {
4273-
if (error) {
4274-
return done(error);
4275-
}
4270+
it("should find the bundle file on disk", (done) => {
4271+
req.get("/public/bundle.js").expect(200, (error) => {
4272+
if (error) {
4273+
return done(error);
4274+
}
42764275

4277-
const bundlePath = path.resolve(
4278-
__dirname,
4279-
"./outputs/write-to-disk-true/bundle.js",
4280-
);
4276+
const bundlePath = path.resolve(
4277+
__dirname,
4278+
"./outputs/write-to-disk-true/bundle.js",
4279+
);
42814280

4282-
expect(
4283-
compiler.hooks.assetEmitted.taps.filter(
4284-
(hook) => hook.name === "DevMiddleware",
4285-
),
4286-
).toHaveLength(1);
4287-
expect(fs.existsSync(bundlePath)).toBe(true);
4281+
expect(
4282+
compiler.hooks.assetEmitted.taps.filter(
4283+
(hook) => hook.name === "DevMiddleware",
4284+
),
4285+
).toHaveLength(1);
4286+
expect(fs.existsSync(bundlePath)).toBe(true);
42884287

4289-
instance.invalidate();
4288+
instance.invalidate();
42904289

4291-
return compiler.hooks.done.tap(
4292-
"DevMiddlewareWriteToDiskTest",
4293-
() => {
4294-
expect(
4295-
compiler.hooks.assetEmitted.taps.filter(
4296-
(hook) => hook.name === "DevMiddleware",
4297-
),
4298-
).toHaveLength(1);
4290+
return compiler.hooks.done.tap(
4291+
"DevMiddlewareWriteToDiskTest",
4292+
() => {
4293+
expect(
4294+
compiler.hooks.assetEmitted.taps.filter(
4295+
(hook) => hook.name === "DevMiddleware",
4296+
),
4297+
).toHaveLength(1);
42994298

4300-
done();
4301-
},
4302-
);
4303-
});
4299+
done();
4300+
},
4301+
);
43044302
});
4303+
});
43054304

4306-
it("should not allow to get files above root", async () => {
4307-
const response = await req.get(
4308-
"/public/..%2f../middleware.test.js",
4309-
);
4305+
it("should not allow to get files above root", async () => {
4306+
const response = await req.get("/public/..%2f../middleware.test.js");
43104307

4311-
expect(response.statusCode).toBe(403);
4312-
expect(response.headers["content-type"]).toBe(
4313-
"text/html; charset=utf-8",
4314-
);
4315-
expect(response.text).toBe(`<!DOCTYPE html>
4308+
expect(response.statusCode).toBe(403);
4309+
expect(response.headers["content-type"]).toBe(
4310+
"text/html; charset=utf-8",
4311+
);
4312+
expect(response.text).toBe(`<!DOCTYPE html>
43164313
<html lang="en">
43174314
<head>
43184315
<meta charset="utf-8">
@@ -4322,9 +4319,8 @@ describe.each([
43224319
<pre>Forbidden</pre>
43234320
</body>
43244321
</html>`);
4325-
});
4326-
},
4327-
);
4322+
});
4323+
});
43284324

43294325
describe('should work with "true" value when the `output.clean` is `true`', () => {
43304326
const outputPath = path.resolve(

0 commit comments

Comments
 (0)