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: merge resolvers #2049

Merged
merged 10 commits into from Nov 7, 2020
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
37 changes: 0 additions & 37 deletions packages/webpack-cli/__tests__/resolveAdvanced.test.js

This file was deleted.

142 changes: 142 additions & 0 deletions packages/webpack-cli/__tests__/resolveArgs.test.js
@@ -0,0 +1,142 @@
const { resolve } = require('path');
const webpackCLI = require('../lib/webpack-cli');

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

const basicResolver = new webpackCLI().resolveArgs;

describe('BasicResolver', () => {
it('should handle the output option', async () => {
const result = await basicResolver({
outputPath: './bundle',
});
expect(result.options.output.path).toEqual(resolve('bundle'));
});

it('should handle the mode option [production]', async () => {
const result = await basicResolver(
{
mode: 'production',
},
{},
);
// ensure no other properties are added
expect(result.options).toMatchObject({ mode: 'production' });
expect(result.options.mode).toEqual('production');
});

it('should handle the mode option [development]', async () => {
const result = await basicResolver(
{
mode: 'development',
},
{},
);

// ensure no other properties are added
expect(result.options).toMatchObject({ mode: 'development' });
expect(result.options.mode).toEqual('development');
});

it('should handle the mode option [none]', async () => {
const result = await basicResolver(
{
mode: 'none',
},
{},
);

// ensure no other properties are added
expect(result.options).toMatchObject({ mode: 'none' });
expect(result.options.mode).toEqual('none');
});

it('should prefer supplied move flag over NODE_ENV', async () => {
process.env.NODE_ENV = 'production';
const result = await basicResolver(
{
mode: 'development',
},
{},
);

// ensure no other properties are added
expect(result.options).toMatchObject({ mode: 'development' });
});

it('should prefer supplied move flag over mode from config', async () => {
const result = await basicResolver(
{
mode: 'development',
},
{ mode: 'production' },
);

// ensure no other properties are added
expect(result.options).toMatchObject({ mode: 'development' });
});

it('should prefer mode form config over NODE_ENV', async () => {
process.env.NODE_ENV = 'development';
const result = await basicResolver({}, { mode: 'production' });

// ensure no other properties are added
expect(result.options).toMatchObject({ mode: 'production' });
});

it('should prefer mode form flag over NODE_ENV and config', async () => {
process.env.NODE_ENV = 'development';
const result = await basicResolver({ mode: 'none' }, { mode: 'production' });

// ensure no other properties are added
expect(result.options).toMatchObject({ mode: 'none' });
});

it('should assign json correctly', async () => {
const result = await basicResolver({
json: true,
});
expect(result.options.stats).toBeFalsy();
expect(result.outputOptions.json).toBeTruthy();
});

it('should assign stats correctly', async () => {
const result = await basicResolver({
stats: 'warning',
});
expect(result.options.stats).toEqual('warning');
expect(result.outputOptions.json).toBeFalsy();
});

it('should load the HMR plugin', async () => {
const result = await basicResolver({
hot: true,
});
expect(result.options.plugins[0].constructor.name).toEqual('HotModuleReplacementPlugin');
});

it('should load the prefetch plugin', async () => {
const result = await basicResolver({
prefetch: 'url',
});
expect(result.options.plugins[0].constructor.name).toEqual('PrefetchPlugin');
});

it('should load the webpack-bundle-analyzer plugin', async () => {
const result = await basicResolver({
analyze: true,
});
expect(result.options.plugins[0].constructor.name).toEqual('BundleAnalyzerPlugin');
});

{
targetValues.map((option) => {
it(`should handle ${option} option`, async () => {
const result = await basicResolver({
target: option,
});
expect(result.options.target).toEqual(option);
});
});
}
});
82 changes: 0 additions & 82 deletions packages/webpack-cli/__tests__/resolveMode.test.js

This file was deleted.

11 changes: 0 additions & 11 deletions packages/webpack-cli/__tests__/resolveOutput.test.js

This file was deleted.

19 changes: 0 additions & 19 deletions packages/webpack-cli/__tests__/resolveStats.js

This file was deleted.

40 changes: 0 additions & 40 deletions packages/webpack-cli/lib/groups/basicResolver.js

This file was deleted.

49 changes: 0 additions & 49 deletions packages/webpack-cli/lib/groups/resolveMode.js

This file was deleted.