Skip to content

Commit

Permalink
tests: add tests for multiple env
Browse files Browse the repository at this point in the history
  • Loading branch information
anshumanv committed Jul 31, 2020
1 parent 9c8b4ad commit a20e702
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions test/config/type/function-with-env/a.js
@@ -1 +1,3 @@
console.log('chuntaro');
// eslint-disable-next-line no-undef
console.log(envMessage || 'env message absent');
15 changes: 10 additions & 5 deletions test/config/type/function-with-env/function-with-env.test.js
@@ -1,5 +1,5 @@
'use strict';
const { existsSync } = require('fs');
const { existsSync, readFile } = require('fs');
const { resolve } = require('path');
const { run } = require('../../../utils/test-utils');

Expand All @@ -18,12 +18,17 @@ describe('function configuration', () => {
// Should generate the appropriate files
expect(existsSync(resolve(__dirname, './bin/dev.js'))).toBeTruthy();
});
it('is able to understand multiple env flags', () => {
const { stderr, stdout } = run(__dirname, ['--env', 'isDev', '--env', 'verboseStats']);
it('is able to understand multiple env flags', (done) => {
const { stderr, stdout } = run(__dirname, ['--env', 'isDev', '--env', 'verboseStats', '--env', 'envMessage']);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
// check that the verbose env is respected
expect(stdout).toContain('LOG from webpack.buildChunkGraph.visitModules');
// Should generate the appropriate files
expect(existsSync(resolve(__dirname, './bin/dev.js'))).toBeTruthy();
// check if the values from DefinePlugin make it to the compiled code
readFile(resolve(__dirname, './bin/dev.js'), 'utf-8', (err, data) => {
expect(err).toBe(null);
expect(data).toContain('env message present');
done();
});
});
});
3 changes: 3 additions & 0 deletions test/config/type/function-with-env/webpack.config.js
@@ -1,3 +1,5 @@
const { DefinePlugin } = require('webpack');

module.exports = (env) => {
if (env.isProd) {
return {
Expand All @@ -11,6 +13,7 @@ module.exports = (env) => {
entry: './a.js',
mode: 'development',
stats: env.verboseStats ? 'verbose' : 'normal',
plugins: [new DefinePlugin({ envMessage: env.envMessage ? 'env message present' : '' })],
output: {
filename: 'dev.js',
},
Expand Down

0 comments on commit a20e702

Please sign in to comment.