Isolate store purchase rehearsals from TREK Cloud production [skip ci]

This commit is contained in:
Maurice
2026-12-02 18:38:59 +01:00
parent e54f954f31
commit 0f683b0dee
6 changed files with 189 additions and 23 deletions
@@ -0,0 +1,45 @@
import assert from 'node:assert/strict';
import { basename } from 'node:path';
import { test } from 'node:test';
import config from '../vite.native.config.js';
const variable = 'TREK_CLOUD_SANDBOX_ORIGIN';
function setOrigin(context, origin) {
const previous = process.env[variable];
process.env[variable] = origin;
context.after(() => {
if (previous === undefined) delete process.env[variable];
else process.env[variable] = previous;
});
}
test('isolates the sandbox output and keeps the ordinary app on the production configuration', (context) => {
const origin = 'https://store-sandbox.example.com';
setOrigin(context, origin);
const sandbox = config({ command: 'build', mode: 'store-sandbox' });
assert.deepEqual(sandbox.define, { __TREK_STORE_SANDBOX_ORIGIN__: JSON.stringify(origin) });
assert.equal(basename(sandbox.build.outDir), 'native-sandbox-dist');
for (const input of [
{ command: 'build', mode: 'production' },
{ command: 'serve', mode: 'store-sandbox' },
]) {
const regular = config(input);
assert.deepEqual(regular.define, {});
assert.equal(basename(regular.build.outDir), 'native-dist');
}
});
for (const origin of [
'',
'http://qa.example.com',
'https://qa.example.com/path',
'https://liketrek.com',
'https://www.liketrek.com',
]) {
test(`refuses a sandbox configuration with origin ${JSON.stringify(origin)}`, (context) => {
setOrigin(context, origin);
assert.throws(() => config({ command: 'build', mode: 'store-sandbox' }), { message: new RegExp(variable) });
});
}