@@ -10,12 +10,13 @@ const async = require('async')
1010const extend = Object . assign || require ( 'util' ) . _extend
1111const generate = require ( '../../lib/generate' )
1212const metadata = require ( '../../lib/options' )
13+ const { isLocalPath, getTemplatePath } = require ( '../../lib/local-path' )
1314
14- const MOCK_META_JSON_PATH = './test/e2e/mock-meta-json'
15- const MOCK_TEMPLATE_REPO_PATH = './test/e2e/mock-template-repo'
15+ const MOCK_META_JSON_PATH = path . resolve ( './test/e2e/mock-meta-json' )
16+ const MOCK_TEMPLATE_REPO_PATH = path . resolve ( './test/e2e/mock-template-repo' )
1617const MOCK_TEMPLATE_BUILD_PATH = path . resolve ( './test/e2e/mock-template-build' )
17- const MOCK_METADATA_REPO_JS_PATH = './test/e2e/mock-metadata-repo-js'
18- const MOCK_SKIP_GLOB = './test/e2e/mock-skip-glob'
18+ const MOCK_METADATA_REPO_JS_PATH = path . resolve ( './test/e2e/mock-metadata-repo-js' )
19+ const MOCK_SKIP_GLOB = path . resolve ( './test/e2e/mock-skip-glob' )
1920
2021function monkeyPatchInquirer ( answers ) {
2122 // monkey patch inquirer
@@ -67,16 +68,16 @@ describe('vue-cli', () => {
6768 } )
6869 } )
6970
70- it ( 'adds additional data to meta data' , ( ) => {
71- const data = generate ( 'test' , MOCK_META_JSON_PATH , MOCK_TEMPLATE_BUILD_PATH )
71+ it ( 'adds additional data to meta data' , done => {
72+ const data = generate ( 'test' , MOCK_META_JSON_PATH , MOCK_TEMPLATE_BUILD_PATH , done )
7273 expect ( data . destDirName ) . to . equal ( 'test' )
7374 expect ( data . inPlace ) . to . equal ( false )
7475 } )
7576
76- it ( 'sets `inPlace` to true when generating in same directory' , ( ) => {
77+ it ( 'sets `inPlace` to true when generating in same directory' , done => {
7778 const currentDir = process . cwd ( )
7879 process . chdir ( MOCK_TEMPLATE_BUILD_PATH )
79- const data = generate ( 'test' , MOCK_META_JSON_PATH , MOCK_TEMPLATE_BUILD_PATH )
80+ const data = generate ( 'test' , MOCK_META_JSON_PATH , MOCK_TEMPLATE_BUILD_PATH , done )
8081 expect ( data . destDirName ) . to . equal ( 'test' )
8182 expect ( data . inPlace ) . to . equal ( true )
8283 process . chdir ( currentDir )
@@ -199,4 +200,27 @@ describe('vue-cli', () => {
199200 done ( )
200201 } )
201202 } )
203+
204+ it ( 'checks for local path' , ( ) => {
205+ expect ( isLocalPath ( '../' ) ) . to . equal ( true )
206+ expect ( isLocalPath ( '../../' ) ) . to . equal ( true )
207+ expect ( isLocalPath ( '../template' ) ) . to . equal ( true )
208+ expect ( isLocalPath ( '../template/abc' ) ) . to . equal ( true )
209+ expect ( isLocalPath ( './' ) ) . to . equal ( true )
210+ expect ( isLocalPath ( '.' ) ) . to . equal ( true )
211+ expect ( isLocalPath ( 'c:/' ) ) . to . equal ( true )
212+ expect ( isLocalPath ( 'D:/' ) ) . to . equal ( true )
213+
214+ expect ( isLocalPath ( 'webpack' ) ) . to . equal ( false )
215+ expect ( isLocalPath ( 'username/rep' ) ) . to . equal ( false )
216+ expect ( isLocalPath ( 'bitbucket:username/rep' ) ) . to . equal ( false )
217+ } )
218+
219+ it ( 'normalizes template path' , ( ) => {
220+ expect ( getTemplatePath ( '/' ) ) . to . equal ( '/' )
221+ expect ( getTemplatePath ( '/absolute/path' ) ) . to . equal ( '/absolute/path' )
222+
223+ expect ( getTemplatePath ( '..' ) ) . to . equal ( path . join ( __dirname , '/../../..' ) )
224+ expect ( getTemplatePath ( '../template' ) ) . to . equal ( path . join ( __dirname , '/../../../template' ) )
225+ } )
202226} )
0 commit comments