업데이트 알림(joke-app과 같게): 웹 빌드 id를 index.html meta(mq-build)에 넣고 서버가 /api/version·welcome으로 알려 줌, 다르면 위쪽에 '업데이트 내용이 있습니다 · 지금 새로고침하기 · ✕' 카드(소켓 다시 연결될 때·5분마다·탭으로 돌아올 때 확인)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
44
apps/server/src/version.test.ts
Normal file
44
apps/server/src/version.test.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
/** 업데이트 알림 (same as joke-app): the server tells which web build it serves. */
|
||||
import { afterEach, expect, test } from 'bun:test';
|
||||
import { mkdtempSync, writeFileSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { webBuildId } from './server';
|
||||
import { Client, api, boot, guest } from './test-utils';
|
||||
|
||||
const running: ReturnType<typeof boot>[] = [];
|
||||
const clients: Client[] = [];
|
||||
afterEach(async () => {
|
||||
for (const c of clients.splice(0)) c.close();
|
||||
for (const s of running.splice(0)) await s.stop();
|
||||
});
|
||||
|
||||
function webDir(html: string): string {
|
||||
const dir = mkdtempSync(join(process.env.TMPDIR ?? tmpdir(), 'mq-web-'));
|
||||
writeFileSync(join(dir, 'index.html'), html);
|
||||
return dir;
|
||||
}
|
||||
|
||||
test('the build id comes from the meta tag of the served index.html', () => {
|
||||
expect(webBuildId(webDir('<html><head><meta name="mq-build" content="abc123def456"></head></html>'))).toBe('abc123def456');
|
||||
expect(webBuildId(webDir('<html><head></head></html>'))).toBeNull();
|
||||
expect(webBuildId('/nonexistent/dir')).toBeNull();
|
||||
});
|
||||
|
||||
test('/api/version and the socket welcome carry the build', async () => {
|
||||
const s = boot({ staticDir: webDir('<html><head><meta name="mq-build" content="0123456789ab"></head></html>') });
|
||||
running.push(s);
|
||||
const r = await api(s.base, '/api/version');
|
||||
expect(r.res.headers.get('cache-control')).toBe('no-store');
|
||||
expect(r.body).toEqual({ build: '0123456789ab' });
|
||||
const g = await guest(s.base, '버전확인');
|
||||
const c = await new Client(s.base, g.cookie).connect();
|
||||
clients.push(c);
|
||||
expect(c.messages.find((m) => m.t === 'welcome')).toMatchObject({ build: '0123456789ab' });
|
||||
});
|
||||
|
||||
test('without a web build (dev, tests) there is nothing to compare', async () => {
|
||||
const s = boot();
|
||||
running.push(s);
|
||||
expect((await api(s.base, '/api/version')).body).toEqual({ build: null });
|
||||
});
|
||||
Reference in New Issue
Block a user