Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ci for webpack@beta.30 #1801

Merged
merged 16 commits into from
Sep 16, 2020
12 changes: 6 additions & 6 deletions test/config-name/config-name.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ describe('--config-name flag', () => {
it('should select only the config whose name is passed with --config-name', (done) => {
const { stderr, stdout } = run(__dirname, ['--config-name', 'first'], false);
expect(stderr).toBeFalsy();
expect(stdout).toContain('Child first');
expect(stdout).not.toContain('Child second');
expect(stdout).not.toContain('Child third');
expect(stdout).toContain('first');
expect(stdout).not.toContain('second');
expect(stdout).not.toContain('third');

stat(resolve(__dirname, './dist/dist-first.js'), (err, stats) => {
expect(err).toBe(null);
Expand All @@ -22,9 +22,9 @@ describe('--config-name flag', () => {
it('should work with multiple values for --config-name', (done) => {
const { stderr, stdout } = run(__dirname, ['--config-name', 'first', '--config-name', 'third'], false);
expect(stderr).toBeFalsy();
expect(stdout).toContain('Child first');
expect(stdout).not.toContain('Child second');
expect(stdout).toContain('Child third');
expect(stdout).toContain('first');
expect(stdout).not.toContain('second');
expect(stdout).toContain('third');

stat(resolve(__dirname, './dist/dist-first.js'), (err, stats) => {
expect(err).toBe(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('Zero Config', () => {
// default entry should be used
expect(stdout).toContain('./index.js');
// should pick up the output path from config
expect(stdout).toContain('Entrypoint main = test-output');
expect(stdout).toContain('test-output');
expect(stdout).toContain('Hash');
expect(stdout).toContain('Version');
expect(stdout).toContain('Built at');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('Default Config:', () => {
// default entry should be used
expect(stdout).toContain('./index.js');
// should pick up the output path from config
expect(stdout).toContain('Entrypoint main = test-output');
expect(stdout).toContain('test-output');
expect(stdout).toContain('Hash');
expect(stdout).toContain('Version');
expect(stdout).toContain('Built at');
Expand Down
4 changes: 2 additions & 2 deletions test/config/multiple/multiple-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ describe('Multiple config flag: ', () => {
// Should contain the correct exit code
expect(exitCode).toEqual(0);
// Should spawn multiple compilers
expect(stdout).toContain('Child amd:');
expect(stdout).toContain('Child commonjs:');
expect(stdout).toContain('amd:');
expect(stdout).toContain('commonjs:');

expect(stderr).toBeFalsy();

Expand Down
27 changes: 23 additions & 4 deletions test/core-flags/output-flags.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ const outputFlags = flagsFromCore.filter(({ name }) => name.startsWith('output-'
describe('output config related flag', () => {
outputFlags.forEach((flag) => {
// extract property name from flag name
const property = flag.name.split('output-')[1];
let property = flag.name.split('output-')[1];
if (property.includes('environment-')) {
property = property.split('environment-')[1];
}
const propName = hyphenToUpperCase(property);

if (flag.type === Boolean && !flag.name.includes('output-library')) {
Expand All @@ -32,9 +35,13 @@ describe('output config related flag', () => {
it(`should config --no-${flag.name} correctly`, () => {
const { stderr, stdout } = run(__dirname, [`--no-${flag.name}`]);

if (flag.name === 'output-enabled-chunk-loading-types-reset') {
if (flag.name.includes('loading-types-reset')) {
expect(stderr).toBeFalsy();
expect(stdout).toContain(`enabledChunkLoadingTypes: [ 'jsonp' ]`);
if (flag.name === 'output-enabled-wasm-loading-types-reset') {
expect(stdout).toContain(`enabledWasmLoadingTypes: [ 'fetch' ]`);
} else {
expect(stdout).toContain(`enabledChunkLoadingTypes: [ 'jsonp', 'import-scripts' ]`);
}
} else if (flag.name.includes('-reset')) {
const option = propName.split('Reset')[0];
expect(stderr).toBeFalsy();
Expand Down Expand Up @@ -76,7 +83,7 @@ describe('output config related flag', () => {
stdout = run(__dirname, [`--${flag.name}`, 'jsonp']).stdout;

expect(stdout).toContain(`${propName}: 'jsonp'`);
} else if (flag.name === 'output-enabled-chunk-loading-types') {
} else if (flag.name === 'output-enabled-chunk-loading-types' || flag.name === 'output-enabled-wasm-loading-types') {
stdout = run(__dirname, [`--${flag.name}`, 'async-node']).stdout;

expect(stdout).toContain(`${propName}: [ 'async-node' ]`);
Expand All @@ -103,6 +110,18 @@ describe('output config related flag', () => {
expect(stdout).toContain(`${propName}: [ 'var' ]`);
} else if (flag.name === 'output-path') {
expect(stdout).toContain('test');
} else if (flag.name === 'output-worker-chunk-loading') {
stdout = run(__dirname, [`--${flag.name}`, 'async-node']).stdout;
expect(stdout).toContain(`${propName}: 'async-node'`);
} else if (flag.name === 'output-worker-chunk-loading') {
stdout = run(__dirname, [`--${flag.name}`, 'async-node']).stdout;
expect(stdout).toContain(`${propName}: 'async-node'`);
} else if (flag.name === 'output-chunk-format') {
stdout = run(__dirname, [`--${flag.name}`, 'commonjs']).stdout;
expect(stdout).toContain(`${propName}: 'commonjs'`);
} else if (flag.name.includes('wasm')) {
stdout = run(__dirname, [`--${flag.name}`, 'async-node']).stdout;
expect(stdout).toContain(`${propName}: 'async-node'`);
} else {
expect(stderr).toBeFalsy();
expect(stdout).toContain(`${propName}: 'test'`);
Expand Down
3 changes: 3 additions & 0 deletions test/core-flags/stats-flags.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ describe('stats config related flag', () => {
expect(stdout).toContain(`stats: { ${propName}: 'log' }`);
} else if (flag.name === 'stats-context') {
expect(stdout).toContain('log');
} else if (flag.name === 'stats-entrypoints') {
stdout = run(__dirname, [`--${flag.name}`, 'auto']).stdout;
expect(stdout).toContain(`stats: { ${propName}: 'auto' }`);
} else {
expect(stdout).toContain(`stats: { ${propName}: [ 'log' ] }`);
}
Expand Down
4 changes: 1 addition & 3 deletions test/stats/cli-flags/stats.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ describe('stats flag', () => {
});

it('should warn when an unknown flag stats value is passed', () => {
const { stderr, stdout } = run(__dirname, ['--stats', 'foo']);
const { stderr } = run(__dirname, ['--stats', 'foo']);
expect(stderr).toBeTruthy();
expect(stderr).toContain('* configuration.stats should be one of these:');
expect(stderr).toContain('"none" | "errors-only" | "minimal" | "normal" | "detailed" | "verbose" | "errors-warnings"');
expect(stdout).toBeTruthy();
snitin315 marked this conversation as resolved.
Show resolved Hide resolved
});
});
8 changes: 6 additions & 2 deletions test/target/flag-test/target-flag.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
const { stat } = require('fs');
const { resolve } = require('path');
const { run } = require('../../utils/test-utils');
const { run, isWebpack5 } = require('../../utils/test-utils');

const targetValues = ['web', 'webworker', 'node', 'async-node', 'node-webkit', 'electron-main', 'electron-renderer', 'electron-preload'];

Expand Down Expand Up @@ -34,6 +34,10 @@ describe('--target flag', () => {

it(`should throw error with invalid value for --target`, () => {
const { stderr } = run(__dirname, ['--target', 'invalid']);
expect(stderr).toContain('Invalid configuration object');
if (isWebpack5) {
expect(stderr).toContain(`Error: Unknown target 'invalid'`);
} else {
expect(stderr).toContain('Invalid configuration object');
}
});
});
3 changes: 3 additions & 0 deletions test/utils/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ const execa = require('execa');
const { sync: spawnSync, node: execaNode } = execa;
const { Writable } = require('readable-stream');
const concat = require('concat-stream');
const { version } = require('webpack');

const WEBPACK_PATH = path.resolve(__dirname, '../../packages/webpack-cli/bin/cli.js');
const ENABLE_LOG_COMPILATION = process.env.ENABLE_PIPE || false;
const isWebpack5 = version.startsWith('5');

/**
* Run the webpack CLI for a test case.
Expand Down Expand Up @@ -275,4 +277,5 @@ module.exports = {
runInstall,
runInfo,
hyphenToUpperCase,
isWebpack5,
};
2 changes: 1 addition & 1 deletion test/zero-config/entry-present/zero-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('Zero Config tests', () => {
// Should be able to find the entry file
expect(stdout).toContain('./src/index.js');
// Should output at the default output dir and filename
expect(stdout).toContain('Entrypoint main = main.js');
expect(stdout).toContain('main.js');
// check that the output file exists
expect(fs.existsSync(path.join(__dirname, '/dist/main.js'))).toBeTruthy();
expect(stderr).toBeFalsy();
Expand Down