Skip to content

Commit 834e8a9

Browse files
mike-marcaccishellscape
authored andcommitted
Fix problem with MultiCompiler in v4 (#88)
* add failing test for MultiCompiler * fix #87 - no failed hook on MultiCompiler * modify code semantics to maintainer preference * maintainer is a dummy and left an extra semicolon
1 parent 29c575b commit 834e8a9

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,19 @@ function koaDevware(dev, compiler) {
2121
resolve(true);
2222
});
2323

24-
compiler.hooks.failed.tap('KoaWebpack', (error) => {
25-
reject(error);
26-
});
24+
function tapFailedHook(comp) {
25+
comp.hooks.failed.tap('KoaWebpack', (error) => {
26+
reject(error);
27+
});
28+
}
29+
30+
if (compiler.compilers) {
31+
for (const child of compiler.compilers) {
32+
tapFailedHook(child);
33+
}
34+
} else {
35+
tapFailedHook(compiler);
36+
}
2737
});
2838
}
2939

test/results.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,42 @@ describe('koa-webpack', () => {
9090
});
9191
}).timeout(5e3);
9292

93+
it('sends the result to a MultiCompiler in watch mode', (done) => {
94+
const { middleware, req, server } = setup({
95+
dev: { lazy: false },
96+
config: [
97+
{
98+
entry: [path.resolve(__dirname, 'fixtures', 'input.js')],
99+
output: {
100+
path: path.resolve(__dirname, 'fixtures'),
101+
filename: 'output.js'
102+
}
103+
},
104+
{
105+
entry: [path.resolve(__dirname, 'fixtures', 'input.js')],
106+
output: {
107+
path: path.resolve(__dirname, 'fixtures'),
108+
filename: 'output2.js'
109+
}
110+
}
111+
]
112+
});
113+
req.get('/output.js')
114+
.expect(200)
115+
.expect((response) => {
116+
assert.ok(/Hello world/.test(response.text), "Expected result to contain 'Hello world'");
117+
})
118+
.then(() => req.get('/output2.js')
119+
.expect(200)
120+
.expect((response) => {
121+
assert.ok(/Hello world/.test(response.text), "Expected result to contain 'Hello world'");
122+
})
123+
.then(() => {
124+
server.kill();
125+
middleware.close(done);
126+
}));
127+
}).timeout(5e3);
128+
93129
it('builds and sends the result in lazy mode', (done) => {
94130
const { middleware, req, server } = setup({ dev: { lazy: true } });
95131
req.get('/output.js')

0 commit comments

Comments
 (0)