Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing scripts field in package.json #39

Merged
merged 1 commit into from
Oct 20, 2017
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
6 changes: 6 additions & 0 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ class Init {
const packageInfo = JSON.parse(await this.readFile('package.json'))

// update 'scripts'
if (!('scripts' in packageInfo)) {
packageInfo.scripts = {}
}
const { scripts } = packageInfo
if (!('test' in scripts)) {
scripts.test = 'test'
}
Object.assign(scripts, {
'test:watch': `${scripts.test} --watch`,
'test:coverage': 'echo "unsupported." && exit 1',
Expand Down
12 changes: 11 additions & 1 deletion test/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ suite('init', () => {
await fs.remove(workDir)
})

test('write package.json', async () => {
test('update package.json', async () => {
await exec('init')
const pkg = await fs.readJson(packageJson)

Expand Down Expand Up @@ -66,6 +66,16 @@ suite('init', () => {
})
})

test('update package.json without fields', async () => {
await fs.writeJson(packageJson, {})
await exec('init')
const pkg = await fs.readJson(packageJson)
assert('scripts' in pkg)
assert('test' in pkg.scripts)
assert('lint-staged' in pkg)
assert('standard-version' in pkg)
})

test('copy .editorconfig', async () => {
await exec('init')

Expand Down