@@ -12,7 +12,7 @@ let server, browser
1212test ( 'modern mode' , async ( ) => {
1313 const project = await create ( 'modern-mode' , defaultPreset )
1414
15- const { stdout } = await project . run ( 'vue-cli-service build --modern ' )
15+ const { stdout } = await project . run ( 'vue-cli-service build' )
1616 expect ( stdout ) . toMatch ( 'Build complete.' )
1717
1818 // assert correct bundle files
@@ -43,13 +43,9 @@ test('modern mode', async () => {
4343 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 > / )
4444 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 > / )
4545
46- // should inject Safari 10 nomodule fix
47- const { safariFix } = require ( '../lib/webpack/ModernModePlugin' )
48- expect ( index ) . toMatch ( `<script>${ safariFix } </script>` )
49-
5046 // Test crossorigin="use-credentials"
5147 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' )
5349 expect ( stdout2 ) . toMatch ( 'Build complete.' )
5450 const index2 = await project . read ( 'dist/index.html' )
5551 // should use <script type="module" crossorigin="use-credentials"> for modern bundle
@@ -82,21 +78,58 @@ test('modern mode', async () => {
8278 expect ( await getH1Text ( ) ) . toMatch ( 'Welcome to Your Vue.js App' )
8379} )
8480
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 )
8784
88- const { stdout } = await project . run ( 'vue-cli-service build --modern --no-unsafe-inline ' )
85+ const { stdout } = await project . run ( 'vue-cli-service build' )
8986 expect ( stdout ) . toMatch ( 'Build complete.' )
9087
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.' )
91112 // should output a separate safari-nomodule-fix bundle
92113 const files = await fs . readdir ( path . join ( project . dir , 'dist/js' ) )
93114 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-
95115 // 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' )
97117 expect ( index ) . not . toMatch ( / [ ^ > ] \s * < \/ s c r i p t > / )
98118} )
99119
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+
100133afterAll ( async ( ) => {
101134 if ( browser ) {
102135 await browser . close ( )
0 commit comments