mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 19:06:15 -08:00
58 lines
3.3 KiB
JavaScript
58 lines
3.3 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import { spawnSync } from 'node:child_process'
|
|
import fs from 'node:fs'
|
|
import os from 'node:os'
|
|
import path from 'node:path'
|
|
import process from 'node:process'
|
|
// eslint-disable-next-line test/no-import-node-test -- Validate real runner exit codes and scope boundaries.
|
|
import test from 'node:test'
|
|
import { browserInvocation, browserScopeConfig, installedTests } from '../scripts/browser-validation/scope.ts'
|
|
|
|
test('Source invocation clears inherited artifact selection without changing caller environment', () => {
|
|
const environment = { ARTPLAYER_BROWSER_ARTIFACTS: '/installed/map.json', KEEP: 'value' }
|
|
const source = browserInvocation('source', ['--project=chromium'], environment)
|
|
assert.equal(source.env.ARTPLAYER_BROWSER_ARTIFACTS, undefined)
|
|
assert.equal(source.env.KEEP, 'value')
|
|
assert.equal(environment.ARTPLAYER_BROWSER_ARTIFACTS, '/installed/map.json')
|
|
assert.deepEqual(browserScopeConfig('source').testMatch, ['**/*.spec.js'])
|
|
const installed = browserInvocation('installed', [], environment)
|
|
assert.equal(installed.env.ARTPLAYER_BROWSER_ARTIFACTS, environment.ARTPLAYER_BROWSER_ARTIFACTS)
|
|
assert.notEqual(source.directory, installed.directory)
|
|
assert(installedTests.includes('ambilight-proxy.spec.js'))
|
|
assert(installedTests.includes('canvas-lifecycle.spec.js'))
|
|
for (const file of installedTests)
|
|
assert(fs.existsSync(path.resolve('test/browser', file)))
|
|
})
|
|
|
|
test('Browser invocation rejects ambiguous scopes and output/configuration overrides', () => {
|
|
assert.throws(() => browserInvocation('unknown', [], {}), /Choose/)
|
|
assert.throws(() => browserInvocation('installed', [], {}), /require ARTPLAYER/)
|
|
for (const flag of ['--config=other.js', '--config', '-c', '-cother.js', '--reporter=json', '--output=elsewhere', '--pass-with-no-tests'])
|
|
assert.throws(() => browserInvocation('source', [flag], {}), /Do not override/)
|
|
})
|
|
|
|
for (const code of [0, 17]) {
|
|
test(`Browser runner preserves actual child exit ${code} and source input identity`, () => {
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'artplayer-browser-runner-'))
|
|
try {
|
|
const cli = path.join(root, 'node_modules/@playwright/test/cli.js')
|
|
fs.mkdirSync(path.dirname(cli), { recursive: true })
|
|
fs.writeFileSync(cli, `require('node:assert/strict').equal(process.env.ARTPLAYER_BROWSER_ARTIFACTS, undefined); process.exit(${code});`)
|
|
const run = spawnSync(process.execPath, [path.resolve('scripts/browser-check.mjs'), 'source'], { cwd: root, env: { ...process.env, ARTPLAYER_BROWSER_ARTIFACTS: '/unwanted/map.json' }, encoding: 'utf8', windowsHide: true, timeout: 10000 })
|
|
assert.equal(run.status, code, run.stderr)
|
|
const directory = path.join(root, 'refactor/.cache/browser-source')
|
|
const invocation = JSON.parse(fs.readFileSync(path.join(directory, 'invocation.json')))
|
|
const result = JSON.parse(fs.readFileSync(path.join(directory, 'result.json')))
|
|
assert.equal(invocation.artifactMap, null)
|
|
assert.equal(result.exitCode, code)
|
|
assert.equal(result.scope, 'source')
|
|
assert(!fs.existsSync(path.join(root, 'refactor/.cache/browser-installed')))
|
|
}
|
|
finally {
|
|
assert.equal(path.dirname(root), path.resolve(os.tmpdir()))
|
|
assert(path.basename(root).startsWith('artplayer-browser-runner-'))
|
|
fs.rmSync(root, { recursive: true, force: true })
|
|
}
|
|
})
|
|
}
|