layout unit tests

This commit is contained in:
Evan You
2018-01-02 12:36:53 -05:00
parent 1658c7f3ce
commit 0cb95a4e7c
12 changed files with 41 additions and 11 deletions

View File

@@ -10,6 +10,7 @@
"precommit": "lint-staged"
},
"jest": {
"testMatch": ["<rootDir>/test/**/*.js"],
"testEnvironment": "node",
"testPathIgnorePatterns": [
"/node_modules/",

View File

@@ -1,5 +0,0 @@
const path = require('path')
exports.ownDir = function (...args) {
return path.join(__dirname, '../', ...args)
}

View File

@@ -4,6 +4,14 @@ const { execSync } = require('child_process')
const padStart = require('string.prototype.padstart')
const { logWithSpinner, stopSpinner } = require('./spinner')
const wrapForTest = fn => {
return (...args) => {
if (!process.env.VUE_CLI_TEST) {
return fn.apply(null, args)
}
}
}
const format = (label, msg) => {
return msg.split('\n').map((line, i) => {
return i === 0
@@ -15,6 +23,8 @@ const format = (label, msg) => {
exports.logWithSpinner = logWithSpinner
exports.stopSpinner = stopSpinner
exports.log = msg => console.log(msg || '')
exports.info = msg => {
console.log(format(chalk.bgBlue.black(' INFO '), msg))
}
@@ -27,7 +37,7 @@ exports.warn = msg => {
console.warn(format(chalk.bgYellow.black(' WARN '), chalk.yellow(msg)))
}
exports.error = (msg) => {
exports.error = msg => {
console.error(format(chalk.bgRed(' ERROR '), chalk.red(msg)))
if (msg instanceof Error) {
console.error(msg.stack)
@@ -46,6 +56,11 @@ exports.clearConsole = title => {
}
}
// wrap all log utils for tests
Object.keys(exports).forEach(key => {
exports[key] = wrapForTest(exports[key])
})
exports.hasYarn = (() => {
try {
execSync('yarnpkg --version', { stdio: 'ignore' })

View File

View File

@@ -19,6 +19,7 @@ const {
} = require('./options')
const {
log,
hasGit,
hasYarn,
logWithSpinner,
@@ -135,14 +136,14 @@ module.exports = class Creator {
// log instructions
stopSpinner()
console.log()
console.log(`🎉 Successfully created project ${chalk.yellow(name)}.`)
console.log(
log()
log(`🎉 Successfully created project ${chalk.yellow(name)}.`)
log(
`👉 Get started with the following commands:\n\n` +
chalk.cyan(` ${chalk.gray('$')} cd ${name}\n`) +
chalk.cyan(` ${chalk.gray('$')} ${options.packageManager === 'yarn' ? 'yarn dev' : 'npm run dev'}`)
)
console.log()
log()
}
resolveIntroPrompts () {

View File

@@ -1,3 +1,3 @@
it('should pass', () => {
expect(1).toBe(1)
})

3
test/unit/Generator.js Normal file
View File

@@ -0,0 +1,3 @@
it('should pass', () => {
})

View File

@@ -0,0 +1,3 @@
it('should pass', () => {
})

3
test/unit/PluginAPI.js Normal file
View File

@@ -0,0 +1,3 @@
it('should pass', () => {
})

View File

@@ -0,0 +1,3 @@
it('should pass', () => {
})

3
test/unit/Service.js Normal file
View File

@@ -0,0 +1,3 @@
it('should pass', () => {
})

3
test/unit/options.js Normal file
View File

@@ -0,0 +1,3 @@
it('should pass', () => {
})