@@ -10,6 +10,10 @@ import { Architect } from '@angular-devkit/architect';
10
10
import * as path from 'path' ;
11
11
import { browserBuild , createArchitect , host } from '../../../testing/test-utils' ;
12
12
13
+ // Following the naming conventions from
14
+ // https://sourcemaps.info/spec.html#h.ghqpj1ytqjbm
15
+ const IGNORE_LIST = 'x_google_ignoreList' ;
16
+
13
17
describe ( 'Browser Builder external source map' , ( ) => {
14
18
const target = { project : 'app' , target : 'build' } ;
15
19
let architect : Architect ;
@@ -50,3 +54,70 @@ describe('Browser Builder external source map', () => {
50
54
expect ( hasTsSourcePaths ) . toBe ( false , `vendor.js.map not should have '.ts' extentions` ) ;
51
55
} ) ;
52
56
} ) ;
57
+
58
+ describe ( 'Identifying third-party code in source maps' , ( ) => {
59
+ interface SourceMap {
60
+ sources : string [ ] ;
61
+ [ IGNORE_LIST ] : number [ ] ;
62
+ }
63
+
64
+ const target = { project : 'app' , target : 'build' } ;
65
+ let architect : Architect ;
66
+
67
+ beforeEach ( async ( ) => {
68
+ await host . initialize ( ) . toPromise ( ) ;
69
+ architect = ( await createArchitect ( host . root ( ) ) ) . architect ;
70
+ } ) ;
71
+ afterEach ( async ( ) => host . restore ( ) . toPromise ( ) ) ;
72
+
73
+ it ( 'specifies which sources are third party when vendor processing is disabled' , async ( ) => {
74
+ const overrides = {
75
+ sourceMap : {
76
+ scripts : true ,
77
+ vendor : false ,
78
+ } ,
79
+ } ;
80
+
81
+ const { files } = await browserBuild ( architect , host , target , overrides ) ;
82
+ const mainMap : SourceMap = JSON . parse ( await files [ 'main.js.map' ] ) ;
83
+ const polyfillsMap : SourceMap = JSON . parse ( await files [ 'polyfills.js.map' ] ) ;
84
+ const runtimeMap : SourceMap = JSON . parse ( await files [ 'runtime.js.map' ] ) ;
85
+ const vendorMap : SourceMap = JSON . parse ( await files [ 'vendor.js.map' ] ) ;
86
+
87
+ expect ( mainMap [ IGNORE_LIST ] ) . not . toBeUndefined ( ) ;
88
+ expect ( polyfillsMap [ IGNORE_LIST ] ) . not . toBeUndefined ( ) ;
89
+ expect ( runtimeMap [ IGNORE_LIST ] ) . not . toBeUndefined ( ) ;
90
+ expect ( vendorMap [ IGNORE_LIST ] ) . not . toBeUndefined ( ) ;
91
+
92
+ expect ( mainMap [ IGNORE_LIST ] . length ) . toEqual ( 0 ) ;
93
+ expect ( polyfillsMap [ IGNORE_LIST ] . length ) . not . toEqual ( 0 ) ;
94
+ expect ( runtimeMap [ IGNORE_LIST ] . length ) . not . toEqual ( 0 ) ;
95
+ expect ( vendorMap [ IGNORE_LIST ] . length ) . not . toEqual ( 0 ) ;
96
+
97
+ const thirdPartyInMain = mainMap . sources . some ( ( s ) => s . includes ( 'node_modules' ) ) ;
98
+ const thirdPartyInPolyfills = polyfillsMap . sources . some ( ( s ) => s . includes ( 'node_modules' ) ) ;
99
+ const thirdPartyInRuntime = runtimeMap . sources . some ( ( s ) => s . includes ( 'webpack' ) ) ;
100
+ const thirdPartyInVendor = vendorMap . sources . some ( ( s ) => s . includes ( 'node_modules' ) ) ;
101
+ expect ( thirdPartyInMain ) . toBe ( false , `main.js.map should not include any node modules` ) ;
102
+ expect ( thirdPartyInPolyfills ) . toBe ( true , `polyfills.js.map should include some node modules` ) ;
103
+ expect ( thirdPartyInRuntime ) . toBe ( true , `runtime.js.map should include some webpack code` ) ;
104
+ expect ( thirdPartyInVendor ) . toBe ( true , `vendor.js.map should include some node modules` ) ;
105
+
106
+ // All sources in the main map are first-party.
107
+ expect ( mainMap . sources . filter ( ( _ , i ) => ! mainMap [ IGNORE_LIST ] . includes ( i ) ) ) . toEqual ( [
108
+ './src/app/app.component.ts' ,
109
+ './src/app/app.module.ts' ,
110
+ './src/environments/environment.ts' ,
111
+ './src/main.ts' ,
112
+ ] ) ;
113
+
114
+ // Only some sources in the polyfills map are first-party.
115
+ expect ( polyfillsMap . sources . filter ( ( _ , i ) => ! polyfillsMap [ IGNORE_LIST ] . includes ( i ) ) ) . toEqual ( [
116
+ './src/polyfills.ts' ,
117
+ ] ) ;
118
+
119
+ // None of the sources in the runtime and vendor maps are first-party.
120
+ expect ( runtimeMap . sources . filter ( ( _ , i ) => ! runtimeMap [ IGNORE_LIST ] . includes ( i ) ) ) . toEqual ( [ ] ) ;
121
+ expect ( vendorMap . sources . filter ( ( _ , i ) => ! vendorMap [ IGNORE_LIST ] . includes ( i ) ) ) . toEqual ( [ ] ) ;
122
+ } ) ;
123
+ } ) ;
0 commit comments