46 lines
1.5 KiB
JavaScript
46 lines
1.5 KiB
JavaScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import path from 'node:path'
|
|
|
|
import {
|
|
loadDriverResources,
|
|
resolveDriverDownloadUrl
|
|
} from '../src/services/driverManifest.js'
|
|
|
|
const repoRoot = path.resolve(import.meta.dirname, '..', '..')
|
|
|
|
test('loadDriverResources 能读取官方与归档版驱动清单', async () => {
|
|
const resources = await loadDriverResources(repoRoot)
|
|
|
|
assert.equal(resources.officialLatest.version, 'latest')
|
|
assert.match(resources.officialLatest.sourceUrl, /^https:\/\/www\.x-printer\.cn\//)
|
|
assert.equal(resources.companyArchive.version, '2026.01.28.01')
|
|
assert.equal(
|
|
resources.companyArchive.relativePath,
|
|
'downloads/printer-driver/xprinter/archive/2026.01.28.01/xprinter-driver-2026.01.28.01.exe'
|
|
)
|
|
})
|
|
|
|
test('resolveDriverDownloadUrl 会把归档版相对路径转为服务器下载地址', async () => {
|
|
const resources = await loadDriverResources(repoRoot)
|
|
const url = resolveDriverDownloadUrl('https://www.jsgdzc.cn', resources.companyArchive)
|
|
|
|
assert.equal(
|
|
url,
|
|
'https://www.jsgdzc.cn/downloads/printer-driver/xprinter/archive/2026.01.28.01/xprinter-driver-2026.01.28.01.exe'
|
|
)
|
|
})
|
|
|
|
test('resolveDriverDownloadUrl 会自动去掉服务器地址末尾的 /api', async () => {
|
|
const resources = await loadDriverResources(repoRoot)
|
|
const url = resolveDriverDownloadUrl(
|
|
'https://www.jsgdzc.cn/api',
|
|
resources.companyArchive
|
|
)
|
|
|
|
assert.equal(
|
|
url,
|
|
'https://www.jsgdzc.cn/downloads/printer-driver/xprinter/archive/2026.01.28.01/xprinter-driver-2026.01.28.01.exe'
|
|
)
|
|
})
|