-
-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add WEBPACK_SERVE environment variable (#2027)
* tests: add test case for requirement * feat: add WEBPACK_SERVE variable * refactor: declare into variable * feat: enforce use of env variable * chore: update variable defination * chore: update snapshots
- Loading branch information
1 parent
7c5a2ba
commit ea369a9
Showing
5 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const getPort = require('get-port'); | ||
const { runServe } = require('../../utils/test-utils'); | ||
|
||
const testPath = path.resolve(__dirname); | ||
|
||
describe('serve variable', () => { | ||
let port; | ||
|
||
beforeEach(async () => { | ||
port = await getPort(); | ||
}); | ||
|
||
const isWindows = process.platform === 'win32'; | ||
|
||
// TODO fix me on windows | ||
if (isWindows) { | ||
it('TODO: Fix on windows', () => { | ||
expect(true).toBe(true); | ||
}); | ||
return; | ||
} | ||
|
||
it('compiles without flags and export variable', async () => { | ||
const { stdout, stderr } = await runServe(['--port', port], testPath); | ||
expect(stdout).toContain('main.js'); | ||
expect(stdout).not.toContain('HotModuleReplacementPlugin'); | ||
expect(stderr).toHaveLength(0); | ||
expect(stdout).toContain('PASS'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('hello world'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const isInProcess = process.env.WEBPACK_SERVE; | ||
|
||
class CustomTestPlugin { | ||
constructor(isInEnvironment) { | ||
this.isInEnvironment = isInEnvironment; | ||
} | ||
apply(compiler) { | ||
compiler.hooks.done.tap('testPlugin', () => { | ||
if (!isInProcess && this.isInEnvironment) { | ||
console.log('PASS'); | ||
} else { | ||
console.log('FAIL'); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
module.exports = (env) => { | ||
return { | ||
mode: 'development', | ||
devtool: false, | ||
plugins: [new CustomTestPlugin(env.WEBPACK_SERVE)], | ||
}; | ||
}; |