UNPKG

@interaktiv/dia-scripts

Version:

CLI toolbox with common scripts for most sort of projects at DIA

84 lines (77 loc) 2.56 kB
"use strict"; jest.mock('webpack', () => ({ NamedModulesPlugin: jest.fn(), DefinePlugin: jest.fn(), optimize: { ModuleConcatenationPlugin: jest.fn() }, NoEmitOnErrorsPlugin: jest.fn() })); jest.mock('webpack-bundle-analyzer', () => ({ BundleAnalyzerPlugin: jest.fn() })); jest.mock('mini-css-extract-plugin', () => Object.assign(jest.fn(), { loader: jest.fn() })); describe('configure webpack', () => { let originalEnv, originalExit, originalConsoleWarn; beforeEach(() => { originalEnv = process.env; originalExit = process.exit; process.exit = jest.fn(); originalConsoleWarn = console.warn; console.warn = jest.fn(); }); afterEach(() => { process.env = originalEnv; process.exit = originalExit; console.warn = originalConsoleWarn; jest.resetModules(); }); it('should consider mode', () => { expect(require('./webpack.config.js')('development', { _: [] }).mode).toBe('development'); }); it('should use the style extraction plugin in production', () => { const config = require('./webpack.config.js')('production', { _: [] }); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); expect(Array.isArray(config.plugins)).toBe(true); expect(config.plugins.map(p => p instanceof MiniCssExtractPlugin)).toContain(true); }); it('should recognize single --bundle-entry arguments', () => { const config = require('./webpack.config.js')('production', { _: [], 'bundle-entry': 'foo/bar.js' }); expect(typeof config.entry).toBe('object'); expect(config.entry.bar).toBe('foo/bar.js'); }); it('should recognize multiple --bundle-entry arguments', () => { const config = require('./webpack.config.js')('production', { _: [], 'bundle-entry': ['foo/bar.js', 'src/baz.js', 'herp/derp.js'] }); expect(typeof config.entry).toBe('object'); expect(config.entry.bar).toBe('foo/bar.js'); expect(config.entry.baz).toBe('src/baz.js'); expect(config.entry.derp).toBe('herp/derp.js'); }); it('should configure dev server', () => { const config = require('./webpack.config.js')('development', { _: [], 'dev-server': true }); expect(typeof config.devServer).toBe('object'); }); it('should configure dev proxy', () => { const config = require('./webpack.config.js')('development', { _: [], 'dev-proxy': '127.0.0.1:8080' }); expect(typeof config.devServer).toBe('object'); expect(config.devServer.proxy).toBeTruthy(); }); });