-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor tests to use
vitest
and yeoman-test
v10 helpers
- Loading branch information
Showing
7 changed files
with
1,532 additions
and
3,347 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 |
---|---|---|
@@ -1,98 +1,84 @@ | ||
'use strict' | ||
const path = require('path') | ||
const assert = require('yeoman-assert') | ||
const helpers = require('yeoman-test') | ||
import { describe } from 'vitest' | ||
import helpers from 'yeoman-test' | ||
import { test } from './yo-test.js' | ||
|
||
describe('license:app', () => { | ||
it('does not create new package.json', () => { | ||
return helpers | ||
.run(require.resolve('../app')) | ||
.withPrompts({ | ||
test('does not create new package.json', async ({ appLocation }) => { | ||
const result = await helpers.create(appLocation) | ||
.withAnswers({ | ||
name: 'Rick', | ||
email: '[email protected]', | ||
website: 'http://example.com', | ||
license: 'MIT' | ||
}) | ||
.then(() => { | ||
assert.file('LICENSE') | ||
assert.noFile('package.json') | ||
}) | ||
|
||
result.assertFile('LICENSE') | ||
result.assertNoFile('package.json') | ||
}) | ||
|
||
it('edit pre-existing package.json', () => { | ||
return helpers | ||
.run(require.resolve('../app')) | ||
.inTmpDir(function (dir) { | ||
const done = this.async() | ||
const fs = require('fs') | ||
fs.writeFile(path.join(dir, 'package.json'), '{}', done) | ||
test('edit pre-existing package.json', async ({ appLocation }) => { | ||
const result = await helpers.create(appLocation) | ||
.withFiles({ | ||
'package.json': '{}' | ||
}) | ||
.withPrompts({ | ||
.withAnswers({ | ||
name: 'Rick', | ||
email: '[email protected]', | ||
website: 'http://example.com', | ||
license: 'MIT' | ||
}) | ||
.then(() => { | ||
assert.file('LICENSE') | ||
assert.fileContent('package.json', '"license": "MIT"') | ||
}) | ||
|
||
result.assertFile('LICENSE') | ||
result.assertFileContent('package.json', '"license": "MIT"') | ||
}) | ||
|
||
it('with author options: --name --email --website', () => { | ||
return helpers | ||
.run(require.resolve('../app')) | ||
.withPrompts({ | ||
test('with author options: --name --email --website', async ({ appLocation }) => { | ||
const result = await helpers.create(appLocation) | ||
.withAnswers({ | ||
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') | ||
}) | ||
|
||
result.assertFileContent('LICENSE', 'ISC') | ||
result.assertFileContent('LICENSE', 'Rick <[email protected]> (http://example.com)') | ||
result.assertNoFile('package.json') | ||
}) | ||
|
||
it('makes npm module private when license selected is UNLICENSED', () => { | ||
return helpers | ||
.run(require.resolve('../app')) | ||
.inTmpDir((dir) => { | ||
const fs = require('fs') | ||
fs.writeFileSync(path.join(dir, 'package.json'), '{}') | ||
test('makes npm module private when license selected is UNLICENSED', async ({ appLocation }) => { | ||
const result = await helpers.create(appLocation) | ||
.withFiles({ | ||
'package.json': '{}' | ||
}) | ||
.withPrompts({ | ||
.withAnswers({ | ||
name: 'Rick', | ||
email: '[email protected]', | ||
website: 'http://example.com', | ||
licensePrompt: 'Choose a license', | ||
license: 'UNLICENSED' | ||
}) | ||
.then(() => { | ||
assert.fileContent('package.json', '"license": "UNLICENSED"') | ||
assert.fileContent('package.json', '"private": true') | ||
}) | ||
|
||
result.assertFileContent('package.json', '"license": "UNLICENSED"') | ||
result.assertFileContent('package.json', '"private": true') | ||
}) | ||
|
||
it('--output change the destination directory', () => { | ||
return helpers | ||
.run(path.join(__dirname, '../app')) | ||
test('--output change the destination directory', async ({ appLocation }) => { | ||
const result = await helpers.create(appLocation) | ||
.withOptions({ | ||
output: 'src/license.txt' | ||
}) | ||
.withPrompts({ | ||
.withAnswers({ | ||
name: 'Rick', | ||
email: '[email protected]', | ||
year: '2015', | ||
website: 'http://example.com', | ||
license: 'GPL-3.0' | ||
}) | ||
.then(() => { | ||
assert.file('src/license.txt') | ||
assert.noFile('LICENSE') | ||
}) | ||
|
||
result.assertFile('src/license.txt') | ||
result.assertNoFile('LICENSE') | ||
}) | ||
}) |
Oops, something went wrong.