1
1
'use strict' ;
2
2
3
- const fs = require ( 'fs' ) ;
3
+ const fs = require ( 'fs-extra ' ) ;
4
4
const path = require ( 'path' ) ;
5
5
const helpers = require ( 'ember-cli-blueprint-test-helpers/helpers' ) ;
6
6
const chaiHelpers = require ( 'ember-cli-blueprint-test-helpers/chai' ) ;
7
+ const Blueprint = require ( 'ember-cli/lib/models/blueprint' ) ;
7
8
8
9
const ects = require ( '../../blueprints/ember-cli-typescript' ) ;
9
10
10
11
const expect = chaiHelpers . expect ;
11
12
const file = chaiHelpers . file ;
12
13
13
14
describe ( 'Acceptance: ember-cli-typescript generator' , function ( ) {
14
- helpers . setupTestHooks ( this ) ;
15
+ helpers . setupTestHooks ( this , { disabledTasks : [ 'addon-install' , 'bower-install' ] } ) ;
16
+
17
+ const originalTaskForFn = Blueprint . prototype . taskFor ;
18
+
19
+ beforeEach ( function ( ) {
20
+ Blueprint . prototype . taskFor = function ( taskName ) {
21
+ if ( taskName === 'npm-install' ) {
22
+ // Mock npm-install that only modifies package.json
23
+ return {
24
+ run : function ( options ) {
25
+ let pkgJson = fs . readJsonSync ( 'package.json' )
26
+ options . packages . forEach ( function ( pkg ) {
27
+ let pkgName = pkg . match ( / ^ ( .* ) @ [ ^ @ ] * $ / ) ;
28
+ pkgJson [ 'devDependencies' ] [ pkgName [ 1 ] ] = '*' ;
29
+ } ) ;
30
+ fs . writeJsonSync ( 'package.json' , pkgJson ) ;
31
+ }
32
+ }
33
+ }
34
+ return originalTaskForFn . call ( this , taskName ) ;
35
+ } ;
36
+ } ) ;
37
+
38
+ afterEach ( function ( ) {
39
+ Blueprint . prototype . taskFor = originalTaskForFn ;
40
+ } ) ;
15
41
16
42
it ( 'basic app' , function ( ) {
17
43
const args = [ 'ember-cli-typescript' ] ;
@@ -26,6 +52,11 @@ describe('Acceptance: ember-cli-typescript generator', function() {
26
52
const pkgJson = JSON . parse ( pkg . content ) ;
27
53
expect ( pkgJson . scripts . prepublishOnly ) . to . be . undefined ;
28
54
expect ( pkgJson . scripts . postpublish ) . to . be . undefined ;
55
+ expect ( pkgJson . devDependencies ) . to . include . all . keys ( 'ember-data' ) ;
56
+ expect ( pkgJson . devDependencies ) . to . include . all . keys ( '@types/ember-data' ) ;
57
+ expect ( pkgJson . devDependencies ) . to . include . all . keys ( 'ember-cli-qunit' ) ;
58
+ expect ( pkgJson . devDependencies ) . to . include . all . keys ( '@types/ember-qunit' , '@types/qunit' ) ;
59
+ expect ( pkgJson . devDependencies ) . to . not . have . any . keys ( '@types/ember-mocha' , '@types/mocha' ) ;
29
60
30
61
const tsconfig = file ( 'tsconfig.json' ) ;
31
62
expect ( tsconfig ) . to . exist ;
@@ -48,6 +79,9 @@ describe('Acceptance: ember-cli-typescript generator', function() {
48
79
49
80
const environmentTypes = file ( 'types/my-app/config/environment.d.ts' ) ;
50
81
expect ( environmentTypes ) . to . exist ;
82
+
83
+ const emberDataCatchallTypes = file ( 'types/ember-data.d.ts' ) ;
84
+ expect ( emberDataCatchallTypes ) . to . exist ;
51
85
} ) ;
52
86
} ) ;
53
87
@@ -64,6 +98,11 @@ describe('Acceptance: ember-cli-typescript generator', function() {
64
98
const pkgJson = JSON . parse ( pkg . content ) ;
65
99
expect ( pkgJson . scripts . prepublishOnly ) . to . equal ( 'ember ts:precompile' ) ;
66
100
expect ( pkgJson . scripts . postpublish ) . to . equal ( 'ember ts:clean' ) ;
101
+ expect ( pkgJson . devDependencies ) . to . not . have . any . keys ( 'ember-data' ) ;
102
+ expect ( pkgJson . devDependencies ) . to . not . have . any . keys ( '@types/ember-data' ) ;
103
+ expect ( pkgJson . devDependencies ) . to . include . all . keys ( 'ember-cli-qunit' ) ;
104
+ expect ( pkgJson . devDependencies ) . to . include . all . keys ( '@types/ember-qunit' , '@types/qunit' ) ;
105
+ expect ( pkgJson . devDependencies ) . to . not . have . any . keys ( '@types/ember-mocha' , '@types/mocha' ) ;
67
106
68
107
const tsconfig = file ( 'tsconfig.json' ) ;
69
108
expect ( tsconfig ) . to . exist ;
@@ -82,6 +121,9 @@ describe('Acceptance: ember-cli-typescript generator', function() {
82
121
const projectTypes = file ( 'types/dummy/index.d.ts' ) ;
83
122
expect ( projectTypes ) . to . exist ;
84
123
expect ( projectTypes ) . not . to . include ( ects . APP_DECLARATIONS ) ;
124
+
125
+ const emberDataCatchallTypes = file ( 'types/ember-data.d.ts' ) ;
126
+ expect ( emberDataCatchallTypes ) . not . to . exist ;
85
127
} ) ;
86
128
} ) ;
87
129
@@ -119,6 +161,9 @@ describe('Acceptance: ember-cli-typescript generator', function() {
119
161
const projectTypes = file ( 'types/my-app/index.d.ts' ) ;
120
162
expect ( projectTypes ) . to . exist ;
121
163
expect ( projectTypes ) . to . include ( ects . APP_DECLARATIONS ) ;
164
+
165
+ const emberDataCatchallTypes = file ( 'types/ember-data.d.ts' ) ;
166
+ expect ( emberDataCatchallTypes ) . to . exist ;
122
167
} ) ;
123
168
} ) ;
124
169
@@ -179,4 +224,44 @@ describe('Acceptance: ember-cli-typescript generator', function() {
179
224
expect ( json . include ) . to . deep . equal ( [ 'app' , 'addon' , 'tests' , 'types' ] ) ;
180
225
} ) ;
181
226
} ) ;
227
+
228
+ it ( 'app with Mocha' , function ( ) {
229
+ const args = [ 'ember-cli-typescript' ] ;
230
+
231
+ return helpers
232
+ . emberNew ( )
233
+ . then ( ( ) => helpers . modifyPackages ( [
234
+ { name : 'ember-cli-mocha' , dev : true } ,
235
+ { name : 'ember-cli-qunit' , delete : true } ,
236
+ ] ) )
237
+ . then ( ( ) => helpers . emberGenerate ( args ) )
238
+ . then ( ( ) => {
239
+ const pkg = file ( 'package.json' ) ;
240
+ expect ( pkg ) . to . exist ;
241
+
242
+ const pkgJson = JSON . parse ( pkg . content ) ;
243
+ expect ( pkgJson . devDependencies ) . to . include . all . keys ( '@types/ember-mocha' , '@types/mocha' ) ;
244
+ expect ( pkgJson . devDependencies ) . to . not . have . any . keys ( '@types/ember-qunit' , '@types/qunit' ) ;
245
+ } ) ;
246
+ } ) ;
247
+
248
+ it ( 'addon with Mocha' , function ( ) {
249
+ const args = [ 'ember-cli-typescript' ] ;
250
+
251
+ return helpers
252
+ . emberNew ( { target : 'addon' } )
253
+ . then ( ( ) => helpers . modifyPackages ( [
254
+ { name : 'ember-cli-mocha' , dev : true } ,
255
+ { name : 'ember-cli-qunit' , delete : true } ,
256
+ ] ) )
257
+ . then ( ( ) => helpers . emberGenerate ( args ) )
258
+ . then ( ( ) => {
259
+ const pkg = file ( 'package.json' ) ;
260
+ expect ( pkg ) . to . exist ;
261
+
262
+ const pkgJson = JSON . parse ( pkg . content ) ;
263
+ expect ( pkgJson . devDependencies ) . to . include . all . keys ( '@types/ember-mocha' , '@types/mocha' ) ;
264
+ expect ( pkgJson . devDependencies ) . to . not . have . any . keys ( '@types/ember-qunit' , '@types/qunit' ) ;
265
+ } ) ;
266
+ } ) ;
182
267
} ) ;
0 commit comments