8000 Add validation for package name in vue init by watilde · Pull Request #73 · vuejs/vue-cli · GitHub
[go: up one dir, main page]

Skip to content

Add validation for package name in vue init #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 11, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add test case for validation
  • Loading branch information
watilde committed Apr 10, 2016
commit ea95f3dbebd14b38256de0e67c43e591bcd2fd60
36 changes: 28 additions & 8 deletions test/e2e/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,27 @@ const crypto = require('crypto')
const render = require('consolidate').handlebars.render
const inquirer = require('inquirer')
const async = require('async')
const extend = Object.assign || require('util')._extend
const generate = require('../../lib/generate')

const MOCK_TEMPLATE_REPO_PATH = './test/e2e/mock-template-repo'
const MOCK_TEMPLATE_BUILD_PATH = path.resolve('./test/e2e/mock-template-build')

function monkeyPatchInquirer(answers) {
// monkey patch inquirer
inquirer.prompt = (questions, cb) => {
const key = questions[0].name
const _answers = {}
const validate = questions[0].validate
const valid = validate(answers[key])
if (valid !== true) {
throw new Error(valid)
}
_answers[key] = answers[key]
cb(_answers)
};
}

describe('vue-cli', () => {
const answers = {
name: 'vue-cli-test',
Expand All @@ -24,15 +40,8 @@ describe('vue-cli', () => {
pick: 'no'
}

// monkey patch inquirer
inquirer.prompt = (questions, cb) => {
const key = questions[0].name
const _answers = {}
_answers[key] = answers[key]
cb(_answers)
}

it('template generation', done => {
monkeyPatchInquirer(answers)
generate('test', MOCK_TEMPLATE_REPO_PATH, MOCK_TEMPLATE_BUILD_PATH, err => {
if (err) done(err)

Expand All @@ -56,6 +65,7 @@ describe('vue-cli', () => {
})

it('avoid rendering files that do not have mustaches', done => {
monkeyPatchInquirer(answers)
const binFilePath = `${MOCK_TEMPLATE_REPO_PATH}/template/bin.file`
const wstream = fs.createWriteStream(binFilePath)
wstream.write(crypto.randomBytes(100))
Expand All @@ -79,4 +89,14 @@ describe('vue-cli', () => {
})
})
})

it('validate input value', done => {
// deep copy
var invalidName = extend({}, answers, {name: 'INVALID-NAME'})
monkeyPatchInquirer(invalidName)
generate('INVALID-NAME', MOCK_TEMPLATE_REPO_PATH, MOCK_TEMPLATE_BUILD_PATH, err => {
expect(err).to.be.an('error');
done()
})
})
})
0