First build
This commit is contained in:
parent
511556737e
commit
fd773f5832
954 changed files with 305115 additions and 2 deletions
92
test/smoke.js
Normal file
92
test/smoke.js
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
'use strict'
|
||||
|
||||
const assert = require('assert')
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
const runner = require('../src/runner')
|
||||
const i18n = require('../src/i18n')
|
||||
|
||||
function testParseArgs() {
|
||||
assert.deepStrictEqual(runner.parseArgs('-dx11 -windowed'), ['-dx11', '-windowed'])
|
||||
assert.deepStrictEqual(runner.parseArgs('--foo "bar baz" --n=1'), ['--foo', 'bar baz', '--n=1'])
|
||||
assert.deepStrictEqual(runner.parseArgs("a 'b c' d"), ['a', 'b c', 'd'])
|
||||
assert.deepStrictEqual(runner.parseArgs(''), [])
|
||||
}
|
||||
|
||||
function testLinkPrefix() {
|
||||
const tmp = fs.mkdtempSync('/tmp/plgl-test-')
|
||||
const compat = path.join(tmp, 'compatdata')
|
||||
const prefix = path.join(tmp, 'pfx-target')
|
||||
fs.mkdirSync(prefix)
|
||||
fs.symlinkSync(prefix, compat, 'dir')
|
||||
assert.strictEqual(fs.readlinkSync(compat), prefix)
|
||||
fs.rmSync(tmp, { recursive: true, force: true })
|
||||
}
|
||||
|
||||
async function testI18n() {
|
||||
require('../src/paths').ensureDirs()
|
||||
const langs = await i18n.init()
|
||||
assert.ok(langs.length >= 2)
|
||||
const codes = i18n.listLangs().map(l => l.code)
|
||||
assert.ok(codes.includes('en-us'))
|
||||
assert.ok(codes.includes('pl'))
|
||||
const en = i18n.getLang('en-us')
|
||||
assert.strictEqual(en.data.nameEn, 'English')
|
||||
assert.strictEqual(i18n.translate('pl', 'toast.saved'), 'Zapisano')
|
||||
assert.strictEqual(i18n.translate('en-us', 'library.lastPlayed', 'x', 'y'), 'Last played x')
|
||||
assert.strictEqual(i18n.translate('en-us', 'nonexistent.key'), 'nonexistent.key')
|
||||
}
|
||||
|
||||
function testTranslationsAreValidJson() {
|
||||
const dir = require('../src/paths').DIRS.BUNDLED_TRANSLATIONS
|
||||
for (const f of fs.readdirSync(dir)) {
|
||||
if (!f.endsWith('.json')) continue
|
||||
const data = JSON.parse(fs.readFileSync(path.join(dir, f), 'utf8'))
|
||||
assert.ok(data.data && data.data.nameEn && data.data.nameSelf, f + ' missing data')
|
||||
assert.ok(data.texts && typeof data.texts === 'object' && Object.keys(data.texts).length > 10, f + ' missing texts')
|
||||
}
|
||||
}
|
||||
|
||||
function testPaths() {
|
||||
const { DIRS } = require('../src/paths')
|
||||
assert.ok(DIRS.WINES.endsWith('files/wines'))
|
||||
assert.ok(DIRS.PREFIXES.endsWith('wineprefixes'))
|
||||
assert.ok(DIRS.FILES.includes('/build/'))
|
||||
}
|
||||
|
||||
function testMainPrefix() {
|
||||
const prefixes = require('../src/prefixes')
|
||||
const defs = prefixes.listPrefixes()
|
||||
assert.ok(defs.prefixes.some(p => p.name === 'Main'), 'Main prefix must exist')
|
||||
assert.strictEqual(defs.default, 'Main')
|
||||
assert.ok(defs.prefixes.find(p => p.name === 'Main').locked, 'Main must be locked')
|
||||
const del = prefixes.deletePrefix('Main')
|
||||
assert.strictEqual(del.ok, false)
|
||||
assert.strictEqual(del.error, 'isMain')
|
||||
const dup = prefixes.createPrefix('Main')
|
||||
assert.strictEqual(dup.ok, false)
|
||||
assert.ok(prefixes.prefixExists('Main'))
|
||||
const created = prefixes.createPrefix('test-prefix-x')
|
||||
assert.ok(created.ok)
|
||||
const setDef = prefixes.setDefaultPrefix('test-prefix-x')
|
||||
assert.ok(setDef.ok)
|
||||
assert.strictEqual(prefixes.listPrefixes().default, 'test-prefix-x')
|
||||
prefixes.deletePrefix('test-prefix-x')
|
||||
assert.strictEqual(prefixes.listPrefixes().default, 'Main')
|
||||
}
|
||||
|
||||
async function run() {
|
||||
testParseArgs()
|
||||
testLinkPrefix()
|
||||
testI18n()
|
||||
testTranslationsAreValidJson()
|
||||
testPaths()
|
||||
testMainPrefix()
|
||||
console.log('All smoke tests passed')
|
||||
}
|
||||
|
||||
run().catch(e => {
|
||||
console.error(e)
|
||||
process.exit(1)
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue