@@ -7,6 +7,11 @@ const defaultOptions = {
7
7
filename : 'test-entry-file.js'
8
8
}
9
9
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
+
10
15
beforeEach ( ( ) => {
11
16
process . env . VUE_CLI_ENTRY_FILES = JSON . stringify ( [ path . join ( process . cwd ( ) , 'test-entry-file.js' ) ] )
12
17
} )
@@ -22,9 +27,9 @@ test('polyfill detection', () => {
22
27
filename : 'test-entry-file.js'
23
28
} )
24
29
// default includes
25
- expect ( code ) . not . toMatch ( `import "core-js/modules/ es6.promise"` )
30
+ expect ( code ) . not . toMatch ( genCoreJSImportRegExp ( ' es6.promise' ) )
26
31
// usage-based detection
27
- expect ( code ) . not . toMatch ( `import "core-js/modules/ es6.map"` )
32
+ expect ( code ) . not . toMatch ( genCoreJSImportRegExp ( ' es6.map' ) )
28
33
29
34
; ( { code } = babel . transformSync ( `
30
35
const a = new Map()
@@ -36,9 +41,9 @@ test('polyfill detection', () => {
36
41
filename : 'test-entry-file.js'
37
42
} ) )
38
43
// default includes
39
- expect ( code ) . toMatch ( `import "core-js/modules/ es6.promise"` )
44
+ expect ( code ) . toMatch ( genCoreJSImportRegExp ( ' es6.promise' ) )
40
45
// 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' ) )
42
47
// usage-based detection
43
48
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 " / )
44
49
} )
@@ -56,7 +61,7 @@ test('modern mode always skips polyfills', () => {
56
61
filename : 'test-entry-file.js'
57
62
} )
58
63
// default includes
59
- expect ( code ) . not . toMatch ( `import "core-js/modules/ es6.promise"` )
64
+ expect ( code ) . not . toMatch ( genCoreJSImportRegExp ( ' es6.promise' ) )
60
65
// usage-based detection
61
66
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 " / )
62
67
@@ -71,7 +76,7 @@ test('modern mode always skips polyfills', () => {
71
76
filename : 'test-entry-file.js'
72
77
} ) )
73
78
// default includes
74
- expect ( code ) . not . toMatch ( `import "core-js/modules/ es6.promise"` )
79
+ expect ( code ) . not . toMatch ( genCoreJSImportRegExp ( ' es6.promise' ) )
75
80
// usage-based detection
76
81
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 " / )
77
82
delete process . env . VUE_CLI_MODERN_BUILD
@@ -98,7 +103,7 @@ test('async/await', () => {
98
103
}
99
104
hello()
100
105
` . trim ( ) , defaultOptions )
101
- expect ( code ) . toMatch ( `import "core-js/modules/ es6.promise"` )
106
+ expect ( code ) . toMatch ( genCoreJSImportRegExp ( ' es6.promise' ) )
102
107
// should use regenerator runtime
103
108
expect ( code ) . toMatch ( `import "regenerator-runtime/runtime"` )
104
109
// should use required helper instead of inline
0 commit comments