diff --git a/package.json b/package.json index 69a8a68f5..a5b7d51bf 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "precommit": "lint-staged" }, "jest": { + "testMatch": ["/test/**/*.js"], "testEnvironment": "node", "testPathIgnorePatterns": [ "/node_modules/", diff --git a/packages/@vue/cli-service/lib/util.js b/packages/@vue/cli-service/lib/util.js deleted file mode 100644 index 8af0a4e5b..000000000 --- a/packages/@vue/cli-service/lib/util.js +++ /dev/null @@ -1,5 +0,0 @@ -const path = require('path') - -exports.ownDir = function (...args) { - return path.join(__dirname, '../', ...args) -} diff --git a/packages/@vue/cli-shared-utils/index.js b/packages/@vue/cli-shared-utils/index.js index 80e2ac678..f07a628dd 100644 --- a/packages/@vue/cli-shared-utils/index.js +++ b/packages/@vue/cli-shared-utils/index.js @@ -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' }) diff --git a/packages/@vue/cli-test-utils/index.js b/packages/@vue/cli-test-utils/index.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/@vue/cli/lib/Creator.js b/packages/@vue/cli/lib/Creator.js index c362249c5..064a21329 100644 --- a/packages/@vue/cli/lib/Creator.js +++ b/packages/@vue/cli/lib/Creator.js @@ -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 () { diff --git a/test/test.js b/test/unit/Creator.js similarity index 59% rename from test/test.js rename to test/unit/Creator.js index 068f36575..779f9498b 100644 --- a/test/test.js +++ b/test/unit/Creator.js @@ -1,3 +1,3 @@ it('should pass', () => { - expect(1).toBe(1) + }) diff --git a/test/unit/Generator.js b/test/unit/Generator.js new file mode 100644 index 000000000..779f9498b --- /dev/null +++ b/test/unit/Generator.js @@ -0,0 +1,3 @@ +it('should pass', () => { + +}) diff --git a/test/unit/GeneratorAPI.js b/test/unit/GeneratorAPI.js new file mode 100644 index 000000000..779f9498b --- /dev/null +++ b/test/unit/GeneratorAPI.js @@ -0,0 +1,3 @@ +it('should pass', () => { + +}) diff --git a/test/unit/PluginAPI.js b/test/unit/PluginAPI.js new file mode 100644 index 000000000..779f9498b --- /dev/null +++ b/test/unit/PluginAPI.js @@ -0,0 +1,3 @@ +it('should pass', () => { + +}) diff --git a/test/unit/PromptModuleAPI.js b/test/unit/PromptModuleAPI.js new file mode 100644 index 000000000..779f9498b --- /dev/null +++ b/test/unit/PromptModuleAPI.js @@ -0,0 +1,3 @@ +it('should pass', () => { + +}) diff --git a/test/unit/Service.js b/test/unit/Service.js new file mode 100644 index 000000000..779f9498b --- /dev/null +++ b/test/unit/Service.js @@ -0,0 +1,3 @@ +it('should pass', () => { + +}) diff --git a/test/unit/options.js b/test/unit/options.js new file mode 100644 index 000000000..779f9498b --- /dev/null +++ b/test/unit/options.js @@ -0,0 +1,3 @@ +it('should pass', () => { + +})