-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
polyfills.js
59 lines (49 loc) · 1.6 KB
/
polyfills.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const path = require(`path`)
const { TraceMap } = require(`@jridgewell/trace-mapping`)
const execa = require(`execa`)
const fs = require(`fs-extra`)
jest.setTimeout(60000)
describe(`polyfills`, () => {
const packageRoot = path.resolve(__dirname, `../../`)
const tmpDir = `.tmp`
beforeAll(async () => {
const pkg = require(`../../package.json`)
const buildScript = pkg.scripts[`build:polyfills`].replace(
` --no-sourcemap`,
``
)
await execa(
`yarn`,
[
...buildScript.split(` `),
`--no-compress`,
`-o`,
path.join(tmpDir, `polyfills.js`),
],
{ cwd: packageRoot }
)
})
afterAll(() => fs.remove(path.join(packageRoot, tmpDir)))
it(`has the correct polyfills`, () => {
const polyfills = require(`../exclude`).LEGACY_POLYFILLS
const polyfillMap = path.join(packageRoot, tmpDir, `polyfills.js.map`)
expect(fs.existsSync(polyfillMap)).toBe(true)
const fileMap = polyfills.map(polyfill => {
if (polyfill === `features/dom-collections`) {
return `core-js/modules/web.dom-collections`
}
return `core-js/modules/${polyfill
.replace(/^(features|modules)\//, `es.`)
.replace(`/`, `.`)}`
})
const polyfillMapSource = fs.readFileSync(polyfillMap, `utf8`)
const tracer = new TraceMap(polyfillMapSource)
const sources = tracer.sources.map(source =>
source.replace(/.*\/node_modules\//, ``)
)
// check if all polyfills are in the bundle
expect(sources).toEqual(
expect.arrayContaining(fileMap.map(file => expect.stringContaining(file)))
)
})
})