1
1
import {
2
2
writeMultipleFiles ,
3
3
expectFileToMatch ,
4
- appendToFile
4
+ appendToFile ,
5
+ expectFileMatchToExist
5
6
} from '../../utils/fs' ;
6
7
import { ng } from '../../utils/process' ;
7
8
import { updateJsonFile } from '../../utils/project' ;
8
9
import { oneLineTrim } from 'common-tags' ;
9
10
10
11
export default function ( ) {
11
12
return writeMultipleFiles ( {
12
- 'src/string-script.js' : 'console.log(\'string-script\');' ,
13
+ 'src/string-script.js' : 'console.log(\'string-script\'); var number = 1+1; ' ,
13
14
'src/input-script.js' : 'console.log(\'input-script\');' ,
14
15
'src/lazy-script.js' : 'console.log(\'lazy-script\');' ,
15
16
'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\');'
19
18
} )
20
19
. then ( ( ) => appendToFile ( 'src/main.ts' , 'import \'./string-script.js\';' ) )
21
20
. then ( ( ) => updateJsonFile ( '.angular-cli.json' , configJson => {
@@ -25,10 +24,8 @@ export default function () {
25
24
{ input : 'input-script.js' } ,
26
25
{ input : 'lazy-script.js' , lazy : true } ,
27
26
{ 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 }
30
28
] ;
31
- app [ 'styles' ] = [ { input : 'common-entry-style.css' , output : 'common-entry' } ] ;
32
29
} ) )
33
30
. then ( ( ) => ng ( 'build' , '--extract-css' ) )
34
31
// files were created successfully
@@ -37,21 +34,24 @@ export default function () {
37
34
. then ( ( ) => expectFileToMatch ( 'dist/lazy-script.bundle.js' , 'lazy-script' ) )
38
35
. then ( ( ) => expectFileToMatch ( 'dist/renamed-script.bundle.js' , 'pre-rename-script' ) )
39
36
. 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' ) )
42
37
// index.html lists the right bundles
43
- . then ( ( ) => expectFileToMatch ( 'dist/index.html' , oneLineTrim `
44
- <link href="common-entry.bundle.css" rel="stylesheet"/>
45
- ` ) )
46
38
. then ( ( ) => expectFileToMatch ( 'dist/index.html' , oneLineTrim `
47
39
<script type="text/javascript" src="inline.bundle.js"></script>
48
40
<script type="text/javascript" src="polyfills.bundle.js"></script>
49
41
<script type="text/javascript" src="scripts.bundle.js"></script>
50
42
<script type="text/javascript" src="renamed-script.bundle.js"></script>
51
- <script type="text/javascript" src="common-entry.bundle.js"></script>
52
43
<script type="text/javascript" src="vendor.bundle.js"></script>
53
44
<script type="text/javascript" src="main.bundle.js"></script>
54
45
` ) )
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' ) ) ;
57
57
}
0 commit comments