@@ -3,6 +3,8 @@ import { join } from 'path';
3
3
import * as webpack from './webpack' ;
4
4
import { FileCache } from './util/file-cache' ;
5
5
import * as helpers from './util/helpers' ;
6
+ import * as ionicGlobal from './core/ionic-global' ;
7
+ import * as bundleComponents from './core/bundle-components' ;
6
8
7
9
describe ( 'Webpack Task' , ( ) => {
8
10
describe ( 'writeBundleFilesToDisk' , ( ) => {
@@ -43,6 +45,8 @@ describe('Webpack Task', () => {
43
45
context . fileCache . set ( fileTwelvePath , { path : fileTwelvePath , content : fileTwelvePath + 'content' } ) ;
44
46
45
47
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 ) ;
46
50
47
51
const promise = webpack . writeBundleFilesToDisk ( context ) ;
48
52
@@ -52,8 +56,7 @@ describe('Webpack Task', () => {
52
56
expect ( writeFileSpy . calls . all ( ) [ 0 ] . args [ 0 ] ) . toEqual ( fileOnePath ) ;
53
57
54
58
// 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' ) ;
57
60
58
61
expect ( writeFileSpy . calls . all ( ) [ 1 ] . args [ 0 ] ) . toEqual ( fileTwoPath ) ;
59
62
@@ -68,6 +71,49 @@ describe('Webpack Task', () => {
68
71
69
72
expect ( writeFileSpy . calls . all ( ) [ 5 ] . args [ 0 ] ) . toEqual ( fileSixPath ) ;
70
73
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 ( ) ;
71
117
} ) ;
72
118
} ) ;
73
119
} ) ;
0 commit comments