mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 01:28:55 +00:00
Isolate store purchase rehearsals from TREK Cloud production [skip ci]
This commit is contained in:
@@ -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) });
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user