-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase test coverage, including incrementNodeInspectorPort (#1428)
* Add tests for incrementNodeInspectorPort * Fill out incrementNodeInspectorPort * Remove unused code from optionMissingArgument * Add tests for exit and custom throw * Error if call storeOptionsAsProperties with options already stored * Add test for bad params to parse * Error if parse "from" is unsupported * Can set alias after adding external command * Add test for invalid position to addHelpText * Clarify throw rather than display error * Add special case which displays help * Add test for incorrect return type on deprecated callback * Add test for implicit electron args * Add test for help requested on unknown subcommand * Add test for help suggestion including command path
- Loading branch information
1 parent
5173665
commit d8faba2
Showing
10 changed files
with
263 additions
and
13 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
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
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
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,135 @@ | ||
const childProcess = require('child_process'); | ||
const path = require('path'); | ||
const commander = require('../'); | ||
|
||
describe('incrementNodeInspectorPort', () => { | ||
let spawnSpy; | ||
let signalSpy; | ||
const oldExecArgv = process.execArgv; | ||
|
||
beforeAll(() => { | ||
spawnSpy = jest.spyOn(childProcess, 'spawn').mockImplementation(() => { | ||
return { | ||
on: () => {} | ||
}; | ||
}); | ||
signalSpy = jest.spyOn(process, 'on').mockImplementation(() => {}); | ||
}); | ||
|
||
afterEach(() => { | ||
spawnSpy.mockClear(); | ||
}); | ||
|
||
afterAll(() => { | ||
spawnSpy.mockRestore(); | ||
signalSpy.mockRestore(); | ||
process.execArgv = oldExecArgv; | ||
}); | ||
|
||
function makeProgram() { | ||
const program = new commander.Command(); | ||
const fileWhichExists = path.join(__dirname, './fixtures/pm-cache.js'); | ||
program.command('cache', 'stand-alone command', { executableFile: fileWhichExists }); | ||
return program; | ||
} | ||
|
||
function extractMockExecArgs(mock) { | ||
return mock.mock.calls[0][1].slice(0, -1); | ||
} | ||
|
||
test('when --inspect then bump port', () => { | ||
const program = makeProgram(); | ||
process.execArgv = ['--inspect']; | ||
program.parse(['node', 'test', 'cache']); | ||
const execArgs = extractMockExecArgs(spawnSpy); | ||
expect(execArgs).toEqual(['--inspect=127.0.0.1:9230']); | ||
}); | ||
|
||
test('when --inspect=100 then bump port', () => { | ||
const program = makeProgram(); | ||
process.execArgv = ['--inspect=100']; | ||
program.parse(['node', 'test', 'cache']); | ||
const execArgs = extractMockExecArgs(spawnSpy); | ||
expect(execArgs).toEqual(['--inspect=127.0.0.1:101']); | ||
}); | ||
|
||
test('when --inspect=1.2.3.4:100 then bump port', () => { | ||
const program = makeProgram(); | ||
process.execArgv = ['--inspect=1.2.3.4:100']; | ||
program.parse(['node', 'test', 'cache']); | ||
const execArgs = extractMockExecArgs(spawnSpy); | ||
expect(execArgs).toEqual(['--inspect=1.2.3.4:101']); | ||
}); | ||
|
||
test('when --inspect=1.2.3.4 then bump port', () => { | ||
const program = makeProgram(); | ||
process.execArgv = ['--inspect=1.2.3.4']; | ||
program.parse(['node', 'test', 'cache']); | ||
const execArgs = extractMockExecArgs(spawnSpy); | ||
expect(execArgs).toEqual(['--inspect=1.2.3.4:9230']); | ||
}); | ||
|
||
test('when --inspect-brk then bump port', () => { | ||
const program = makeProgram(); | ||
process.execArgv = ['--inspect-brk']; | ||
program.parse(['node', 'test', 'cache']); | ||
const execArgs = extractMockExecArgs(spawnSpy); | ||
expect(execArgs).toEqual(['--inspect-brk=127.0.0.1:9230']); | ||
}); | ||
|
||
test('when --inspect-brk=100 then bump port', () => { | ||
const program = makeProgram(); | ||
process.execArgv = ['--inspect-brk=100']; | ||
program.parse(['node', 'test', 'cache']); | ||
const execArgs = extractMockExecArgs(spawnSpy); | ||
expect(execArgs).toEqual(['--inspect-brk=127.0.0.1:101']); | ||
}); | ||
|
||
test('when --inspect-brk=1.2.3.4 then bump port', () => { | ||
const program = makeProgram(); | ||
process.execArgv = ['--inspect-brk=1.2.3.4']; | ||
program.parse(['node', 'test', 'cache']); | ||
const execArgs = extractMockExecArgs(spawnSpy); | ||
expect(execArgs).toEqual(['--inspect-brk=1.2.3.4:9230']); | ||
}); | ||
|
||
test('when --inspect-brk=1.2.3.4:100 then bump port', () => { | ||
const program = makeProgram(); | ||
process.execArgv = ['--inspect-brk=1.2.3.4:100']; | ||
program.parse(['node', 'test', 'cache']); | ||
const execArgs = extractMockExecArgs(spawnSpy); | ||
expect(execArgs).toEqual(['--inspect-brk=1.2.3.4:101']); | ||
}); | ||
|
||
test('when --inspect-port=100 then bump port', () => { | ||
const program = makeProgram(); | ||
process.execArgv = ['--inspect-port=100']; | ||
program.parse(['node', 'test', 'cache']); | ||
const execArgs = extractMockExecArgs(spawnSpy); | ||
expect(execArgs).toEqual(['--inspect-port=127.0.0.1:101']); | ||
}); | ||
|
||
test('when --inspect-port=1.2.3.4:100 then bump port', () => { | ||
const program = makeProgram(); | ||
process.execArgv = ['--inspect-port=1.2.3.4:100']; | ||
program.parse(['node', 'test', 'cache']); | ||
const execArgs = extractMockExecArgs(spawnSpy); | ||
expect(execArgs).toEqual(['--inspect-port=1.2.3.4:101']); | ||
}); | ||
|
||
test('when --inspect-unexpected then unchanged', () => { | ||
const program = makeProgram(); | ||
process.execArgv = ['--inspect-unexpected']; | ||
program.parse(['node', 'test', 'cache']); | ||
const execArgs = extractMockExecArgs(spawnSpy); | ||
expect(execArgs).toEqual(['--inspect-unexpected']); | ||
}); | ||
|
||
test('when --frozen-intrinsics then unchanged', () => { | ||
const program = makeProgram(); | ||
process.execArgv = ['--frozen-intrinsics ']; | ||
program.parse(['node', 'test', 'cache']); | ||
const execArgs = extractMockExecArgs(spawnSpy); | ||
expect(execArgs).toEqual(['--frozen-intrinsics ']); | ||
}); | ||
}); |