11'use strict' ;
22
3- const fs = require ( 'fs' ) ;
3+ const fs = require ( 'fs-extra ' ) ;
44const path = require ( 'path' ) ;
55const helpers = require ( 'ember-cli-blueprint-test-helpers/helpers' ) ;
66const chaiHelpers = require ( 'ember-cli-blueprint-test-helpers/chai' ) ;
7+ const Blueprint = require ( 'ember-cli/lib/models/blueprint' ) ;
78
89const ects = require ( '../../blueprints/ember-cli-typescript' ) ;
910
1011const expect = chaiHelpers . expect ;
1112const file = chaiHelpers . file ;
1213
1314describe ( '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+ } ) ;
1541
1642 it ( 'basic app' , function ( ) {
1743 const args = [ 'ember-cli-typescript' ] ;
@@ -26,6 +52,11 @@ describe('Acceptance: ember-cli-typescript generator', function() {
2652 const pkgJson = JSON . parse ( pkg . content ) ;
2753 expect ( pkgJson . scripts . prepublishOnly ) . to . be . undefined ;
2854 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' ) ;
2960
3061 const tsconfig = file ( 'tsconfig.json' ) ;
3162 expect ( tsconfig ) . to . exist ;
@@ -48,6 +79,9 @@ describe('Acceptance: ember-cli-typescript generator', function() {
4879
4980 const environmentTypes = file ( 'types/my-app/config/environment.d.ts' ) ;
5081 expect ( environmentTypes ) . to . exist ;
82+
83+ const emberDataCatchallTypes = file ( 'types/ember-data.d.ts' ) ;
84+ expect ( emberDataCatchallTypes ) . to . exist ;
5185 } ) ;
5286 } ) ;
5387
@@ -64,6 +98,11 @@ describe('Acceptance: ember-cli-typescript generator', function() {
6498 const pkgJson = JSON . parse ( pkg . content ) ;
6599 expect ( pkgJson . scripts . prepublishOnly ) . to . equal ( 'ember ts:precompile' ) ;
66100 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' ) ;
67106
68107 const tsconfig = file ( 'tsconfig.json' ) ;
69108 expect ( tsconfig ) . to . exist ;
@@ -82,6 +121,9 @@ describe('Acceptance: ember-cli-typescript generator', function() {
82121 const projectTypes = file ( 'types/dummy/index.d.ts' ) ;
83122 expect ( projectTypes ) . to . exist ;
84123 expect ( projectTypes ) . not . to . include ( ects . APP_DECLARATIONS ) ;
124+
125+ const emberDataCatchallTypes = file ( 'types/ember-data.d.ts' ) ;
126+ expect ( emberDataCatchallTypes ) . not . to . exist ;
85127 } ) ;
86128 } ) ;
87129
@@ -119,6 +161,9 @@ describe('Acceptance: ember-cli-typescript generator', function() {
119161 const projectTypes = file ( 'types/my-app/index.d.ts' ) ;
120162 expect ( projectTypes ) . to . exist ;
121163 expect ( projectTypes ) . to . include ( ects . APP_DECLARATIONS ) ;
164+
165+ const emberDataCatchallTypes = file ( 'types/ember-data.d.ts' ) ;
166+ expect ( emberDataCatchallTypes ) . to . exist ;
122167 } ) ;
123168 } ) ;
124169
@@ -179,4 +224,44 @@ describe('Acceptance: ember-cli-typescript generator', function() {
179224 expect ( json . include ) . to . deep . equal ( [ 'app' , 'addon' , 'tests' , 'types' ] ) ;
180225 } ) ;
181226 } ) ;
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+ } ) ;
182267} ) ;
0 commit comments