Skip to content

Commit 0d6640d

Browse files
committed
✅ Add tests for validating we support all core-js modules
Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent 1796661 commit 0d6640d

File tree

3 files changed

+58
-16
lines changed

3 files changed

+58
-16
lines changed

package-lock.json

Lines changed: 27 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"devDependencies": {
5454
"@rollup/plugin-typescript": "^11.1.0",
5555
"@types/jest": "^29.5.0",
56+
"core-js": "^3.30.0",
5657
"jest": "^29.5.0",
5758
"prettier": "^2.8.6",
5859
"ts-jest": "^29.0.5",

tests/analyze.test.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
*/
55

66
import { parse } from 'acorn'
7-
import {filterModules} from '../src/analyze'
7+
import {detectableModules, filterModules} from '../src/analyze'
8+
import compat from 'core-js-compat';
89

910
const parseModule = (code: string) => parse(code, { ecmaVersion: 'latest' })
1011
test('keep all used', () => {
@@ -45,8 +46,36 @@ test('Can detect errors with cause', () => {
4546
expect(filterModules(['es.error.cause'], ast0)).toEqual([])
4647
expect(filterModules(['es.error.cause'], ast)).toEqual(['es.error.cause'])
4748
})
49+
50+
test.failing('Can detect all ES modules', () => {
51+
const ast = parseModule('')
52+
expect(
53+
filterModules(compat.modules.filter(v => v.startsWith('es.')), ast)
54+
).toBe([
55+
// can not detect this
56+
'es.error.to-string'
57+
])
58+
})
59+
4860
// X-Fail as not implemented
4961
test.failing('Can detect all esnext modules', () => {
5062
const ast = parseModule('')
5163
expect(filterModules(compat.modules.filter(v => v.startsWith('esnext.')), ast)).toBe([])
64+
})
65+
66+
// X-Fail as not implemented
67+
test.failing('Can detect all web modules', () => {
68+
const ast = parseModule('')
69+
expect(filterModules(compat.modules.filter(v => v.startsWith('web.')), ast)).toBe([])
70+
})
71+
72+
test('All modules exist', async () => {
73+
let failed = false
74+
75+
const all = detectableModules.map(mod => import(`core-js/modules/${mod[0]}.js`))
76+
try {
77+
await Promise.all(all)
78+
} catch(e) {
79+
expect(e).toBe('')
80+
}
5281
})

0 commit comments

Comments
 (0)