배포 bundle과 같은 commit의 정적 버전 문서를 생성하고, 열린 탭이 DB mutation 없이 변경을 감지하도록 한다. 동일 버전은 tab session에서 한 번만 안내하며 강제 새로고침은 하지 않는다.
50 lines
2.4 KiB
TypeScript
50 lines
2.4 KiB
TypeScript
import { execFile } from 'node:child_process';
|
|
import { mkdtemp, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import { promisify } from 'node:util';
|
|
|
|
import { afterEach, describe, expect, it } from 'vitest';
|
|
|
|
const execFileAsync = promisify(execFile);
|
|
const materializer = path.resolve(import.meta.dirname, '../../../tools/build-scripts/materialize-profile-frontend.mjs');
|
|
const temporaryRoots: string[] = [];
|
|
|
|
afterEach(async () => {
|
|
await Promise.all(temporaryRoots.splice(0).map((root) => rm(root, { recursive: true, force: true })));
|
|
});
|
|
|
|
describe('profile frontend materializer', () => {
|
|
it('replaces an existing profile artifact from the cached release build', async () => {
|
|
const workspaceRoot = await mkdtemp(path.join(os.tmpdir(), 'profile-frontend-materializer-'));
|
|
temporaryRoots.push(workspaceRoot);
|
|
const source = path.join(workspaceRoot, 'app', 'game-frontend', '.release-build');
|
|
const target = path.join(workspaceRoot, '.release-dist', 'che_2', 'game-frontend');
|
|
await mkdir(source, { recursive: true });
|
|
await mkdir(target, { recursive: true });
|
|
await writeFile(path.join(source, 'index.html'), 'new release');
|
|
await writeFile(path.join(source, 'deployment-version.json'), '{"commitSha":"new"}\n');
|
|
await writeFile(path.join(target, 'index.html'), 'old release');
|
|
|
|
await execFileAsync(process.execPath, [materializer, 'che:2'], { cwd: workspaceRoot });
|
|
|
|
await expect(readFile(path.join(target, 'index.html'), 'utf8')).resolves.toBe('new release');
|
|
await expect(readFile(path.join(target, 'deployment-version.json'), 'utf8')).resolves.toBe(
|
|
'{"commitSha":"new"}\n'
|
|
);
|
|
});
|
|
|
|
it('keeps an existing artifact untouched when the cached build is missing', async () => {
|
|
const workspaceRoot = await mkdtemp(path.join(os.tmpdir(), 'profile-frontend-materializer-'));
|
|
temporaryRoots.push(workspaceRoot);
|
|
const target = path.join(workspaceRoot, '.release-dist', 'che_2', 'game-frontend');
|
|
await mkdir(target, { recursive: true });
|
|
await writeFile(path.join(target, 'index.html'), 'old release');
|
|
|
|
await expect(
|
|
execFileAsync(process.execPath, [materializer, 'che:2'], { cwd: workspaceRoot })
|
|
).rejects.toThrow();
|
|
await expect(readFile(path.join(target, 'index.html'), 'utf8')).resolves.toBe('old release');
|
|
});
|
|
});
|