Files
opsxshell/scripts/build-script.test.mjs

63 lines
2.9 KiB
JavaScript

import assert from 'node:assert/strict'
import { spawnSync } from 'node:child_process'
import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs'
import test from 'node:test'
import { dirname, resolve } from 'node:path'
import { tmpdir } from 'node:os'
import { fileURLToPath } from 'node:url'
import { inspectVersions, setVersion } from './set-version.mjs'
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..')
test('build.sh is valid Bash and documents supported native targets', () => {
const syntax = spawnSync('bash', ['-n', 'scripts/build.sh'], { cwd: root, encoding: 'utf8' })
assert.equal(syntax.status, 0, syntax.stderr)
const help = spawnSync('bash', ['scripts/build.sh', '--help'], { cwd: root, encoding: 'utf8' })
assert.equal(help.status, 0, help.stderr)
assert.match(help.stdout, /mac-arm64/)
assert.match(help.stdout, /win-x64/)
assert.match(help.stdout, /linux-x64/)
assert.match(help.stdout, /不会创建或推送 Git tag/)
assert.match(help.stdout, /src-tauri\/target\/<triple>\/release\/bundle\//)
const script = readFileSync(resolve(root, 'scripts/build.sh'), 'utf8')
assert.match(script, /BUNDLE_ROOT=.*release\/bundle/)
assert.doesNotMatch(script, /ROOT_DIR\/release\/v/)
})
test('build.bat provides an equivalent native Windows x64 release path', () => {
const script = readFileSync(resolve(root, 'scripts/build.bat'), 'utf8')
assert.match(script, /x86_64-pc-windows-msvc/)
assert.match(script, /acceptance:full/)
assert.match(script, /release-preflight\.mjs windows/)
assert.match(script, /verify-release\.mjs windows/)
assert.match(script, /nsis\\\*\.exe/)
assert.match(script, /SHA256SUMS\.txt/)
assert.match(script, /不会创建或推送 Git tag/)
assert.match(script, /src-tauri\\target\\<triple>\\release\\bundle\\/)
assert.doesNotMatch(script, /release\\v%VERSION%/)
})
test('release metadata versions stay synchronized', () => {
const versions = Object.values(inspectVersions(root))
assert.ok(versions.length > 0)
assert.ok(
versions.every((version) => version === versions[0]),
JSON.stringify(versions)
)
})
test('version updater synchronizes every release metadata file', () => {
const fixture = mkdtempSync(resolve(tmpdir(), 'opsxshell-version-'))
mkdirSync(resolve(fixture, 'src-tauri'))
writeFileSync(resolve(fixture, 'package.json'), '{"version":"2.1.0"}\n')
writeFileSync(resolve(fixture, 'package-lock.json'), '{"version":"2.1.0","packages":{"":{"version":"2.1.0"}}}\n')
writeFileSync(resolve(fixture, 'src-tauri/tauri.conf.json'), '{"version":"2.1.0"}\n')
writeFileSync(resolve(fixture, 'src-tauri/Cargo.toml'), '[package]\nname = "opsxshell"\nversion = "2.1.0"\n')
writeFileSync(resolve(fixture, 'src-tauri/Cargo.lock'), '[[package]]\nname = "opsxshell"\nversion = "2.1.0"\n')
const versions = setVersion(fixture, '2.1.7')
assert.ok(Object.values(versions).every((version) => version === '2.1.7'))
})