1
0
Fork 0

add basic integration tests

This commit is contained in:
Travis Fischer 2018-03-09 18:45:50 -05:00 committed by Joost De Cock
parent f67003ccfc
commit 7ddd168b3a
8 changed files with 3093 additions and 75 deletions

View file

@ -1,27 +1,5 @@
{
"parser": "babel-eslint",
"extends": [
"standard",
"standard-react"
],
"env": {
"es6": true
},
"plugins": [
"react"
],
"parserOptions": {
"sourceType": "module",
"allowImportExportEverywhere": true
},
"rules": {
// don't force es6 functions to include space before paren
"space-before-function-paren": 0,
// allow specifying true explicitly for boolean props
"react/jsx-boolean-value": 0,
// allow imports mixed with non-import statements at top of file
"import/first": 0
}
"standard"
]
}

View file

@ -18,3 +18,7 @@ dist
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# temp directories created during testing
my-test-library
nala

View file

@ -0,0 +1,10 @@
language: node_js
node_js:
- 9
- 8
- 6
- 4
cache:
yarn: true
directories:
- node_modules

View file

@ -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')

View file

@ -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)
})
})

View file

@ -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
}

View file

@ -9,6 +9,9 @@
"bin": {
"create-react-library": "index.js"
},
"scripts": {
"test": "ava -v && standard *.js lib/*.js"
},
"keywords": [
"react",
"preact",
@ -37,5 +40,10 @@
"p-each-series": "^1.0.0",
"parse-git-config": "^2.0.0",
"which": "^1.3.0"
},
"devDependencies": {
"ava": "^0.25.0",
"rmfr": "^2.0.0",
"standard": "^11.0.0"
}
}

File diff suppressed because it is too large Load diff