Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit

Permalink
refactor: improve choices output
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkdo committed Jun 10, 2019
1 parent c13a140 commit 47e3ba0
Show file tree
Hide file tree
Showing 4 changed files with 2,486 additions and 227 deletions.
69 changes: 30 additions & 39 deletions saofile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ module.exports = {
{
name: 'pm',
message: 'Choose a package manager',
choices: ['yarn', 'npm'],
choices: [
{ name: 'Yarn', value: 'yarn' },
{ name: 'Npm', value: 'npm' }
],
type: 'list',
default: 'yarn'
},
Expand All @@ -37,16 +40,16 @@ module.exports = {
message: 'Use a custom UI framework',
type: 'list',
choices: [
'none',
'bootstrap',
'vuetify',
'bulma',
'tailwind',
'element-ui',
'buefy',
'ant-design-vue',
'iview',
'tachyons'
{ name: 'None', value: 'none' },
{ name: 'Ant Design Vue', value: 'ant-design-vue' },
{ name: 'Bootstrap Vue', value: 'bootstrap' },
{ name: 'Buefy', value: 'buefy' },
{ name: 'Bulma', value: 'bulma' },
{ name: 'Element', value: 'element-ui' },
{ name: 'iView', value: 'iview' },
{ name: 'Tachyons', value: 'tachyons' },
{ name: 'Tailwind CSS', value: 'tailwind' },
{ name: 'Vuetify.js', value: 'vuetify' }
],
default: 'none'
},
Expand All @@ -55,14 +58,14 @@ module.exports = {
message: 'Use a custom server framework',
type: 'list',
choices: [
'none',
'express',
'koa',
'adonis',
'hapi',
'feathers',
'micro',
'fastify'
{ name: 'none', value: 'none' },
{ name: 'AdonisJs', value: 'adonis' },
{ name: 'Express', value: 'express' },
{ name: 'Fastify', value: 'fastify' },
{ name: 'Feathers', value: 'feathers' },
{ name: 'hapi', value: 'hapi' },
{ name: 'Koa', value: 'koa' },
{ name: 'Micro', value: 'micro' }
],
default: 'none'
},
Expand All @@ -71,22 +74,10 @@ module.exports = {
message: 'Choose features to install',
type: 'checkbox',
choices: [
{
name: 'Progressive Web App (PWA) Support',
value: 'pwa'
},
{
name: 'Linter / Formatter',
value: 'linter'
},
{
name: 'Prettier',
value: 'prettier'
},
{
name: 'Axios',
value: 'axios'
}
{ name: 'Axios', value: 'axios' },
{ name: 'ESLint', value: 'linter' },
{ name: 'Prettier', value: 'prettier' },
{ name: 'Progressive Web App (PWA) Support', value: 'pwa' },
],
default: []
},
Expand All @@ -95,9 +86,9 @@ module.exports = {
message: 'Use a custom test framework',
type: 'list',
choices: [
'none',
'jest',
'ava'
{ name: 'none', value: 'none' },
{ name: 'Jest', value: 'jest' },
{ name: 'AVA', value: 'ava' }
],
default: 'none'
},
Expand All @@ -106,7 +97,7 @@ module.exports = {
message: 'Choose rendering mode',
type: 'list',
choices: [
{ name: 'Universal', value: 'universal' },
{ name: 'Universal (SSR)', value: 'universal' },
{ name: 'Single Page App', value: 'spa' }
],
default: 'universal'
Expand Down
105 changes: 24 additions & 81 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path'
import test from 'ava'
import sao from 'sao'
import saoConfig from '../saofile'

const generator = path.join(__dirname, '..')

Expand All @@ -17,88 +18,30 @@ const verifyPkg = async (t, answers) => {
const stream = await sao.mock({ generator }, answers)

const pkg = await stream.readFile('package.json')
t.snapshot(stream.fileList, 'Generated files')
t.snapshot(stream.fileList, 'Generated package.json')
t.snapshot(getPkgFields(pkg), 'package.json')
}

test('defaults', async (t) => {
await verifyPkg(t)
})

test('use express', async (t) => {
await verifyPkg(t, {
server: 'express'
})
})

test('use koa', async (t) => {
await verifyPkg(t, {
server: 'koa'
})
})

test('use hapi', async (t) => {
await verifyPkg(t, {
server: 'hapi'
})
})

test('use feathers', async (t) => {
await verifyPkg(t, {
server: 'feathers'
})
})

test('use micro', async (t) => {
await verifyPkg(t, {
server: 'micro'
})
})

test('use fastify', async (t) => {
await verifyPkg(t, {
server: 'fastify'
})
})

test('use axios', async (t) => {
await verifyPkg(t, {
features: ['axios']
})
})

test('use jest', async (t) => {
await verifyPkg(t, {
test: 'jest'
})
})

test('use ava', async (t) => {
await verifyPkg(t, {
test: 'ava'
})
})

test('use eslint', async (t) => {
await verifyPkg(t, {
features: ['linter']
})
})

test('use yarn', async (t) => {
await verifyPkg(t, {
pm: 'yarn'
})
})

test('use prettier', async (t) => {
await verifyPkg(t, {
features: ['prettier']
})
})
const verifyNuxtConfig = async (t, answers = {}) => {
const stream = await sao.mock({ generator }, answers)
const configFile = answers.server === 'adonis' ? 'config/nuxt.js' : 'nuxt.config.js'
const config = await stream.readFile(configFile)
t.snapshot(config, `Generated ${configFile}`)
}

test('use pwa', async (t) => {
await verifyPkg(t, {
features: ['pwa']
})
})
test('verify default answers', async (t) => {
await verifyPkg(t)
await verifyNuxtConfig(t)
})

for (const prompt of saoConfig.prompts) {
if (Array.isArray(prompt.choices)) {
for (const choice of prompt.choices) {
test(`verify ${prompt.name}: ${choice.name}`, async (t) => {
const answer = { [prompt.name]: prompt.type === 'list' ? choice.value : [choice.value] }
await verifyPkg(t, answer)
await verifyNuxtConfig(t, answer)
})
}
}
}
Loading

0 comments on commit 47e3ba0

Please sign in to comment.