Skip to content

Commit 1b9ca66

Browse files
authored
test(legacy): add a test to checks all inline snippets are valid JS (#15098)
1 parent 1c605ff commit 1b9ca66

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

packages/plugin-legacy/src/__tests__/snippets.spec.ts

+30-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
import { expect, test } from 'vitest'
1+
import { describe, expect, test } from 'vitest'
22
import type { ecmaVersion } from 'acorn'
33
import { parse } from 'acorn'
4-
import { detectModernBrowserDetector } from '../snippets'
4+
import {
5+
detectModernBrowserCode,
6+
detectModernBrowserDetector,
7+
dynamicFallbackInlineCode,
8+
safari10NoModuleFix,
9+
systemJSInlineCode,
10+
} from '../snippets'
511

612
const shouldFailVersions: ecmaVersion[] = []
713
for (let v = 2015; v <= 2019; v++) {
814
shouldFailVersions.push(v as ecmaVersion)
915
}
1016

11-
const shouldPassVersions: acorn.ecmaVersion[] = []
12-
for (let v = 2020; v <= 2022; v++) {
17+
const shouldPassVersions: ecmaVersion[] = []
18+
for (let v = 2020; v <= 2024; v++) {
1319
shouldPassVersions.push(v as ecmaVersion)
1420
}
1521

@@ -34,3 +40,23 @@ for (const version of shouldPassVersions) {
3440
}).not.toThrow()
3541
})
3642
}
43+
44+
describe('snippets are valid', () => {
45+
const codes = {
46+
safari10NoModuleFix,
47+
systemJSInlineCode,
48+
detectModernBrowserCode,
49+
dynamicFallbackInlineCode,
50+
}
51+
52+
for (const [name, value] of Object.entries(codes)) {
53+
test(`${name} is valid JS`, () => {
54+
expect(() => {
55+
parse(value, {
56+
ecmaVersion: 'latest',
57+
sourceType: 'module',
58+
})
59+
}).not.toThrow()
60+
})
61+
}
62+
})

0 commit comments

Comments
 (0)