Skip to content

Commit

Permalink
test(legacy): add a test to checks all inline snippets are valid JS (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Nov 22, 2023
1 parent 1c605ff commit 1b9ca66
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions packages/plugin-legacy/src/__tests__/snippets.spec.ts
Original file line number Diff line number Diff line change
@@ -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)
}

Expand All @@ -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()
})
}
})

0 comments on commit 1b9ca66

Please sign in to comment.