add basic integration tests
This commit is contained in:
parent
f67003ccfc
commit
7ddd168b3a
8 changed files with 3093 additions and 75 deletions
|
@ -13,10 +13,15 @@ const pkg = require('../package')
|
|||
|
||||
module.exports = async (info) => {
|
||||
const {
|
||||
dest,
|
||||
manager
|
||||
manager,
|
||||
name
|
||||
} = info
|
||||
|
||||
// handle scoped package names
|
||||
const parts = name.split('/')
|
||||
info.shortName = parts[parts.length - 1]
|
||||
|
||||
const dest = path.join(process.cwd(), info.shortName)
|
||||
await mkdirp(dest)
|
||||
|
||||
const source = path.join(__dirname, '../template')
|
||||
|
@ -48,6 +53,8 @@ module.exports = async (info) => {
|
|||
ora.promise(promise, 'Initializing git repo')
|
||||
await promise
|
||||
}
|
||||
|
||||
return dest
|
||||
}
|
||||
|
||||
module.exports.copyTemplateFile = async (opts) => {
|
||||
|
@ -62,7 +69,10 @@ module.exports.copyTemplateFile = async (opts) => {
|
|||
const destFilePath = path.join(dest, fileRelativePath)
|
||||
const destFileDir = path.parse(destFilePath).dir
|
||||
|
||||
const content = await consolidate.handlebars(file, info)
|
||||
const content = await consolidate.handlebars(file, {
|
||||
...info,
|
||||
yarn: (info.manager === 'yarn')
|
||||
})
|
||||
|
||||
await mkdirp(destFileDir)
|
||||
fs.writeFileSync(destFilePath, content, 'utf8')
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
'use strict'
|
||||
|
||||
const { test } = require('ava')
|
||||
const execa = require('execa')
|
||||
const rmfr = require('rmfr')
|
||||
|
||||
const createLibrary = require('./create-library')
|
||||
|
||||
const tests = [
|
||||
{
|
||||
name: 'my-test-library',
|
||||
author: 'nala',
|
||||
description: 'this is a auto-generated test module. please ignore.',
|
||||
repo: 'nala/my-test-library',
|
||||
license: 'MIT',
|
||||
manager: 'yarn'
|
||||
},
|
||||
{
|
||||
name: 'my-test-library',
|
||||
author: 'nala',
|
||||
description: 'this is a auto-generated test module. please ignore.',
|
||||
repo: 'nala/my-test-library',
|
||||
license: 'MIT',
|
||||
manager: 'npm'
|
||||
},
|
||||
{
|
||||
name: '@automagical/nala',
|
||||
author: 'superstar-cats',
|
||||
description: 'this is a auto-generated test module. please ignore.',
|
||||
repo: 'superstar-cats/nala',
|
||||
license: 'GPL',
|
||||
manager: 'yarn'
|
||||
}
|
||||
]
|
||||
|
||||
tests.forEach((info) => {
|
||||
test.serial(`creating "${info.name}" using ${info.manager}`, async (t) => {
|
||||
console.log(`creating "${info.name}" using ${info.manager}...`)
|
||||
// ensure library is created successfully
|
||||
const root = await createLibrary(info)
|
||||
t.truthy(root.indexOf(info.shortName) >= 0)
|
||||
|
||||
// ensure yarn runs successfully
|
||||
let ret = await execa.shell('yarn', { cwd: root })
|
||||
t.is(ret.code, 0)
|
||||
|
||||
// ensure jest tests pass
|
||||
ret = await execa.shell('yarn test', { cwd: root })
|
||||
t.is(ret.code, 0)
|
||||
|
||||
// ensure git is initialized properly
|
||||
ret = await execa.shell('git status', { cwd: root })
|
||||
t.is(ret.code, 0)
|
||||
|
||||
await rmfr(root)
|
||||
})
|
||||
})
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
const inquirer = require('inquirer')
|
||||
const isValidNpmName = require('is-valid-npm-name')
|
||||
const path = require('path')
|
||||
|
||||
module.exports = async (defaults) => {
|
||||
const info = await inquirer.prompt([
|
||||
|
@ -47,12 +46,5 @@ module.exports = async (defaults) => {
|
|||
}
|
||||
])
|
||||
|
||||
// handle scoped package names
|
||||
const parts = info.name.split('/')
|
||||
info.shortName = parts[parts.length - 1]
|
||||
|
||||
info.yarn = (info.manager === 'yarn')
|
||||
info.dest = path.join(process.cwd(), info.shortName)
|
||||
|
||||
return info
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue