@@ -2,6 +2,8 @@ import { Yok } from "../../../lib/common/yok";
2
2
import { WebpackCompilerService } from "../../../lib/services/webpack/webpack-compiler-service" ;
3
3
import { assert } from "chai" ;
4
4
5
+ const iOSPlatformName = "ios" ;
6
+ const androidPlatformName = "android" ;
5
7
const chunkFiles = [ "bundle.js" , "runtime.js" , "vendor.js" ] ;
6
8
7
9
function getAllEmittedFiles ( hash : string ) {
@@ -35,39 +37,54 @@ describe("WebpackCompilerService", () => {
35
37
describe ( "getUpdatedEmittedFiles" , ( ) => {
36
38
// backwards compatibility with old versions of nativescript-dev-webpack
37
39
it ( "should return only hot updates when nextHash is not provided" , async ( ) => {
38
- const result = webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash1" ) , chunkFiles , null ) ;
40
+ const result = webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash1" ) , chunkFiles , null , iOSPlatformName ) ;
39
41
const expectedEmittedFiles = [ 'bundle.hash1.hot-update.js' , 'hash1.hot-update.json' ] ;
40
42
41
43
assert . deepEqual ( result . emittedFiles , expectedEmittedFiles ) ;
42
44
} ) ;
43
45
// 2 successful webpack compilations
44
46
it ( "should return only hot updates when nextHash is provided" , async ( ) => {
45
- webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash1" ) , chunkFiles , "hash2" ) ;
46
- const result = webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash2" ) , chunkFiles , "hash3" ) ;
47
+ webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash1" ) , chunkFiles , "hash2" , iOSPlatformName ) ;
48
+ const result = webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash2" ) , chunkFiles , "hash3" , iOSPlatformName ) ;
47
49
48
50
assert . deepEqual ( result . emittedFiles , [ 'bundle.hash2.hot-update.js' , 'hash2.hot-update.json' ] ) ;
49
51
} ) ;
50
52
// 1 successful webpack compilation, n compilations with no emitted files
51
53
it ( "should return all files when there is a webpack compilation with no emitted files" , ( ) => {
52
- webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash1" ) , chunkFiles , "hash2" ) ;
53
- const result = webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash4" ) , chunkFiles , "hash5" ) ;
54
+ webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash1" ) , chunkFiles , "hash2" , iOSPlatformName ) ;
55
+ const result = webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash4" ) , chunkFiles , "hash5" , iOSPlatformName ) ;
54
56
55
57
assert . deepEqual ( result . emittedFiles , [ 'bundle.js' , 'runtime.js' , 'bundle.hash4.hot-update.js' , 'hash4.hot-update.json' ] ) ;
56
58
} ) ;
57
59
// 1 successful webpack compilation, n compilations with no emitted files, 1 successful webpack compilation
58
60
it ( "should return only hot updates after fixing the compilation error" , ( ) => {
59
- webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash1" ) , chunkFiles , "hash2" ) ;
60
- webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash5" ) , chunkFiles , "hash6" ) ;
61
- const result = webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash6" ) , chunkFiles , "hash7" ) ;
61
+ webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash1" ) , chunkFiles , "hash2" , iOSPlatformName ) ;
62
+ webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash5" ) , chunkFiles , "hash6" , iOSPlatformName ) ;
63
+ const result = webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash6" ) , chunkFiles , "hash7" , iOSPlatformName ) ;
62
64
63
65
assert . deepEqual ( result . emittedFiles , [ 'bundle.hash6.hot-update.js' , 'hash6.hot-update.json' ] ) ;
64
66
} ) ;
65
67
// 1 webpack compilation with no emitted files
66
68
it ( "should return all files when first compilation on livesync change is not successful" , ( ) => {
67
- ( < any > webpackCompilerService ) . expectedHash = "hash1" ;
68
- const result = webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash1" ) , chunkFiles , "hash2" ) ;
69
+ ( < any > webpackCompilerService ) . expectedHashes = {
70
+ "ios" : "hash1"
71
+ } ;
72
+ const result = webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash1" ) , chunkFiles , "hash2" , iOSPlatformName ) ;
69
73
70
74
assert . deepEqual ( result . emittedFiles , [ "bundle.hash1.hot-update.js" , "hash1.hot-update.json" ] ) ;
71
75
} ) ;
76
+ it ( "should return correct hashes when there are more than one platform" , ( ) => {
77
+ webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash1" ) , chunkFiles , "hash2" , iOSPlatformName ) ;
78
+ webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash3" ) , chunkFiles , "hash4" , androidPlatformName ) ;
79
+
80
+ webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash2" ) , chunkFiles , "hash5" , iOSPlatformName ) ;
81
+ webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash4" ) , chunkFiles , "hash6" , androidPlatformName ) ;
82
+
83
+ const iOSResult = webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash5" ) , chunkFiles , "hash7" , iOSPlatformName ) ;
84
+ assert . deepEqual ( iOSResult . emittedFiles , [ "bundle.hash5.hot-update.js" , "hash5.hot-update.json" ] ) ;
85
+
86
+ const androidResult = webpackCompilerService . getUpdatedEmittedFiles ( getAllEmittedFiles ( "hash6" ) , chunkFiles , "hash8" , androidPlatformName ) ;
87
+ assert . deepEqual ( androidResult . emittedFiles , [ "bundle.hash6.hot-update.js" , "hash6.hot-update.json" ] ) ;
88
+ } ) ;
72
89
} ) ;
73
90
} ) ;
0 commit comments