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

test: cleanup #2688

Merged
merged 1 commit into from May 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 17 additions & 29 deletions test/build/basic/basic.test.js
Expand Up @@ -5,147 +5,135 @@ const { run } = require('../../utils/test-utils');

describe('bundle command', () => {
it('should work without command (default command)', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [], false);
const { exitCode, stderr, stdout } = await run(__dirname, []);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});

it('should work without command and options (default command)', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['--mode', 'development'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['--mode', 'development']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});

it('should work with multiple entries syntax without command (default command)', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['./src/index.js', './src/other.js'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['./src/index.js', './src/other.js']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});

it('should work with multiple entries syntax without command with options (default command)', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['./src/index.js', './src/other.js', '--mode', 'development'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['./src/index.js', './src/other.js', '--mode', 'development']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});

it('should work with multiple entries syntax without command with options #2 (default command)', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['--mode', 'development', './src/index.js', './src/other.js'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['--mode', 'development', './src/index.js', './src/other.js']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});

it('should work with multiple entries syntax without command with options #3 (default command)', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['./src/index.js', './src/other.js', '--entry', './src/again.js'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['./src/index.js', './src/other.js', '--entry', './src/again.js']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});

it('should work with and override entries from the configuration', async () => {
const { exitCode, stderr, stdout } = await run(
__dirname,
['./src/index.js', './src/other.js', '--config', './entry.config.js'],
false,
);
const { exitCode, stderr, stdout } = await run(__dirname, ['./src/index.js', './src/other.js', '--config', './entry.config.js']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});

it('should work with the "build" alias', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['build'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['build']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});

it('should work with "bundle" alias', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['bundle'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['bundle']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});

it('should work with the "b" alias', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['b'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['b']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});

it('should work with entries syntax using the "build" alias', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['build', './src/index.js'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['build', './src/index.js']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});

it('should work with entries syntax using the "bundle" alias', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['bundle', './src/index.js'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['bundle', './src/index.js']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});

it('should work with entries syntax using the "b" alias', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['b', './src/index.js'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['b', './src/index.js']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});

it('should work with multiple entries syntax using the "build" alias', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['build', './src/index.js', './src/other.js'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['build', './src/index.js', './src/other.js']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});

it('should work with multiple entries syntax using the "build" alias and options', async () => {
const { exitCode, stderr, stdout } = await run(
__dirname,
['build', './src/index.js', './src/other.js', '--mode', 'development'],
false,
);
const { exitCode, stderr, stdout } = await run(__dirname, ['build', './src/index.js', './src/other.js', '--mode', 'development']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});

it('should work with multiple entries syntax using the "build" alias and options', async () => {
const { exitCode, stderr, stdout } = await run(
__dirname,
['build', '--mode', 'development', './src/index.js', './src/other.js'],
false,
);
const { exitCode, stderr, stdout } = await run(__dirname, ['build', '--mode', 'development', './src/index.js', './src/other.js']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});

it('should log error and suggest right name on the "buil" command', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['buil'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['buil']);

expect(exitCode).toBe(2);
expect(stderr).toContain("Unknown command or entry 'buil'");
Expand Down
2 changes: 1 addition & 1 deletion test/build/build-variable/build-variable.test.js
Expand Up @@ -4,7 +4,7 @@ const { run } = require('../../utils/test-utils');

describe('bundle variable', () => {
it('compiles without flags and export variable', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [], false);
const { exitCode, stderr, stdout } = await run(__dirname, []);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
Expand Down
2 changes: 1 addition & 1 deletion test/build/bundle-variable/bundle-variable.test.js
Expand Up @@ -4,7 +4,7 @@ const { run } = require('../../utils/test-utils');

describe('bundle variable', () => {
it('compiles without flags and export variable', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [], false);
const { exitCode, stderr, stdout } = await run(__dirname, []);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
Expand Down
Expand Up @@ -2,7 +2,7 @@ const { run } = require('../../../utils/test-utils');

describe('webpack cli', () => {
it('should support CommonJS file', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['-c', 'webpack.config.cjs'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['-c', 'webpack.config.cjs']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
Expand Down
2 changes: 1 addition & 1 deletion test/build/config-format/commonjs/commonjs.test.js
Expand Up @@ -2,7 +2,7 @@ const { run } = require('../../../utils/test-utils');

describe('webpack cli', () => {
it('should support CommonJS file', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['-c', 'webpack.config.cjs'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['-c', 'webpack.config.cjs']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
Expand Down
Expand Up @@ -5,7 +5,7 @@ const { run } = require('../../../utils/test-utils');

describe('dotfolder array config lookup', () => {
it('should find a webpack array configuration in a dotfolder', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [], false);
const { exitCode, stderr, stdout } = await run(__dirname, []);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
Expand Down
Expand Up @@ -7,7 +7,7 @@ const { run } = require('../../../utils/test-utils');

describe('dotfolder single config lookup', () => {
it('should find a webpack configuration in a dotfolder', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [], false);
const { exitCode, stderr, stdout } = await run(__dirname, []);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
Expand Down
4 changes: 2 additions & 2 deletions test/build/config-lookup/relative/basic-config.test.js
Expand Up @@ -4,15 +4,15 @@ const { run } = require('../../../utils/test-utils');

describe('relative path to config', () => {
it('should work', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['-c', 'webpack.config.js', '--output-path', './binary/a'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['-c', 'webpack.config.js', '--output-path', './binary/a']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});

it('should work #2', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['-c', './webpack.config.js', '--output-path', './binary/b'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['-c', './webpack.config.js', '--output-path', './binary/b']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
Expand Down
12 changes: 6 additions & 6 deletions test/build/config-name/config-name.test.js
Expand Up @@ -4,7 +4,7 @@ const { run } = require('../../utils/test-utils');

describe('--config-name flag', () => {
it('should select only the config whose name is passed with --config-name', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['--config-name', 'first'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['--config-name', 'first']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
Expand All @@ -14,7 +14,7 @@ describe('--config-name flag', () => {
});

it('should work with multiple values for --config-name', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['--config-name', 'first', '--config-name', 'third'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['--config-name', 'first', '--config-name', 'third']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
Expand All @@ -39,15 +39,15 @@ describe('--config-name flag', () => {
});

it('should log error if invalid config name is provided', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['--config-name', 'test'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['--config-name', 'test']);

expect(exitCode).toBe(2);
expect(stderr).toContain('Configuration with the name "test" was not found.');
expect(stdout).toBeFalsy();
});

it('should log error if multiple configurations are not found', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['--config-name', 'test', '-c', 'single-config.js'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['--config-name', 'test', '-c', 'single-config.js']);

expect(exitCode).toBe(2);
expect(stderr).toContain('Configuration with the name "test" was not found.');
Expand Down Expand Up @@ -80,7 +80,7 @@ describe('--config-name flag', () => {
});

it('should work with config as a function', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['--config', 'function-config.js', '--config-name', 'first'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['--config', 'function-config.js', '--config-name', 'first']);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
Expand All @@ -104,7 +104,7 @@ describe('--config-name flag', () => {
});

it('should log error if invalid config name is provided ', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['--config', 'function-config.js', '--config-name', 'test'], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['--config', 'function-config.js', '--config-name', 'test']);

expect(exitCode).toBe(2);
expect(stderr).toContain('Configuration with the name "test" was not found.');
Expand Down
2 changes: 1 addition & 1 deletion test/build/config/absent/config-absent.test.js
Expand Up @@ -5,7 +5,7 @@ const { run } = require('../../../utils/test-utils');

describe('Config:', () => {
it('supplied config file is absent', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['-c', path.resolve(__dirname, 'webpack.config.js')], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['-c', path.resolve(__dirname, 'webpack.config.js')]);

// should throw with correct exit code
expect(exitCode).toBe(2);
Expand Down
11 changes: 6 additions & 5 deletions test/build/config/basic/basic-config.test.js
Expand Up @@ -5,11 +5,12 @@ const { run } = require('../../../utils/test-utils');

describe('basic config file', () => {
it('is able to understand and parse a very basic configuration file', async () => {
const { exitCode, stderr, stdout } = await run(
__dirname,
['-c', resolve(__dirname, 'webpack.config.js'), '--output-path', './binary'],
false,
);
const { exitCode, stderr, stdout } = await run(__dirname, [
'-c',
resolve(__dirname, 'webpack.config.js'),
'--output-path',
'./binary',
]);
expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
Expand Down
Expand Up @@ -4,7 +4,7 @@ const { run, isWebpack5 } = require('../../../../utils/test-utils');

describe('Zero Config', () => {
it('runs when config is present but not supplied via flag', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [], false);
const { exitCode, stderr, stdout } = await run(__dirname, []);

expect(exitCode).toEqual(0);
expect(stderr).toBeFalsy();
Expand Down
Expand Up @@ -4,7 +4,7 @@ const { run, isWebpack5 } = require('../../../../utils/test-utils');

describe('Default Config:', () => {
it('Should be able to pick cjs config by default', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [], false);
const { exitCode, stderr, stdout } = await run(__dirname, []);

expect(exitCode).toEqual(0);
expect(stderr).toBeFalsy();
Expand Down
Expand Up @@ -5,7 +5,7 @@ const { run } = require('../../../../utils/test-utils');

describe('multiple dev config files with webpack.config.js', () => {
it('Uses webpack.config.development.js', async () => {
const { stdout, stderr, exitCode } = await run(__dirname, [], false);
const { stdout, stderr, exitCode } = await run(__dirname, []);
expect(exitCode).toEqual(0);
expect(stderr).toBeFalsy();
expect(stdout).not.toBe(undefined);
Expand Down
Expand Up @@ -5,7 +5,7 @@ const { run } = require('../../../../utils/test-utils');

describe('multiple config files', () => {
it('Uses dev config when both dev and none are present', async () => {
const { stdout, stderr, exitCode } = await run(__dirname, [], false);
const { stdout, stderr, exitCode } = await run(__dirname, []);
expect(exitCode).toEqual(0);
expect(stderr).toBeFalsy();
expect(stdout).not.toBe(undefined);
Expand Down
Expand Up @@ -5,7 +5,7 @@ const { run } = require('../../../../utils/test-utils');

describe('multiple config files', () => {
it('Uses dev config when development mode is supplied', async () => {
const { stdout, stderr, exitCode } = await run(__dirname, ['--mode', 'development'], false);
const { stdout, stderr, exitCode } = await run(__dirname, ['--mode', 'development']);
expect(exitCode).toEqual(0);
expect(stderr).toBeFalsy();
expect(stdout).not.toBe(undefined);
Expand Down
2 changes: 1 addition & 1 deletion test/build/config/invalid-path/invalid-path.test.js
Expand Up @@ -4,7 +4,7 @@ const { run } = require('../../../utils/test-utils');

describe('basic config file', () => {
it('is able to understand and parse a very basic configuration file', async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['-c', path.resolve(__dirname, 'invalid-webpack.config.js')], false);
const { exitCode, stderr, stdout } = await run(__dirname, ['-c', path.resolve(__dirname, 'invalid-webpack.config.js')]);

expect(exitCode).toBe(2);
expect(stderr).toContain(`Failed to load '${path.resolve(__dirname, 'invalid-webpack.config.js')}' config`);
Expand Down
Expand Up @@ -5,11 +5,12 @@ const { run } = require('../../../utils/test-utils');

describe('basic config file', () => {
it('is able to understand and parse a very basic configuration file', async () => {
const { exitCode, stderr, stdout } = await run(
__dirname,
['-c', resolve(__dirname, 'webpack.config.js'), '--output-path', './binary'],
false,
);
const { exitCode, stderr, stdout } = await run(__dirname, [
'-c',
resolve(__dirname, 'webpack.config.js'),
'--output-path',
'./binary',
]);
expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
Expand Down