@@ -12,7 +12,7 @@ let server, browser
12
12
test ( 'modern mode' , async ( ) => {
13
13
const project = await create ( 'modern-mode' , defaultPreset )
14
14
15
- const { stdout } = await project . run ( 'vue-cli-service build --modern ' )
15
+ const { stdout } = await project . run ( 'vue-cli-service build' )
16
16
expect ( stdout ) . toMatch ( 'Build complete.' )
17
17
18
18
// assert correct bundle files
@@ -43,13 +43,9 @@ test('modern mode', async () => {
43
43
expect ( index ) . toMatch ( / < s c r i p t d e f e r = " d e f e r " s r c = " \/ j s \/ c h u n k - v e n d o r s - l e g a c y \. \w { 8 } \. j s " n o m o d u l e > / )
44
44
expect ( index ) . toMatch ( / < s c r i p t d e f e r = " d e f e r " s r c = " \/ j s \/ a p p - l e g a c y \. \w { 8 } \. j s " n o m o d u l e > / )
45
45
46
- // should inject Safari 10 nomodule fix
47
- const { safariFix } = require ( '../lib/webpack/ModernModePlugin' )
48
- expect ( index ) . toMatch ( `<script>${ safariFix } </script>` )
49
-
50
46
// Test crossorigin="use-credentials"
51
47
await project . write ( 'vue.config.js' , `module.exports = { crossorigin: 'use-credentials' }` )
52
- const { stdout : stdout2 } = await project . run ( 'vue-cli-service build --modern ' )
48
+ const { stdout : stdout2 } = await project . run ( 'vue-cli-service build' )
53
49
expect ( stdout2 ) . toMatch ( 'Build complete.' )
54
50
const index2 = await project . read ( 'dist/index.html' )
55
51
// should use <script type="module" crossorigin="use-credentials"> for modern bundle
@@ -82,21 +78,58 @@ test('modern mode', async () => {
82
78
expect ( await getH1Text ( ) ) . toMatch ( 'Welcome to Your Vue.js App' )
83
79
} )
84
80
85
- test ( 'no-unsafe-inline' , async ( ) => {
86
- const project = await create ( 'no-unsafe-inline' , defaultPreset )
81
+ test ( 'should not inject the nomodule-fix script if Safari 10 is not targeted' , async ( ) => {
82
+ // the default targets already excludes safari 10
83
+ const project = await create ( 'skip-safari-fix' , defaultPreset )
87
84
88
- const { stdout } = await project . run ( 'vue-cli-service build --modern --no-unsafe-inline ' )
85
+ const { stdout } = await project . run ( 'vue-cli-service build' )
89
86
expect ( stdout ) . toMatch ( 'Build complete.' )
90
87
88
+ // should contain no inline scripts in the output html
89
+ const index = await project . read ( 'dist/index.html' )
90
+ expect ( index ) . not . toMatch ( / [ ^ > ] \s * < \/ s c r i p t > / )
91
+ // should not contain the safari-nomodule-fix bundle, either
92
+ const files = await fs . readdir ( path . join ( project . dir , 'dist/js' ) )
93
+ expect ( files . some ( f => / ^ s a f a r i - n o m o d u l e - f i x \. j s $ / . test ( f ) ) ) . toBe ( false )
94
+ } )
95
+
96
+ test ( 'should inject nomodule-fix script when Safari 10 support is required' , async ( ) => {
97
+ const project = await create ( 'safari-nomodule-fix' , defaultPreset )
98
+
99
+ const pkg = JSON . parse ( await project . read ( 'package.json' ) )
100
+ pkg . browserslist . push ( 'safari > 10' )
101
+ await project . write ( 'package.json' , JSON . stringify ( pkg , null , 2 ) )
102
+
103
+ let { stdout } = await project . run ( 'vue-cli-service build' )
104
+ let index = await project . read ( 'dist/index.html' )
105
+ // should inject Safari 10 nomodule fix as an inline script
106
+ const { safariFix } = require ( '../lib/webpack/ModernModePlugin' )
107
+ expect ( index ) . toMatch ( `<script>${ safariFix } </script>` )
108
+
109
+ // `--no-unsafe-inline` option
110
+ stdout = ( await project . run ( 'vue-cli-service build --no-unsafe-inline' ) ) . stdout
111
+ expect ( stdout ) . toMatch ( 'Build complete.' )
91
112
// should output a separate safari-nomodule-fix bundle
92
113
const files = await fs . readdir ( path . join ( project . dir , 'dist/js' ) )
93
114
expect ( files . some ( f => / ^ s a f a r i - n o m o d u l e - f i x \. j s $ / . test ( f ) ) ) . toBe ( true )
94
-
95
115
// should contain no inline scripts in the output html
96
- const index = await project . read ( 'dist/index.html' )
116
+ index = await project . read ( 'dist/index.html' )
97
117
expect ( index ) . not . toMatch ( / [ ^ > ] \s * < \/ s c r i p t > / )
98
118
} )
99
119
120
+ test ( '--no-module' , async ( ) => {
121
+ const project = await create ( 'no-module' , defaultPreset )
122
+
123
+ const { stdout } = await project . run ( 'vue-cli-service build --no-module' )
124
+ expect ( stdout ) . toMatch ( 'Build complete.' )
125
+
126
+ const index = await project . read ( 'dist/index.html' )
127
+ expect ( index ) . not . toMatch ( 'type="module"' )
128
+
129
+ const files = await fs . readdir ( path . join ( project . dir , 'dist/js' ) )
130
+ expect ( files . some ( f => / - l e g a c y .j s / . test ( f ) ) ) . toBe ( false )
131
+ } )
132
+
100
133
afterAll ( async ( ) => {
101
134
if ( browser ) {
102
135
await browser . close ( )
0 commit comments