@@ -3,6 +3,8 @@ import { join } from 'path';
33import * as webpack from './webpack' ;
44import { FileCache } from './util/file-cache' ;
55import * as helpers from './util/helpers' ;
6+ import * as ionicGlobal from './core/ionic-global' ;
7+ import * as bundleComponents from './core/bundle-components' ;
68
79describe ( 'Webpack Task' , ( ) => {
810 describe ( 'writeBundleFilesToDisk' , ( ) => {
@@ -43,6 +45,8 @@ describe('Webpack Task', () => {
4345 context . fileCache . set ( fileTwelvePath , { path : fileTwelvePath , content : fileTwelvePath + 'content' } ) ;
4446
4547 const writeFileSpy = spyOn ( helpers , helpers . writeFileAsync . name ) . and . returnValue ( Promise . resolve ( ) ) ;
48+ spyOn ( ionicGlobal , ionicGlobal . prependIonicGlobal . name ) ;
49+ spyOn ( bundleComponents , bundleComponents . doesCompilerExist . name ) . and . returnValue ( false ) ;
4650
4751 const promise = webpack . writeBundleFilesToDisk ( context ) ;
4852
@@ -52,8 +56,7 @@ describe('Webpack Task', () => {
5256 expect ( writeFileSpy . calls . all ( ) [ 0 ] . args [ 0 ] ) . toEqual ( fileOnePath ) ;
5357
5458 // igore the appended ionic global
55- let mainBundleContent = fileOnePath + 'content' ;
56- expect ( mainBundleContent . indexOf ( writeFileSpy . calls . all ( ) [ 0 ] . args [ 1 ] ) ) . toEqual ( - 1 ) ;
59+ expect ( writeFileSpy . calls . all ( ) [ 0 ] . args [ 1 ] ) . toEqual ( fileOnePath + 'content' ) ;
5760
5861 expect ( writeFileSpy . calls . all ( ) [ 1 ] . args [ 0 ] ) . toEqual ( fileTwoPath ) ;
5962
@@ -68,6 +71,49 @@ describe('Webpack Task', () => {
6871
6972 expect ( writeFileSpy . calls . all ( ) [ 5 ] . args [ 0 ] ) . toEqual ( fileSixPath ) ;
7073 expect ( writeFileSpy . calls . all ( ) [ 5 ] . args [ 1 ] ) . toEqual ( fileSixPath + 'content' ) ;
74+
75+ expect ( ionicGlobal . prependIonicGlobal ) . not . toHaveBeenCalled ( ) ;
76+ } ) ;
77+ } ) ;
78+
79+ it ( 'should preprend ionic core info' , ( ) => {
80+ const appDir = join ( 'some' , 'fake' , 'dir' , 'myApp' ) ;
81+ const buildDir = join ( appDir , 'www' , 'build' ) ;
82+
83+ const context = {
84+ fileCache : new FileCache ( ) ,
85+ buildDir : buildDir ,
86+ outputJsFileName : 'main.js'
87+ } ;
88+
89+ const fileOnePath = join ( buildDir , 'main.js' ) ;
90+ const fileTwoPath = join ( buildDir , 'main.js.map' ) ;
91+
92+ context . fileCache . set ( fileOnePath , { path : fileOnePath , content : fileOnePath + 'content' } ) ;
93+ context . fileCache . set ( fileTwoPath , { path : fileTwoPath , content : fileTwoPath + 'content' } ) ;
94+
95+ const prependIonicGlobalData = {
96+ code : 'someCode' ,
97+ map : 'someString'
98+ } ;
99+
100+ const writeFileSpy = spyOn ( helpers , helpers . writeFileAsync . name ) . and . returnValue ( Promise . resolve ( ) ) ;
101+ spyOn ( ionicGlobal , ionicGlobal . prependIonicGlobal . name ) . and . returnValue ( prependIonicGlobalData ) ;
102+ spyOn ( bundleComponents , bundleComponents . doesCompilerExist . name ) . and . returnValue ( true ) ;
103+
104+ const promise = webpack . writeBundleFilesToDisk ( context ) ;
105+
106+ return promise . then ( ( ) => {
107+ expect ( writeFileSpy ) . toHaveBeenCalledTimes ( 2 ) ;
108+
109+ expect ( writeFileSpy . calls . all ( ) [ 0 ] . args [ 0 ] ) . toEqual ( fileOnePath ) ;
110+
111+ // igore the appended ionic global
112+ expect ( writeFileSpy . calls . all ( ) [ 0 ] . args [ 1 ] ) . toEqual ( prependIonicGlobalData . code ) ;
113+
114+ expect ( writeFileSpy . calls . all ( ) [ 1 ] . args [ 0 ] ) . toEqual ( fileTwoPath ) ;
115+
116+ expect ( ionicGlobal . prependIonicGlobal ) . toHaveBeenCalled ( ) ;
71117 } ) ;
72118 } ) ;
73119 } ) ;
0 commit comments