-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(license): achieve 100% coverage
- Loading branch information
1 parent
531842c
commit f8bf58d
Showing
1 changed file
with
81 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
'use strict' | ||
const path = require('path') | ||
const assert = require('yeoman-assert') | ||
const helpers = require('yeoman-test') | ||
|
||
describe('license:generators/license', () => { | ||
it('does not create new package.json', () => { | ||
return helpers | ||
.run(require.resolve('../generators/license')) | ||
.withPrompts({ | ||
name: 'Rick', | ||
email: '[email protected]', | ||
website: 'http://example.com', | ||
license: 'MIT' | ||
}) | ||
.then(() => { | ||
assert.file('LICENSE') | ||
assert.noFile('package.json') | ||
}) | ||
}) | ||
|
||
it('edit pre-existing package.json', () => { | ||
return helpers | ||
.run(require.resolve('../generators/license')) | ||
.inTmpDir(function (dir) { | ||
const done = this.async() | ||
const fs = require('fs') | ||
// eslint-disable-next-line security/detect-non-literal-fs-filename | ||
fs.writeFile(path.join(dir, 'package.json'), '{}', done) | ||
}) | ||
.withPrompts({ | ||
name: 'Rick', | ||
email: '[email protected]', | ||
website: 'http://example.com', | ||
license: 'MIT' | ||
}) | ||
.then(() => { | ||
assert.file('LICENSE') | ||
assert.fileContent('package.json', '"license": "MIT"') | ||
}) | ||
}) | ||
|
||
it('with author options: --name --email --website', () => { | ||
return helpers | ||
.run(require.resolve('../generators/license')) | ||
.withPrompts({ | ||
license: 'ISC' | ||
}) | ||
.withOptions({ | ||
name: 'Rick', | ||
email: '[email protected]', | ||
website: 'http://example.com' | ||
}) | ||
.then(() => { | ||
assert.fileContent('LICENSE', 'ISC') | ||
assert.fileContent('LICENSE', 'Rick <[email protected]> (http://example.com)') | ||
assert.noFile('package.json') | ||
}) | ||
}) | ||
|
||
it('makes npm module private when license selected is nolicense', () => { | ||
return helpers | ||
.run(require.resolve('../generators/license')) | ||
.inTmpDir(function (dir) { | ||
const fs = require('fs') | ||
// eslint-disable-next-line security/detect-non-literal-fs-filename | ||
fs.writeFileSync(path.join(dir, 'package.json'), '{}') | ||
}) | ||
.withPrompts({ | ||
name: 'Rick', | ||
email: '[email protected]', | ||
website: 'http://example.com', | ||
licensePrompt: 'Choose a license', | ||
license: 'nolicense' | ||
}) | ||
.then(() => { | ||
assert.noFileContent('package.json', '"license"') | ||
assert.fileContent('package.json', '"private": true') | ||
}) | ||
}) | ||
}) |