11import {
22 writeMultipleFiles ,
33 expectFileToMatch ,
4- appendToFile
4+ appendToFile ,
5+ expectFileMatchToExist
56} from '../../utils/fs' ;
67import { ng } from '../../utils/process' ;
78import { updateJsonFile } from '../../utils/project' ;
89import { oneLineTrim } from 'common-tags' ;
910
1011export default function ( ) {
1112 return writeMultipleFiles ( {
12- 'src/string-script.js' : 'console.log(\'string-script\');' ,
13+ 'src/string-script.js' : 'console.log(\'string-script\'); var number = 1+1; ' ,
1314 'src/input-script.js' : 'console.log(\'input-script\');' ,
1415 'src/lazy-script.js' : 'console.log(\'lazy-script\');' ,
1516 'src/pre-rename-script.js' : 'console.log(\'pre-rename-script\');' ,
16- 'src/pre-rename-lazy-script.js' : 'console.log(\'pre-rename-lazy-script\');' ,
17- 'src/common-entry-script.js' : 'console.log(\'common-entry-script\');' ,
18- 'src/common-entry-style.css' : '.common-entry-style { color: red }' ,
17+ 'src/pre-rename-lazy-script.js' : 'console.log(\'pre-rename-lazy-script\');'
1918 } )
2019 . then ( ( ) => appendToFile ( 'src/main.ts' , 'import \'./string-script.js\';' ) )
2120 . then ( ( ) => updateJsonFile ( '.angular-cli.json' , configJson => {
@@ -25,10 +24,8 @@ export default function () {
2524 { input : 'input-script.js' } ,
2625 { input : 'lazy-script.js' , lazy : true } ,
2726 { input : 'pre-rename-script.js' , output : 'renamed-script' } ,
28- { input : 'pre-rename-lazy-script.js' , output : 'renamed-lazy-script' , lazy : true } ,
29- { input : 'common-entry-script.js' , output : 'common-entry' }
27+ { input : 'pre-rename-lazy-script.js' , output : 'renamed-lazy-script' , lazy : true }
3028 ] ;
31- app [ 'styles' ] = [ { input : 'common-entry-style.css' , output : 'common-entry' } ] ;
3229 } ) )
3330 . then ( ( ) => ng ( 'build' , '--extract-css' ) )
3431 // files were created successfully
@@ -37,21 +34,24 @@ export default function () {
3734 . then ( ( ) => expectFileToMatch ( 'dist/lazy-script.bundle.js' , 'lazy-script' ) )
3835 . then ( ( ) => expectFileToMatch ( 'dist/renamed-script.bundle.js' , 'pre-rename-script' ) )
3936 . then ( ( ) => expectFileToMatch ( 'dist/renamed-lazy-script.bundle.js' , 'pre-rename-lazy-script' ) )
40- . then ( ( ) => expectFileToMatch ( 'dist/common-entry.bundle.js' , 'common-entry-script' ) )
41- . then ( ( ) => expectFileToMatch ( 'dist/common-entry.bundle.css' , '.common-entry-style' ) )
4237 // index.html lists the right bundles
43- . then ( ( ) => expectFileToMatch ( 'dist/index.html' , oneLineTrim `
44- <link href="common-entry.bundle.css" rel="stylesheet"/>
45- ` ) )
4638 . then ( ( ) => expectFileToMatch ( 'dist/index.html' , oneLineTrim `
4739 <script type="text/javascript" src="inline.bundle.js"></script>
4840 <script type="text/javascript" src="polyfills.bundle.js"></script>
4941 <script type="text/javascript" src="scripts.bundle.js"></script>
5042 <script type="text/javascript" src="renamed-script.bundle.js"></script>
51- <script type="text/javascript" src="common-entry.bundle.js"></script>
5243 <script type="text/javascript" src="vendor.bundle.js"></script>
5344 <script type="text/javascript" src="main.bundle.js"></script>
5445 ` ) )
55- // ensure scripts aren't using script-loader when imported from the app
56- . then ( ( ) => expectFileToMatch ( 'dist/main.bundle.js' , 'console.log(\'string-script\');' ) ) ;
46+ // Ensure scripts can be separately imported from the app.
47+ . then ( ( ) => expectFileToMatch ( 'dist/main.bundle.js' , 'console.log(\'string-script\');' ) )
48+ // Verify uglify, sourcemaps and hashes. Lazy scripts should not get hashes.
49+ . then ( ( ) => ng ( 'build' , '--prod' , '--sourcemap' ) )
50+ . then ( ( ) => expectFileMatchToExist ( 'dist' , / s c r i p t s \. [ 0 - 9 a - f ] { 20 } \. b u n d l e \. j s / ) )
51+ . then ( fileName => expectFileToMatch ( `dist/${ fileName } ` , 'var number=2;' ) )
52+ . then ( ( ) => expectFileMatchToExist ( 'dist' , / s c r i p t s \. [ 0 - 9 a - f ] { 20 } \. b u n d l e \. j s \. m a p / ) )
53+ . then ( ( ) => expectFileMatchToExist ( 'dist' , / r e n a m e d - s c r i p t \. [ 0 - 9 a - f ] { 20 } \. b u n d l e \. j s / ) )
54+ . then ( ( ) => expectFileMatchToExist ( 'dist' , / r e n a m e d - s c r i p t \. [ 0 - 9 a - f ] { 20 } \. b u n d l e \. j s .m a p / ) )
55+ . then ( ( ) => expectFileToMatch ( 'dist/lazy-script.bundle.js' , 'lazy-script' ) )
56+ . then ( ( ) => expectFileToMatch ( 'dist/renamed-lazy-script.bundle.js' , 'pre-rename-lazy-script' ) ) ;
5757}
0 commit comments