Skip to content

Commit

Permalink
Refactor tests to use vitest and yeoman-test v10 helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
jozefizso committed Dec 29, 2024
1 parent 9043a1e commit 1c9646c
Show file tree
Hide file tree
Showing 7 changed files with 1,532 additions and 3,347 deletions.
90 changes: 38 additions & 52 deletions __tests__/test-app.test.js
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')
})
})
Loading

0 comments on commit 1c9646c

Please sign in to comment.