-
-
Notifications
You must be signed in to change notification settings - Fork 596
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove --mode flag validation (#1744)
- Loading branch information
Showing
5 changed files
with
10 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,34 @@ | ||
'use strict'; | ||
const { run } = require('../../utils/test-utils'); | ||
const { stat, readFile } = require('fs'); | ||
const { resolve } = require('path'); | ||
|
||
describe('mode flags', () => { | ||
it('should set mode=production by default', (done) => { | ||
it('should set mode=production by default', () => { | ||
const { stderr, stdout } = run(__dirname); | ||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain(`mode: 'production'`); | ||
|
||
stat(resolve(__dirname, './bin/main.js'), (err, stats) => { | ||
expect(err).toBe(null); | ||
expect(stats.isFile()).toBe(true); | ||
done(); | ||
}); | ||
readFile(resolve(__dirname, './bin/main.js'), 'utf-8', (err, data) => { | ||
expect(err).toBe(null); | ||
expect(data).toContain('production test'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should load a development config when --mode=development is passed', (done) => { | ||
it('should load a development config when --mode=development is passed', () => { | ||
const { stderr, stdout } = run(__dirname, ['--mode', 'development']); | ||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain(`mode: 'development'`); | ||
|
||
stat(resolve(__dirname, './bin/main.js'), (err, stats) => { | ||
expect(err).toBe(null); | ||
expect(stats.isFile()).toBe(true); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should load a production config when --mode=production is passed', (done) => { | ||
it('should load a production config when --mode=production is passed', () => { | ||
const { stderr, stdout } = run(__dirname, ['--mode', 'production']); | ||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain(`mode: 'production'`); | ||
|
||
stat(resolve(__dirname, './bin/main.js'), (err, stats) => { | ||
expect(err).toBe(null); | ||
expect(stats.isFile()).toBe(true); | ||
done(); | ||
}); | ||
readFile(resolve(__dirname, './bin/main.js'), 'utf-8', (err, data) => { | ||
expect(err).toBe(null); | ||
expect(data).toContain('production test'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should load a none config when --mode=none is passed', (done) => { | ||
it('should load a none config when --mode=none is passed', () => { | ||
const { stderr, stdout } = run(__dirname, ['--mode', 'none']); | ||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain(`mode: 'none'`); | ||
|
||
stat(resolve(__dirname, './bin/main.js'), (err, stats) => { | ||
expect(err).toBe(null); | ||
expect(stats.isFile()).toBe(true); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should show warning and load a production config when --mode=abcd is passed', (done) => { | ||
const { stderr, stdout } = run(__dirname, ['--mode', 'abcd']); | ||
expect(stderr).toContain('invalid value for "mode" option. Using "production" by default'); | ||
expect(stdout).toContain(`mode: 'production'`); | ||
|
||
stat(resolve(__dirname, './bin/main.js'), (err, stats) => { | ||
expect(err).toBe(null); | ||
expect(stats.isFile()).toBe(true); | ||
done(); | ||
}); | ||
readFile(resolve(__dirname, './bin/main.js'), 'utf-8', (err, data) => { | ||
expect(err).toBe(null); | ||
expect(data).toContain('production test'); | ||
done(); | ||
}); | ||
it('should throw error when --mode=abcd is passed', () => { | ||
const { stderr } = run(__dirname, ['--mode', 'abcd']); | ||
expect(stderr).toContain('configuration.mode should be one of these'); | ||
expect(stderr).toContain(`"development" | "production" | "none"`); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('test'); |