1
- import { Yok } from "../lib/common/yok" ;
1
+ import { Yok } from "../lib/common/yok" ;
2
2
import * as stubs from "./stubs" ;
3
- import { ProjectTemplatesService } from "../lib/services/project-templates-service" ;
3
+ import { ProjectTemplatesService } from "../lib/services/project-templates-service" ;
4
4
import * as assert from "assert" ;
5
5
import Future = require( "fibers/future" ) ;
6
6
import * as path from "path" ;
@@ -9,28 +9,28 @@ import temp = require("temp");
9
9
let isDeleteDirectoryCalledForNodeModulesDir = false ;
10
10
let nativeScriptValidatedTemplatePath = "nsValidatedTemplatePath" ;
11
11
12
- function createTestInjector ( configuration ?: { shouldNpmInstallThrow : boolean , npmInstallationDirContents : string [ ] , npmInstallationDirNodeModulesContents : string [ ] } ) : IInjector {
12
+ function createTestInjector ( configuration ?: { shouldNpmInstallThrow : boolean , npmInstallationDirContents : string [ ] , npmInstallationDirNodeModulesContents : string [ ] } ) : IInjector {
13
13
let injector = new Yok ( ) ;
14
14
injector . register ( "errors" , stubs . ErrorsStub ) ;
15
15
injector . register ( "logger" , stubs . LoggerStub ) ;
16
16
injector . register ( "fs" , {
17
17
readDirectory : ( dirPath : string ) : string [ ] => {
18
- if ( dirPath . toLowerCase ( ) . indexOf ( "node_modules" ) !== - 1 ) {
18
+ if ( dirPath . toLowerCase ( ) . indexOf ( "node_modules" ) !== - 1 ) {
19
19
return configuration . npmInstallationDirNodeModulesContents ;
20
20
}
21
21
return configuration . npmInstallationDirContents ;
22
22
} ,
23
23
24
24
deleteDirectory : ( directory : string ) => {
25
- if ( directory . indexOf ( "node_modules" ) !== - 1 ) {
25
+ if ( directory . indexOf ( "node_modules" ) !== - 1 ) {
26
26
isDeleteDirectoryCalledForNodeModulesDir = true ;
27
27
}
28
28
}
29
29
30
30
} ) ;
31
31
injector . register ( "npm" , {
32
32
install : ( packageName : string , pathToSave : string , config ?: any ) => {
33
- if ( configuration . shouldNpmInstallThrow ) {
33
+ if ( configuration . shouldNpmInstallThrow ) {
34
34
throw new Error ( "NPM install throws error." ) ;
35
35
}
36
36
@@ -40,7 +40,7 @@ function createTestInjector(configuration?: {shouldNpmInstallThrow: boolean, npm
40
40
41
41
injector . register ( "npmInstallationManager" , {
42
42
install : ( packageName : string , options ?: INpmInstallOptions ) => {
43
- if ( configuration . shouldNpmInstallThrow ) {
43
+ if ( configuration . shouldNpmInstallThrow ) {
44
44
throw new Error ( "NPM install throws error." ) ;
45
45
}
46
46
@@ -50,6 +50,8 @@ function createTestInjector(configuration?: {shouldNpmInstallThrow: boolean, npm
50
50
51
51
injector . register ( "projectTemplatesService" , ProjectTemplatesService ) ;
52
52
53
+ injector . register ( "analyticsService" , { track : ( ) => Future . fromResult ( ) } ) ;
54
+
53
55
return injector ;
54
56
}
55
57
@@ -61,36 +63,36 @@ describe("project-templates-service", () => {
61
63
} ) ;
62
64
63
65
describe ( "prepareTemplate" , ( ) => {
64
- describe ( "throws error" , ( ) => {
66
+ describe ( "throws error" , ( ) => {
65
67
it ( "when npm install fails" , ( ) => {
66
- testInjector = createTestInjector ( { shouldNpmInstallThrow : true , npmInstallationDirContents : [ ] , npmInstallationDirNodeModulesContents : null } ) ;
68
+ testInjector = createTestInjector ( { shouldNpmInstallThrow : true , npmInstallationDirContents : [ ] , npmInstallationDirNodeModulesContents : null } ) ;
67
69
projectTemplatesService = testInjector . resolve ( "projectTemplatesService" ) ;
68
70
let tempFolder = temp . mkdirSync ( "preparetemplate" ) ;
69
71
assert . throws ( ( ) => projectTemplatesService . prepareTemplate ( "invalidName" , tempFolder ) . wait ( ) ) ;
70
72
} ) ;
71
73
} ) ;
72
74
73
75
describe ( "returns correct path to template" , ( ) => {
74
- it ( "when reserved template name is used" , ( ) => {
75
- testInjector = createTestInjector ( { shouldNpmInstallThrow : false , npmInstallationDirContents : [ ] , npmInstallationDirNodeModulesContents : [ ] } ) ;
76
+ it ( "when reserved template name is used" , ( ) => {
77
+ testInjector = createTestInjector ( { shouldNpmInstallThrow : false , npmInstallationDirContents : [ ] , npmInstallationDirNodeModulesContents : [ ] } ) ;
76
78
projectTemplatesService = testInjector . resolve ( "projectTemplatesService" ) ;
77
79
let tempFolder = temp . mkdirSync ( "preparetemplate" ) ;
78
80
let actualPathToTemplate = projectTemplatesService . prepareTemplate ( "typescript" , tempFolder ) . wait ( ) ;
79
81
assert . strictEqual ( path . basename ( actualPathToTemplate ) , nativeScriptValidatedTemplatePath ) ;
80
82
assert . strictEqual ( isDeleteDirectoryCalledForNodeModulesDir , true , "When correct path is returned, template's node_modules directory should be deleted." ) ;
81
83
} ) ;
82
84
83
- it ( "when reserved template name is used (case-insensitive test)" , ( ) => {
84
- testInjector = createTestInjector ( { shouldNpmInstallThrow : false , npmInstallationDirContents : [ ] , npmInstallationDirNodeModulesContents : [ ] } ) ;
85
+ it ( "when reserved template name is used (case-insensitive test)" , ( ) => {
86
+ testInjector = createTestInjector ( { shouldNpmInstallThrow : false , npmInstallationDirContents : [ ] , npmInstallationDirNodeModulesContents : [ ] } ) ;
85
87
projectTemplatesService = testInjector . resolve ( "projectTemplatesService" ) ;
86
88
let tempFolder = temp . mkdirSync ( "preparetemplate" ) ;
87
89
let actualPathToTemplate = projectTemplatesService . prepareTemplate ( "tYpEsCriPT" , tempFolder ) . wait ( ) ;
88
90
assert . strictEqual ( path . basename ( actualPathToTemplate ) , nativeScriptValidatedTemplatePath ) ;
89
91
assert . strictEqual ( isDeleteDirectoryCalledForNodeModulesDir , true , "When correct path is returned, template's node_modules directory should be deleted." ) ;
90
92
} ) ;
91
93
92
- it ( "uses defaultTemplate when undefined is passed as parameter" , ( ) => {
93
- testInjector = createTestInjector ( { shouldNpmInstallThrow : false , npmInstallationDirContents : [ ] , npmInstallationDirNodeModulesContents : [ ] } ) ;
94
+ it ( "uses defaultTemplate when undefined is passed as parameter" , ( ) => {
95
+ testInjector = createTestInjector ( { shouldNpmInstallThrow : false , npmInstallationDirContents : [ ] , npmInstallationDirNodeModulesContents : [ ] } ) ;
94
96
projectTemplatesService = testInjector . resolve ( "projectTemplatesService" ) ;
95
97
let tempFolder = temp . mkdirSync ( "preparetemplate" ) ;
96
98
let actualPathToTemplate = projectTemplatesService . prepareTemplate ( undefined , tempFolder ) . wait ( ) ;
0 commit comments