Skip to content

Commit

Permalink
test(Server): add addEntries tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroppy committed Apr 9, 2019
1 parent 0f7abdf commit 468e45f
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
59 changes: 59 additions & 0 deletions test/Server.test.js
@@ -1,5 +1,6 @@
'use strict';

const { relative, sep } = require('path');
const webpack = require('webpack');
const Server = require('../lib/Server');
const config = require('./fixtures/simple-config/webpack.config');
Expand All @@ -16,6 +17,64 @@ const allStats = [
];

describe('Server', () => {
describe('addEntries', () => {
it('add hot option', () => {
return new Promise((res) => {
// eslint-disable-next-line
const Server = require('../lib/Server');
const compiler = webpack(config);
const server = new Server(compiler, {
hot: true,
});

expect(
server.middleware.context.compiler.options.entry.map((p) => {
return relative('.', p).split(sep);
})
).toMatchSnapshot();
expect(
server.middleware.context.compiler.options.plugins
).toMatchSnapshot();

compiler.hooks.done.tap('webpack-dev-server', () => {
server.close(() => {
res();
});
});

compiler.run(() => {});
});
});

it('add hotOnly option', () => {
return new Promise((res) => {
// eslint-disable-next-line
const Server = require('../lib/Server');
const compiler = webpack(config);
const server = new Server(compiler, {
hotOnly: true,
});

expect(
server.middleware.context.compiler.options.entry.map((p) => {
return relative('.', p).split(sep);
})
).toMatchSnapshot();
expect(
server.middleware.context.compiler.options.plugins
).toMatchSnapshot();

compiler.hooks.done.tap('webpack-dev-server', () => {
server.close(() => {
res();
});
});

compiler.run(() => {});
});
});
});

// issue: https://github.com/webpack/webpack-dev-server/issues/1724
describe('express.static.mine.types', () => {
beforeEach(() => {
Expand Down
61 changes: 61 additions & 0 deletions test/__snapshots__/Server.test.js.snap
@@ -0,0 +1,61 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Server addEntries add hot option 1`] = `
Array [
Array [
"client",
"index.js?http:",
"localhost",
],
Array [
"node_modules",
"webpack",
"hot",
"dev-server.js",
],
Array [
"foo.js",
],
]
`;

exports[`Server addEntries add hot option 2`] = `
Array [
HotModuleReplacementPlugin {
"fullBuildTimeout": 200,
"multiStep": undefined,
"options": Object {},
"requestTimeout": 10000,
},
]
`;

exports[`Server addEntries add hotOnly option 1`] = `
Array [
Array [
"client",
"index.js?http:",
"localhost",
],
Array [
"node_modules",
"webpack",
"hot",
"only-dev-server.js",
],
Array [
"foo.js",
],
]
`;

exports[`Server addEntries add hotOnly option 2`] = `
Array [
HotModuleReplacementPlugin {
"fullBuildTimeout": 200,
"multiStep": undefined,
"options": Object {},
"requestTimeout": 10000,
},
]
`;

0 comments on commit 468e45f

Please sign in to comment.