|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const { run } = require('../utils/test-utils'); |
| 4 | + |
| 5 | +describe('basic info usage', () => { |
| 6 | + it('should validate webpack config successfully', () => { |
| 7 | + const { exitCode, stderr, stdout } = run(__dirname, ['configtest', './webpack.config.js'], false); |
| 8 | + |
| 9 | + expect(exitCode).toBe(0); |
| 10 | + expect(stderr).toBeFalsy(); |
| 11 | + expect(stdout).toContain('There are no validation errors in the given webpack configuration.'); |
| 12 | + }); |
| 13 | + |
| 14 | + it('should throw validation error', () => { |
| 15 | + const { exitCode, stderr, stdout } = run(__dirname, ['configtest', './error.config.js'], false); |
| 16 | + |
| 17 | + expect(exitCode).toBe(2); |
| 18 | + expect(stderr).toContain('Invalid configuration object.'); |
| 19 | + expect(stderr).toContain('configuration.mode should be one of these:'); |
| 20 | + expect(stdout).toBeFalsy(); |
| 21 | + }); |
| 22 | + |
| 23 | + it('should throw syntax error', () => { |
| 24 | + const { exitCode, stderr, stdout } = run(__dirname, ['configtest', './syntax-error.config.js'], false); |
| 25 | + |
| 26 | + expect(exitCode).toBe(2); |
| 27 | + expect(stderr).toContain(`SyntaxError: Unexpected token ';'`); |
| 28 | + expect(stdout).toBeFalsy(); |
| 29 | + }); |
| 30 | + |
| 31 | + it(`should validate the config with alias 't'`, () => { |
| 32 | + const { exitCode, stderr, stdout } = run(__dirname, ['t', './error.config.js'], false); |
| 33 | + |
| 34 | + expect(exitCode).toBe(2); |
| 35 | + expect(stderr).toContain('Invalid configuration object.'); |
| 36 | + expect(stderr).toContain('configuration.mode should be one of these:'); |
| 37 | + expect(stdout).toBeFalsy(); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should throw error if configuration does not exist', () => { |
| 41 | + const { exitCode, stderr, stdout } = run(__dirname, ['configtest', './a.js'], false); |
| 42 | + |
| 43 | + expect(exitCode).toBe(2); |
| 44 | + expect(stderr).toContain(`The specified config file doesn't exist`); |
| 45 | + expect(stdout).toBeFalsy(); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should throw error if no configuration was provided', () => { |
| 49 | + const { exitCode, stderr, stdout } = run(__dirname, ['configtest'], false); |
| 50 | + |
| 51 | + expect(exitCode).toBe(2); |
| 52 | + expect(stderr).toContain(`error: missing required argument 'config-path'`); |
| 53 | + expect(stdout).toBeFalsy(); |
| 54 | + }); |
| 55 | +}); |
0 commit comments