Skip to content

Commit

Permalink
Allow to disable unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Dec 30, 2017
1 parent 1312b51 commit 3e5a5b5
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 6 deletions.
6 changes: 5 additions & 1 deletion cli.js
Expand Up @@ -8,7 +8,11 @@ const pkg = require('./package')
const cli = cac()

cli.command('*', 'Generate a new project', input => {
const folderName = input[0] || '.'
if (input.length === 0) {
return cli.showHelp()
}

const folderName = input[0]
const targetPath = path.resolve(folderName)
console.log(`> Generating project in ${targetPath}`)

Expand Down
9 changes: 8 additions & 1 deletion sao.js
Expand Up @@ -23,6 +23,12 @@ module.exports = {
message: 'Use default manifest.json and icons for PWA',
store: true
},
unitTest: {
type: 'confirm',
default: true,
message: 'Use Tyu(Jest) to run unit tests',
store: true
},
username: {
message: `What's your GitHub username`,
default: ':gitUser:',
Expand All @@ -40,7 +46,8 @@ module.exports = {
filters: {
'src/pwa.js': 'pwa',
'static/manifest.json': 'manifest',
'static/icons/**': 'manifest'
'static/icons/**': 'manifest',
'src/components/App.test.js': 'unitTest'
},
gitInit: true,
installDependencies: true,
Expand Down
8 changes: 4 additions & 4 deletions template/package.json
Expand Up @@ -9,8 +9,8 @@
"dev": "poi",
"build": "poi build",
"report": "poi build --bundle-report",
"serve": "serve dist --single",
"test": "tyu"
"serve": "serve dist --single"<% if (unitTest) { %>,
"test": "tyu"<% } %>
},
"author": {
"name": "<%= username %>",
Expand All @@ -25,8 +25,8 @@
"devDependencies": {
"poi": "^9.0.0",
"poi-preset-bundle-report": "^2.0.0",
"serve": "^6.1.0",
"tyu": "^1.0.4"<% if (pwa) { %>,
"serve": "^6.1.0"<% if (unitTest) { %>,
"tyu": "^1.0.4"<% } %><% if (pwa) { %>,
"poi-preset-offline": "^9.0.0"<% } %>
}
}
39 changes: 39 additions & 0 deletions test/snapshots/test.js.md
Expand Up @@ -24,4 +24,43 @@ Generated by [AVA](https://ava.li).
'static/icons/android-chrome-192x192.png',
'static/icons/android-chrome-512x512.png',
'static/manifest.json',


## no unit test

> Snapshot 1
[
'.editorconfig',
'.gitignore',
'README.md',
'index.ejs',
'package.json',
'poi.config.js',
'src/components/App.vue',
'src/index.js',
'src/polyfills.js',
'src/pwa.js',
'static/favicon.ico',
'static/icons/android-chrome-192x192.png',
'static/icons/android-chrome-512x512.png',
'static/manifest.json',
]

> scripts
{
build: 'poi build',
dev: 'poi',
report: 'poi build --bundle-report',
serve: 'serve dist --single',
}

> devDependencies
{
poi: '^9.0.0',
'poi-preset-bundle-report': '^2.0.0',
'poi-preset-offline': '^9.0.0',
serve: '^6.1.0',
}
Binary file modified test/snapshots/test.js.snap
Binary file not shown.
10 changes: 10 additions & 0 deletions test/test.js
Expand Up @@ -8,3 +8,13 @@ test('defaults', async t => {
const res = await sao.mockPrompt(template, {})
t.snapshot(res.fileList)
})

test('no unit test', async t => {
const res = await sao.mockPrompt(template, {
unitTest: false
})
t.snapshot(res.fileList)
const pkg = JSON.parse(res.fileContents('package.json'))
t.snapshot(pkg.scripts, 'scripts')
t.snapshot(pkg.devDependencies, 'devDependencies')
})

0 comments on commit 3e5a5b5

Please sign in to comment.