Skip to content

Commit a224617

Browse files
committed
test: refactor
1 parent 4f646db commit a224617

File tree

3 files changed

+32
-103
lines changed

3 files changed

+32
-103
lines changed

test/e2e/DevServer.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,14 @@ describe('DevServer', () => {
8989
})
9090
.catch(done);
9191
});
92+
93+
it('should prepend devServer entry points depending on targetProperties', (done) => {
94+
testBin('--config ./test/fixtures/dev-server/target-config.js')
95+
.then((output) => {
96+
expect(output.exitCode).toEqual(0);
97+
expect(output.stderr).toContain('client/default/index.js');
98+
done();
99+
})
100+
.catch(done);
101+
});
92102
});
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const { resolve } = require('path');
2+
3+
module.exports = {
4+
mode: 'development',
5+
stats: 'detailed',
6+
entry: resolve(__dirname, './foo.js'),
7+
target: ['web', 'webworker'],
8+
output: {
9+
chunkLoading: false,
10+
wasmLoading: false,
11+
workerChunkLoading: false,
12+
},
13+
devServer: {
14+
client: {
15+
path: '/custom/path',
16+
},
17+
transportMode: {
18+
server: 'sockjs',
19+
client: 'sockjs',
20+
},
21+
}
22+
}

test/server/utils/DevServerPlugin.test.js

-103
Original file line numberDiff line numberDiff line change
@@ -254,107 +254,4 @@ describe('DevServerPlugin util', () => {
254254

255255
expect(typeof entries === 'function').toBe(true);
256256
});
257-
258-
(isWebpack5 ? it : it.skip)(
259-
'should prepend devServer entry points depending on targetProperties',
260-
async () => {
261-
// https://github.com/webpack/webpack/issues/11660
262-
const configNoChunkLoading = Object.assign({}, config);
263-
configNoChunkLoading.output = Object.assign(
264-
{
265-
chunkLoading: false,
266-
wasmLoading: false,
267-
workerChunkLoading: false,
268-
},
269-
config.output
270-
);
271-
272-
const webpackOptions = [
273-
Object.assign({ target: ['web', 'webworker'] }, configNoChunkLoading),
274-
Object.assign({ target: 'browserslist:last 2 versions' }, config),
275-
Object.assign({ target: ['web', 'node'] }, configNoChunkLoading),
276-
Object.assign(
277-
{ target: 'browserslist:last 2 versions, maintained node versions' },
278-
configNoChunkLoading
279-
),
280-
Object.assign(
281-
{ target: 'browserslist:maintained node versions' },
282-
config
283-
),
284-
Object.assign({ target: false }, config),
285-
];
286-
const compiler = webpack(webpackOptions);
287-
288-
const devServerOptions = {
289-
transportMode: {
290-
server: 'sockjs',
291-
client: 'sockjs',
292-
},
293-
};
294-
295-
await Promise.all(
296-
// eslint-disable-next-line no-shadow
297-
compiler.compilers.map((compiler, index) => {
298-
const plugin = new DevServerPlugin(devServerOptions);
299-
plugin.apply(compiler);
300-
301-
return getEntries(compiler).then((entries) => {
302-
const expectInline = index < 2; /* all but the node target */
303-
304-
expect(entries.length).toEqual(expectInline ? 2 : 1);
305-
306-
if (expectInline) {
307-
expect(
308-
normalize(entries[0]).indexOf('client/default/index.js?') !== -1
309-
).toBeTruthy();
310-
}
311-
312-
expect(normalize(entries[expectInline ? 1 : 0])).toEqual(
313-
'./foo.js'
314-
);
315-
});
316-
})
317-
);
318-
}
319-
);
320-
321-
it('should allows selecting compilations to inline the client into', async () => {
322-
const webpackOptions = [
323-
Object.assign({}, config),
324-
Object.assign({ target: 'web' }, config),
325-
Object.assign({ name: 'only-include' }, config) /* index:2 */,
326-
Object.assign({ target: 'node' }, config),
327-
];
328-
const compiler = webpack(webpackOptions);
329-
330-
const devServerOptions = {
331-
injectClient: (compilerConfig) => compilerConfig.name === 'only-include',
332-
transportMode: {
333-
server: 'sockjs',
334-
client: 'sockjs',
335-
},
336-
};
337-
338-
await Promise.all(
339-
// eslint-disable-next-line no-shadow
340-
compiler.compilers.map((compiler, index) => {
341-
const plugin = new DevServerPlugin(devServerOptions);
342-
plugin.apply(compiler);
343-
return getEntries(compiler).then((entries) => {
344-
const expectInline =
345-
index === 2; /* only the "only-include" compiler */
346-
347-
expect(entries.length).toEqual(expectInline ? 2 : 1);
348-
349-
if (expectInline) {
350-
expect(
351-
normalize(entries[0]).indexOf('client/default/index.js?') !== -1
352-
).toBeTruthy();
353-
}
354-
355-
expect(normalize(entries[expectInline ? 1 : 0])).toEqual('./foo.js');
356-
});
357-
})
358-
);
359-
});
360257
});

0 commit comments

Comments
 (0)