okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-split-linuxui (83aa59fdc) into f-split-int2b6a38b328

main
1.8 KiB30 linesraw
1import test from 'node:test';
2import assert from 'node:assert/strict';
3import { readFile, mkdtemp, mkdir, writeFile, rm } from 'node:fs/promises';
4import { tmpdir } from 'node:os';
5import { join } from 'node:path';
6import { fileURLToPath } from 'node:url';
7import { appVersionFrom } from '../server/app-version.mjs';
8
9const here = fileURLToPath(new URL('../server', import.meta.url));
10
11test('the shell passes the version; a bad value is ignored', () => {
12  assert.equal(appVersionFrom({ env: { STRATA_APP_VERSION: '0.2.0-beta' }, here: '/nowhere/a/b' }), '0.2.0-beta');
13  assert.equal(appVersionFrom({ env: { STRATA_APP_VERSION: ' 1.2.3 ' }, here: '/nowhere/a/b' }), '1.2.3');
14  assert.equal(appVersionFrom({ env: { STRATA_APP_VERSION: 'latest' }, here: '/nowhere/a/b' }), 'dev');
15  assert.equal(appVersionFrom({ env: {}, here: '/nowhere/a/b' }), 'dev');
16});
17
18test('in a checkout the same file the shell is built from is read, so there is one source', async () => {
19  const toml = await readFile(join(here, '..', '..', 'desktop', 'src-tauri', 'Cargo.toml'), 'utf8');
20  const declared = /^version\s*=\s*"([^"]+)"/m.exec(toml)[1];
21  assert.equal(appVersionFrom({ env: {}, here }), declared);
22  assert.notEqual(declared, '0.1.0', 'the app version is the product version, not the 0.1.0 placeholder');
23  const dir = await mkdtemp(join(tmpdir(), 'strata-appver-'));
24  try {
25    await mkdir(join(dir, 'host', 'server'), { recursive: true });
26    await mkdir(join(dir, 'desktop', 'src-tauri'), { recursive: true });
27    await writeFile(join(dir, 'desktop', 'src-tauri', 'Cargo.toml'), '[package]\nname = "x"\nversion = "9.8.7-rc.1"\n');
28    assert.equal(appVersionFrom({ env: {}, here: join(dir, 'host', 'server') }), '9.8.7-rc.1');
29  } finally { await rm(dir, { recursive: true, force: true }); }
30});