mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 22:59:10 +00:00
test(legacy): add a test to checks all inline snippets are valid JS (#15098)
This commit is contained in:
parent
1c605ffe9b
commit
1b9ca66b6d
@ -1,15 +1,21 @@
|
||||
import { expect, test } from 'vitest'
|
||||
import { describe, expect, test } from 'vitest'
|
||||
import type { ecmaVersion } from 'acorn'
|
||||
import { parse } from 'acorn'
|
||||
import { detectModernBrowserDetector } from '../snippets'
|
||||
import {
|
||||
detectModernBrowserCode,
|
||||
detectModernBrowserDetector,
|
||||
dynamicFallbackInlineCode,
|
||||
safari10NoModuleFix,
|
||||
systemJSInlineCode,
|
||||
} from '../snippets'
|
||||
|
||||
const shouldFailVersions: ecmaVersion[] = []
|
||||
for (let v = 2015; v <= 2019; v++) {
|
||||
shouldFailVersions.push(v as ecmaVersion)
|
||||
}
|
||||
|
||||
const shouldPassVersions: acorn.ecmaVersion[] = []
|
||||
for (let v = 2020; v <= 2022; v++) {
|
||||
const shouldPassVersions: ecmaVersion[] = []
|
||||
for (let v = 2020; v <= 2024; v++) {
|
||||
shouldPassVersions.push(v as ecmaVersion)
|
||||
}
|
||||
|
||||
@ -34,3 +40,23 @@ for (const version of shouldPassVersions) {
|
||||
}).not.toThrow()
|
||||
})
|
||||
}
|
||||
|
||||
describe('snippets are valid', () => {
|
||||
const codes = {
|
||||
safari10NoModuleFix,
|
||||
systemJSInlineCode,
|
||||
detectModernBrowserCode,
|
||||
dynamicFallbackInlineCode,
|
||||
}
|
||||
|
||||
for (const [name, value] of Object.entries(codes)) {
|
||||
test(`${name} is valid JS`, () => {
|
||||
expect(() => {
|
||||
parse(value, {
|
||||
ecmaVersion: 'latest',
|
||||
sourceType: 'module',
|
||||
})
|
||||
}).not.toThrow()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user