| 
									
										
										
										
											2018-02-13 11:26:06 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2018-02-13 11:26:06 -08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-25 23:16:56 +01:00
										 |  |  | import {obsoleteInIvy} from '@angular/private/testing'; | 
					
						
							| 
									
										
										
										
											2018-03-13 11:00:53 -07:00
										 |  |  | import * as fs from 'fs'; | 
					
						
							| 
									
										
										
										
											2018-02-13 11:26:06 -08:00
										 |  |  | import * as path from 'path'; | 
					
						
							|  |  |  | import * as shx from 'shelljs'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-25 20:50:54 +01:00
										 |  |  | // Resolve the "npm_package" directory by using the runfile resolution. Note that we need to
 | 
					
						
							|  |  |  | // resolve the "package.json" of the package since otherwise NodeJS would resolve the "main"
 | 
					
						
							|  |  |  | // file, which is not necessarily at the root of the "npm_package".
 | 
					
						
							|  |  |  | shx.cd(path.dirname(require.resolve('angular/packages/common/npm_package/package.json'))); | 
					
						
							| 
									
										
										
										
											2018-02-13 11:26:06 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-13 11:00:53 -07:00
										 |  |  | describe('@angular/common ng_package', () => { | 
					
						
							| 
									
										
										
										
											2018-04-03 22:06:32 +02:00
										 |  |  |   describe('should have the locales files', () => { | 
					
						
							| 
									
										
										
										
											2018-04-03 17:21:42 +02:00
										 |  |  |     it('/locales', () => { | 
					
						
							| 
									
										
										
										
											2018-04-03 22:06:32 +02:00
										 |  |  |       const files = shx.ls('locales').stdout.split('\n'); | 
					
						
							| 
									
										
										
										
											2018-04-03 17:21:42 +02:00
										 |  |  |       expect(files.some(n => n.endsWith('.d.ts'))).toBe(true, `.d.ts files don't exist`); | 
					
						
							|  |  |  |       expect(files.some(n => n.endsWith('.js'))).toBe(true, `.js files don't exist`); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     it('/locales/extra', () => { | 
					
						
							| 
									
										
										
										
											2018-04-03 22:06:32 +02:00
										 |  |  |       const files = shx.ls('locales/extra').stdout.split('\n'); | 
					
						
							| 
									
										
										
										
											2018-04-03 17:21:42 +02:00
										 |  |  |       expect(files.some(n => n.endsWith('.d.ts'))).toBe(true, `.d.ts files don't exist`); | 
					
						
							|  |  |  |       expect(files.some(n => n.endsWith('.js'))).toBe(true, `.js files don't exist`); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-04-09 07:17:29 -07:00
										 |  |  |     // regression test for https://github.com/angular/angular/issues/23217
 | 
					
						
							|  |  |  |     // Note, we don't have an e2e test that covers this
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |     it('doesn\'t pass require in a way that breaks webpack static analysis', () => { | 
					
						
							|  |  |  |       expect(shx.cat('locales/fr.js')).not.toContain('factory(require, exports)'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-04-03 17:21:42 +02:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-13 11:26:06 -08:00
										 |  |  |   it('should have right bundle files', () => { | 
					
						
							|  |  |  |     expect(shx.ls('-R', 'bundles').stdout.split('\n').filter(n => !!n).sort()).toEqual([ | 
					
						
							|  |  |  |       'common-http-testing.umd.js', | 
					
						
							|  |  |  |       'common-http-testing.umd.js.map', | 
					
						
							|  |  |  |       'common-http-testing.umd.min.js', | 
					
						
							|  |  |  |       'common-http-testing.umd.min.js.map', | 
					
						
							|  |  |  |       'common-http.umd.js', | 
					
						
							|  |  |  |       'common-http.umd.js.map', | 
					
						
							|  |  |  |       'common-http.umd.min.js', | 
					
						
							|  |  |  |       'common-http.umd.min.js.map', | 
					
						
							|  |  |  |       'common-testing.umd.js', | 
					
						
							|  |  |  |       'common-testing.umd.js.map', | 
					
						
							|  |  |  |       'common-testing.umd.min.js', | 
					
						
							|  |  |  |       'common-testing.umd.min.js.map', | 
					
						
							| 
									
										
										
										
											2019-04-25 09:36:49 -05:00
										 |  |  |       'common-upgrade.umd.js', | 
					
						
							|  |  |  |       'common-upgrade.umd.js.map', | 
					
						
							|  |  |  |       'common-upgrade.umd.min.js', | 
					
						
							|  |  |  |       'common-upgrade.umd.min.js.map', | 
					
						
							| 
									
										
										
										
											2018-02-13 11:26:06 -08:00
										 |  |  |       'common.umd.js', | 
					
						
							|  |  |  |       'common.umd.js.map', | 
					
						
							|  |  |  |       'common.umd.min.js', | 
					
						
							|  |  |  |       'common.umd.min.js.map', | 
					
						
							|  |  |  |     ]); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-03-20 09:58:05 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 16:40:21 -07:00
										 |  |  |   it('should reference core using global symbol in umd', () => { | 
					
						
							|  |  |  |     expect(shx.cat('bundles/common.umd.js')).toContain('global.ng.core'); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-03-29 16:24:59 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-20 09:58:05 -07:00
										 |  |  |   it('should have right fesm files', () => { | 
					
						
							| 
									
										
										
										
											2018-02-13 11:26:06 -08:00
										 |  |  |     const expected = [ | 
					
						
							|  |  |  |       'common.js', | 
					
						
							|  |  |  |       'common.js.map', | 
					
						
							|  |  |  |       'http', | 
					
						
							|  |  |  |       'http.js', | 
					
						
							|  |  |  |       'http.js.map', | 
					
						
							|  |  |  |       'http/testing.js', | 
					
						
							|  |  |  |       'http/testing.js.map', | 
					
						
							|  |  |  |       'testing.js', | 
					
						
							|  |  |  |       'testing.js.map', | 
					
						
							| 
									
										
										
										
											2019-04-25 09:36:49 -05:00
										 |  |  |       'upgrade.js', | 
					
						
							|  |  |  |       'upgrade.js.map', | 
					
						
							| 
									
										
										
										
											2018-02-13 11:26:06 -08:00
										 |  |  |     ]; | 
					
						
							| 
									
										
										
										
											2018-03-20 09:58:05 -07:00
										 |  |  |     expect(shx.ls('-R', 'fesm2015').stdout.split('\n').filter(n => !!n).sort()).toEqual(expected); | 
					
						
							| 
									
										
										
										
											2018-02-13 11:26:06 -08:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-04-05 08:13:20 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-27 19:47:02 -08:00
										 |  |  |   it('should have the correct source map paths', () => { | 
					
						
							|  |  |  |     expect(shx.grep('sourceMappingURL', 'fesm2015/common.js')) | 
					
						
							|  |  |  |         .toMatch('//# sourceMappingURL=common.js.map'); | 
					
						
							|  |  |  |     expect(shx.grep('sourceMappingURL', 'fesm2015/http.js')) | 
					
						
							|  |  |  |         .toMatch('//# sourceMappingURL=http.js.map'); | 
					
						
							|  |  |  |     expect(shx.grep('sourceMappingURL', 'fesm2015/http/testing.js')) | 
					
						
							|  |  |  |         .toMatch('//# sourceMappingURL=testing.js.map'); | 
					
						
							|  |  |  |     expect(shx.grep('sourceMappingURL', 'fesm2015/testing.js')) | 
					
						
							|  |  |  |         .toMatch('//# sourceMappingURL=testing.js.map'); | 
					
						
							| 
									
										
										
										
											2019-04-25 09:36:49 -05:00
										 |  |  |     expect(shx.grep('sourceMappingURL', 'fesm2015/upgrade.js')) | 
					
						
							|  |  |  |         .toMatch('//# sourceMappingURL=upgrade.js.map'); | 
					
						
							| 
									
										
										
										
											2018-11-27 19:47:02 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-25 23:16:56 +01:00
										 |  |  |   describe('secondary entry-point', () => { | 
					
						
							|  |  |  |     obsoleteInIvy( | 
					
						
							|  |  |  |         `now that we don't need metadata files, we don't need these redirects to help resolve paths to them`) | 
					
						
							|  |  |  |         .it('should contain a root type definition re-export', () => { | 
					
						
							|  |  |  |           expect(shx.cat('./testing.d.ts')).toContain(`export * from './testing/testing';`); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-27 19:47:02 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-13 11:00:53 -07:00
										 |  |  |   describe('should have module resolution properties in the package.json file for', () => { | 
					
						
							|  |  |  |     // https://github.com/angular/common-builds/blob/master/package.json
 | 
					
						
							|  |  |  |     it('/', () => { | 
					
						
							|  |  |  |       const actual = JSON.parse(fs.readFileSync('package.json', {encoding: 'utf-8'})); | 
					
						
							|  |  |  |       expect(actual['main']).toEqual('./bundles/common.umd.js'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     // https://github.com/angular/common-builds/blob/master/http/package.json
 | 
					
						
							|  |  |  |     it('/http', () => { | 
					
						
							|  |  |  |       const actual = JSON.parse(fs.readFileSync('http/package.json', {encoding: 'utf-8'})); | 
					
						
							|  |  |  |       expect(actual['main']).toEqual('../bundles/common-http.umd.js'); | 
					
						
							| 
									
										
										
										
											2018-03-20 09:58:05 -07:00
										 |  |  |       expect(actual['es2015']).toEqual('../fesm2015/http.js'); | 
					
						
							| 
									
										
										
										
											2020-05-05 21:35:44 -07:00
										 |  |  |       expect(actual['module']).toEqual('../fesm2015/http.js'); | 
					
						
							| 
									
										
										
										
											2018-03-13 11:00:53 -07:00
										 |  |  |       expect(actual['typings']).toEqual('./http.d.ts'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     // https://github.com/angular/common-builds/blob/master/testing/package.json
 | 
					
						
							|  |  |  |     it('/testing', () => { | 
					
						
							|  |  |  |       const actual = JSON.parse(fs.readFileSync('testing/package.json', {encoding: 'utf-8'})); | 
					
						
							|  |  |  |       expect(actual['main']).toEqual('../bundles/common-testing.umd.js'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     // https://github.com/angular/common-builds/blob/master/http/testing/package.json
 | 
					
						
							|  |  |  |     it('/http/testing', () => { | 
					
						
							|  |  |  |       const actual = JSON.parse(fs.readFileSync('http/testing/package.json', {encoding: 'utf-8'})); | 
					
						
							|  |  |  |       expect(actual['main']).toEqual('../../bundles/common-http-testing.umd.js'); | 
					
						
							| 
									
										
										
										
											2018-03-20 09:58:05 -07:00
										 |  |  |       expect(actual['es2015']).toEqual('../../fesm2015/http/testing.js'); | 
					
						
							| 
									
										
										
										
											2020-05-05 21:35:44 -07:00
										 |  |  |       expect(actual['module']).toEqual('../../fesm2015/http/testing.js'); | 
					
						
							| 
									
										
										
										
											2018-03-13 11:00:53 -07:00
										 |  |  |       expect(actual['typings']).toEqual('./testing.d.ts'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-04-25 09:36:49 -05:00
										 |  |  |     // https://github.com/angular/common-builds/blob/master/upgrade/package.json
 | 
					
						
							|  |  |  |     it('/upgrade', () => { | 
					
						
							|  |  |  |       const actual = JSON.parse(fs.readFileSync('upgrade/package.json', {encoding: 'utf-8'})); | 
					
						
							|  |  |  |       expect(actual['main']).toEqual('../bundles/common-upgrade.umd.js'); | 
					
						
							|  |  |  |       expect(actual['es2015']).toEqual('../fesm2015/upgrade.js'); | 
					
						
							| 
									
										
										
										
											2020-05-05 21:35:44 -07:00
										 |  |  |       expect(actual['module']).toEqual('../fesm2015/upgrade.js'); | 
					
						
							| 
									
										
										
										
											2019-04-25 09:36:49 -05:00
										 |  |  |       expect(actual['typings']).toEqual('./upgrade.d.ts'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-03-13 11:00:53 -07:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-02-13 11:26:06 -08:00
										 |  |  | }); |