Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/bin-utils/__tests__/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jest.mock('../../bin-utils', () => {
return defaultPsConfig
}),
initialize: jest.fn(() => {
if (mockFindUp.mock.syncFail) {
return undefined
}
return {
packageScriptsPath: '/path/to/package-scripts.js',
packageJsonPath: '/path/to/package.json',
Expand Down Expand Up @@ -196,6 +199,22 @@ test('init without an existing config will initialize package-scripts.js', () =>
delete mockFindUp.mock.syncReturn
})

test('init without an existing package.json will fail', () => {
mockFindUp.mock.syncFail = true
mockFindUp.mock.syncReturn = undefined

const result = parse('init')
expect(result).toBe(undefined)
expect(mockReadLine.keyInYN).toHaveBeenCalledTimes(0)
expect(mockGetLogger.mock.error).toHaveBeenCalledWith(
expect.stringMatching(/Unable/),
)

delete mockFindUp.mock.syncFail
delete mockReadLine.mock.keyInYNReturn
delete mockFindUp.mock.syncReturn
})

test('if there is a help script in the psConfig, does not show the help', () => {
mockBinUtils.mock.psConfig = {scripts: {help: 'hi'}, options: {}}
expect(parse('help')).not.toBe(undefined)
Expand Down
1 change: 1 addition & 0 deletions src/bin-utils/initialize/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const CORE_SCRIPTS = [
function initialize(configType = 'js') {
/* eslint global-require:0,import/no-dynamic-require:0 */
const packageJsonPath = findUpSync('package.json')
/* istanbul ignore next */
if (packageJsonPath === null) {
return
}
Expand Down
2 changes: 1 addition & 1 deletion src/bin-utils/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function parse(rawArgv) {
}
}
const init = initialize(initArgv.type)
if (!packageScriptsPath) {
if (!init) {
log.error(chalk.red('Unable to to find an existing package.json'))
return
}
Expand Down