@@ -7,6 +7,11 @@ const defaultOptions = {
77 filename : 'test-entry-file.js'
88}
99
10+ const genCoreJSImportRegExp = mod => {
11+ // expected to include a `node_modules` in the import path because we use absolute path for core-js
12+ return new RegExp ( `import "${ [ '.*node_modules' , 'core-js' , 'modules' , mod ] . join ( `[\\${ path . sep } ]+` ) } ` )
13+ }
14+
1015beforeEach ( ( ) => {
1116 process . env . VUE_CLI_ENTRY_FILES = JSON . stringify ( [ path . join ( process . cwd ( ) , 'test-entry-file.js' ) ] )
1217} )
@@ -22,9 +27,9 @@ test('polyfill detection', () => {
2227 filename : 'test-entry-file.js'
2328 } )
2429 // default includes
25- expect ( code ) . not . toMatch ( `import "core-js/modules/ es6.promise"` )
30+ expect ( code ) . not . toMatch ( genCoreJSImportRegExp ( ' es6.promise' ) )
2631 // usage-based detection
27- expect ( code ) . not . toMatch ( `import "core-js/modules/ es6.map"` )
32+ expect ( code ) . not . toMatch ( genCoreJSImportRegExp ( ' es6.map' ) )
2833
2934 ; ( { code } = babel . transformSync ( `
3035 const a = new Map()
@@ -36,9 +41,9 @@ test('polyfill detection', () => {
3641 filename : 'test-entry-file.js'
3742 } ) )
3843 // default includes
39- expect ( code ) . toMatch ( `import "core-js/modules/ es6.promise"` )
44+ expect ( code ) . toMatch ( genCoreJSImportRegExp ( ' es6.promise' ) )
4045 // promise polyfill alone doesn't work in IE, needs this as well. fix: #1642
41- expect ( code ) . toMatch ( `import "core-js/modules/ es6.array.iterator"` )
46+ expect ( code ) . toMatch ( genCoreJSImportRegExp ( ' es6.array.iterator' ) )
4247 // usage-based detection
4348 expect ( code ) . toMatch ( / i m p o r t _ M a p f r o m " .* r u n t i m e - c o r e j s 2 \/ c o r e - j s \/ m a p " / )
4449} )
@@ -56,7 +61,7 @@ test('modern mode always skips polyfills', () => {
5661 filename : 'test-entry-file.js'
5762 } )
5863 // default includes
59- expect ( code ) . not . toMatch ( `import "core-js/modules/ es6.promise"` )
64+ expect ( code ) . not . toMatch ( genCoreJSImportRegExp ( ' es6.promise' ) )
6065 // usage-based detection
6166 expect ( code ) . not . toMatch ( / i m p o r t _ M a p f r o m " .* r u n t i m e - c o r e j s 2 \/ c o r e - j s \/ m a p " / )
6267
@@ -71,7 +76,7 @@ test('modern mode always skips polyfills', () => {
7176 filename : 'test-entry-file.js'
7277 } ) )
7378 // default includes
74- expect ( code ) . not . toMatch ( `import "core-js/modules/ es6.promise"` )
79+ expect ( code ) . not . toMatch ( genCoreJSImportRegExp ( ' es6.promise' ) )
7580 // usage-based detection
7681 expect ( code ) . not . toMatch ( / i m p o r t _ M a p f r o m " .* r u n t i m e - c o r e j s 2 \/ c o r e - j s \/ m a p " / )
7782 delete process . env . VUE_CLI_MODERN_BUILD
@@ -98,7 +103,7 @@ test('async/await', () => {
98103 }
99104 hello()
100105 ` . trim ( ) , defaultOptions )
101- expect ( code ) . toMatch ( `import "core-js/modules/ es6.promise"` )
106+ expect ( code ) . toMatch ( genCoreJSImportRegExp ( ' es6.promise' ) )
102107 // should use regenerator runtime
103108 expect ( code ) . toMatch ( `import "regenerator-runtime/runtime"` )
104109 // should use required helper instead of inline
0 commit comments