Skip to content

Commit

Permalink
feat(server): add WEBPACK_DEV_SERVER env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed May 27, 2019
1 parent 4b097e2 commit 4e46438
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ if (semver.satisfies(process.version, '8.6.0 - 9')) {
tls.DEFAULT_ECDH_CURVE = 'auto';
}

if (!process.env.WEBPACK_DEV_SERVER) {
process.env.WEBPACK_DEV_SERVER = true;
}

class Server {
constructor(compiler, options = {}, _log) {
if (options.lazy && !options.filename) {
Expand Down Expand Up @@ -753,6 +757,10 @@ class Server {
if (fn) {
fn.call(this.listeningApp, err);
}

if (this.options.onListening) {
this.options.onListening();
}
});
}

Expand Down
26 changes: 26 additions & 0 deletions test/Server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,4 +474,30 @@ describe('Server', () => {
afterAll(testServer.close);
});
});

describe('WEBPACK_DEV_SERVER environment variable', () => {
const OLD_ENV = process.env;

beforeEach(() => {
// this is important - it clears the cache
jest.resetModules();

process.env = { ...OLD_ENV };

delete process.env.WEBPACK_DEV_SERVER;
});

afterEach(() => {
process.env = OLD_ENV;
});

it('should be present', () => {
expect(process.env.WEBPACK_DEV_SERVER).toBeUndefined();

// eslint-disable-next-line global-require
require('../lib/Server');

expect(process.env.WEBPACK_DEV_SERVER).toBe(true);
});
});
});

0 comments on commit 4e46438

Please sign in to comment.