mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-11 22:06:17 -08:00
build(types): ENG-04 add strict projects and legacy compiler checks
This commit is contained in:
1 parent
09902b8b8c
commit
771482426f
22 files changed
+346
-49
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import test from 'node:test'
|
||||
import ts from 'typescript'
|
||||
import compat from 'typescript-compat'
|
||||
import { checkConsumer, checkProject } from '../../scripts/typecheck.mjs'
|
||||
import { refactorDir } from './releases.mjs'
|
||||
|
||||
test('Current and compatibility compilers reject invalid old public calls and unused error assertions', () => {
|
||||
const original = fs.readFileSync(path.join(refactorDir, '../test/types/public.ts'), 'utf8')
|
||||
for (const compiler of [ts, compat]) {
|
||||
assert.deepEqual(checkConsumer(compiler, 'node10-commonjs'), [])
|
||||
const invalid = "import Artplayer from 'artplayer'; new Artplayer({ container: '#player', url: 42 });"
|
||||
assert(checkConsumer(compiler, 'node10-commonjs', invalid).some(d => d.code === 2322))
|
||||
const unused = original.replace('url: 42', "url: 'valid.mp4'")
|
||||
assert(checkConsumer(compiler, 'node10-commonjs', unused).some(d => d.code === 2578))
|
||||
}
|
||||
})
|
||||
|
||||
test('Browser implementation configuration catches source errors without emitting JavaScript', () => {
|
||||
const parent = path.join(refactorDir, '.cache')
|
||||
fs.mkdirSync(parent, { recursive: true })
|
||||
const directory = fs.mkdtempSync(path.join(parent, 'types-check-'))
|
||||
try {
|
||||
const config = path.join(directory, 'tsconfig.json')
|
||||
fs.writeFileSync(config, JSON.stringify({ extends: path.join(refactorDir, '../tsconfig.base.json'), include: ['source.ts'] }))
|
||||
fs.writeFileSync(path.join(directory, 'source.ts'), 'export const title: string = 42;\n')
|
||||
assert.deepEqual(checkProject(config).diagnostics.map(d => d.code), [2322])
|
||||
assert(!fs.existsSync(path.join(directory, 'source.js')))
|
||||
}
|
||||
finally {
|
||||
const relative = path.relative(parent, directory)
|
||||
assert(relative.startsWith('types-check-') && !relative.includes(path.sep))
|
||||
fs.rmSync(directory, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user