@@ -800,14 +800,51 @@ describe('ember-cli-babel', function() {
800800 } ) ;
801801
802802 describe ( 'TypeScript transpilation' , function ( ) {
803- beforeEach ( function ( ) {
804- this . addon . parent . addons . push ( {
805- name : 'ember-cli-typescript' ,
806- pkg : {
807- version : '4.0.0-alpha.1'
808- }
803+ let input ;
804+ let output ;
805+ let subject ;
806+ let project ;
807+ let unlink ;
808+
809+ beforeEach ( co . wrap ( function * ( ) {
810+ let fixturifyProject = new FixturifyProject ( 'whatever' , '0.0.1' ) ;
811+ fixturifyProject . addDependency ( 'ember-cli-typescript' , '4.0.0-alpha.1' , addon => {
812+ return prepareAddon ( addon ) ;
809813 } ) ;
810- } ) ;
814+ fixturifyProject . addDependency ( 'ember-cli-babel' , 'babel/ember-cli-babel#master' ) ;
815+ let pkg = JSON . parse ( fixturifyProject . toJSON ( 'package.json' ) ) ;
816+ fixturifyProject . writeSync ( ) ;
817+
818+ let linkPath = path . join ( fixturifyProject . root , 'whatever/node_modules/ember-cli-babel' ) ;
819+ let addonPath = path . resolve ( __dirname , '../' ) ;
820+ rimraf . sync ( linkPath ) ;
821+ fs . symlinkSync ( addonPath , linkPath , 'junction' ) ;
822+ unlink = ( ) => {
823+ fs . unlinkSync ( linkPath ) ;
824+ } ;
825+
826+ let cli = new MockCLI ( ) ;
827+ let root = path . join ( fixturifyProject . root , 'whatever' ) ;
828+ project = new EmberProject ( root , pkg , cli . ui , cli ) ;
829+ project . initializeAddons ( ) ;
830+ this . addon = project . addons . find ( a => { return a . name === 'ember-cli-babel' ; } ) ;
831+ input = yield createTempDir ( ) ;
832+ } ) ) ;
833+
834+ afterEach ( co . wrap ( function * ( ) {
835+ unlink ( ) ;
836+
837+ if ( input ) {
838+ yield input . dispose ( ) ;
839+ }
840+
841+ if ( output ) {
842+ yield output . dispose ( ) ;
843+ }
844+
845+ // shut down workers after the tests are run so that mocha doesn't hang
846+ yield terminateWorkerPool ( ) ;
847+ } ) ) ;
811848
812849 it ( 'should transpile .ts files' , co . wrap ( function * ( ) {
813850 input . write ( { 'foo.ts' : `let foo: string = "hi";` } ) ;
@@ -967,41 +1004,67 @@ describe('ember-cli-babel', function() {
9671004 } ) ;
9681005
9691006 describe ( '_shouldHandleTypeScript' , function ( ) {
1007+ let project ;
1008+ let unlink ;
1009+
1010+ let setupTsAddon = function * ( context , version = '4.0.0-alpha.1' ) {
1011+ let fixturifyProject = new FixturifyProject ( 'whatever' , '0.0.1' ) ;
1012+ fixturifyProject . addDependency ( 'ember-cli-typescript' , version , addon => {
1013+ return prepareAddon ( addon ) ;
1014+ } ) ;
1015+ fixturifyProject . addDependency ( 'ember-cli-babel' , 'babel/ember-cli-babel#master' ) ;
1016+ let pkg = JSON . parse ( fixturifyProject . toJSON ( 'package.json' ) ) ;
1017+ fixturifyProject . writeSync ( ) ;
1018+
1019+ let linkPath = path . join ( fixturifyProject . root , 'whatever/node_modules/ember-cli-babel' ) ;
1020+ let addonPath = path . resolve ( __dirname , '../' ) ;
1021+ rimraf . sync ( linkPath ) ;
1022+ fs . symlinkSync ( addonPath , linkPath , 'junction' ) ;
1023+ unlink = ( ) => {
1024+ fs . unlinkSync ( linkPath ) ;
1025+ } ;
1026+
1027+ let cli = new MockCLI ( ) ;
1028+ let root = path . join ( fixturifyProject . root , 'whatever' ) ;
1029+ project = new EmberProject ( root , pkg , cli . ui , cli ) ;
1030+ project . initializeAddons ( ) ;
1031+ context . addon = project . addons . find ( a => { return a . name === 'ember-cli-babel' ; } ) ;
1032+ input = yield createTempDir ( ) ;
1033+ }
1034+
1035+ afterEach ( co . wrap ( function * ( ) {
1036+ if ( unlink ) {
1037+ unlink ( ) ;
1038+ unlink = undefined ;
1039+ }
1040+
1041+ // shut down workers after the tests are run so that mocha doesn't hang
1042+ yield terminateWorkerPool ( ) ;
1043+ } ) ) ;
1044+
9701045 it ( 'should return false by default' , function ( ) {
971- expect ( _shouldHandleTypeScript ( { } , this . addon . parent ) ) . to . be . false ;
1046+ expect ( _shouldHandleTypeScript ( { } , this . addon . parent , this . addon . project ) ) . to . be . false ;
9721047 } ) ;
973- it ( 'should return true when ember-cli-typescript >= 4.0.0-alpha.1 is installed' , function ( ) {
974- this . addon . parent . addons . push ( {
975- name : 'ember-cli-typescript' ,
976- pkg : {
977- version : '4.0.0-alpha.1' ,
978- } ,
979- } ) ;
980- expect ( _shouldHandleTypeScript ( { } , this . addon . parent ) ) . to . be . true ;
1048+ it ( 'should return true when ember-cli-typescript >= 4.0.0-alpha.1 is installed' , function * ( ) {
1049+ yield setupTsAddon ( this ) ;
1050+ expect ( _shouldHandleTypeScript ( { } , this . addon . parent , this . addon . project ) ) . to . be . true ;
9811051 } ) ;
982- it ( 'should return false when ember-cli-typescript < 4.0.0-alpha.1 is installed' , function ( ) {
983- this . addon . parent . addons . push ( {
984- name : 'ember-cli-typescript' ,
985- pkg : {
986- version : '3.0.0' ,
987- } ,
988- } ) ;
989- expect ( _shouldHandleTypeScript ( { } , this . addon . parent ) ) . to . be . false ;
1052+ it ( 'should return false when ember-cli-typescript < 4.0.0-alpha.1 is installed' , function * ( ) {
1053+ yield setupTsAddon ( this , '3.0.0' ) ;
1054+ expect ( _shouldHandleTypeScript ( { } , this . addon . parent , this . addon . project ) ) . to . be . false ;
9901055 } ) ;
991- it ( 'should return true when the TypeScript transform is manually enabled' , function ( ) {
992- expect ( _shouldHandleTypeScript ( { 'ember-cli-babel' : { enableTypeScriptTransform : true } } , this . addon . parent ) ) . to . be . true ;
1056+ it ( 'should return true when the TypeScript transform is manually enabled' , function * ( ) {
1057+ yield setupTsAddon ( this , '3.0.0' ) ;
1058+ expect ( _shouldHandleTypeScript ( { 'ember-cli-babel' : { enableTypeScriptTransform : true } } , this . addon . parent , this . addon . project ) ) . to . be . true ;
9931059 } ) ;
1060+
9941061 it ( 'should return false when the TypeScript transforms is manually disabled' , function ( ) {
995- expect ( _shouldHandleTypeScript ( { 'ember-cli-babel' : { enableTypeScriptTransform : false } } , this . addon . parent ) ) . to . be . false ;
1062+ expect ( _shouldHandleTypeScript ( { 'ember-cli-babel' : { enableTypeScriptTransform : false } } , this . addon . parent , this . addon . project ) ) . to . be . false ;
9961063 } ) ;
997- it ( 'should return false when the TypeScript transform is manually disabled, even when ember-cli-typescript >= 4.0.0-alpha.1 is installed' , function ( ) {
998- this . addon . parent . addons . push ( {
999- name : 'ember-cli-typescript' ,
1000- pkg : {
1001- version : '4.0.0-alpha.1' ,
1002- } ,
1003- } ) ;
1004- expect ( _shouldHandleTypeScript ( { 'ember-cli-babel' : { enableTypeScriptTransform : false } } , this . addon . parent ) ) . to . be . false ;
1064+
1065+ it ( 'should return false when the TypeScript transform is manually disabled, even when ember-cli-typescript >= 4.0.0-alpha.1 is installed' , function * ( ) {
1066+ yield setupTsAddon ( this , '4.1.0' ) ;
1067+ expect ( _shouldHandleTypeScript ( { 'ember-cli-babel' : { enableTypeScriptTransform : false } } , this . addon . parent , this . addon . project ) ) . to . be . false ;
10051068 } ) ;
10061069 } ) ;
10071070
@@ -1177,17 +1240,17 @@ describe('ember-cli-babel', function() {
11771240
11781241 describe ( '_getExtensions' , function ( ) {
11791242 it ( 'defaults to js only' , function ( ) {
1180- expect ( _getExtensions ( { } , this . addon . parent ) ) . to . have . members ( [ 'js' ] ) ;
1243+ expect ( _getExtensions ( { } , this . addon . parent , this . addon . project ) ) . to . have . members ( [ 'js' ] ) ;
11811244 } ) ;
11821245 it ( 'adds ts automatically' , function ( ) {
11831246 this . addon . _shouldHandleTypeScript = function ( ) { return true ; }
1184- expect ( _getExtensions ( { 'ember-cli-babel' : { enableTypeScriptTransform : true } } , this . addon . parent ) ) . to . have . members ( [ 'js' , 'ts' ] ) ;
1247+ expect ( _getExtensions ( { 'ember-cli-babel' : { enableTypeScriptTransform : true } } , this . addon . parent , this . addon . project ) ) . to . have . members ( [ 'js' , 'ts' ] ) ;
11851248 } ) ;
11861249 it ( 'respects user-configured extensions' , function ( ) {
1187- expect ( _getExtensions ( { 'ember-cli-babel' : { extensions : [ 'coffee' ] } } , this . addon . parent ) ) . to . have . members ( [ 'coffee' ] ) ;
1250+ expect ( _getExtensions ( { 'ember-cli-babel' : { extensions : [ 'coffee' ] } } , this . addon . parent , this . addon . project ) ) . to . have . members ( [ 'coffee' ] ) ;
11881251 } ) ;
11891252 it ( 'respects user-configured extensions even when adding TS plugin' , function ( ) {
1190- expect ( _getExtensions ( { 'ember-cli-babel' : { enableTypeScriptTransform : true , extensions : [ 'coffee' ] } } , this . addon . parent ) ) . to . have . members ( [ 'coffee' ] ) ;
1253+ expect ( _getExtensions ( { 'ember-cli-babel' : { enableTypeScriptTransform : true , extensions : [ 'coffee' ] } } , this . addon . parent , this . addon . project ) ) . to . have . members ( [ 'coffee' ] ) ;
11911254 } ) ;
11921255 } ) ;
11931256
0 commit comments