mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-16 08:25:14 +02:00
feat(telemetry): dim first-run notice
This commit is contained in:
parent
9834c609f4
commit
1953466c78
2 changed files with 23 additions and 2 deletions
|
|
@ -54,7 +54,7 @@ describe('telemetry identity', () => {
|
|||
expect(identity.installId).toMatch(/^[0-9a-f-]{36}$/);
|
||||
expect(identity.createdFile).toBe(true);
|
||||
expect(identity.noticeShown).toBe(true);
|
||||
expect(testIo.stderr()).toBe(`${TELEMETRY_NOTICE}\n`);
|
||||
expect(testIo.stderr()).toBe(`[2m${TELEMETRY_NOTICE}[22m\n`);
|
||||
|
||||
const stored = JSON.parse(await readFile(join(homeDir, '.ktx', 'telemetry.json'), 'utf-8')) as {
|
||||
enabled: boolean;
|
||||
|
|
@ -64,6 +64,20 @@ describe('telemetry identity', () => {
|
|||
expect(stored.noticeShownVersion).toBe(1);
|
||||
});
|
||||
|
||||
it('emits the notice without ANSI when NO_COLOR is set', async () => {
|
||||
const testIo = makeIo(true);
|
||||
|
||||
await loadTelemetryIdentity({
|
||||
homeDir,
|
||||
env: { NO_COLOR: '1' },
|
||||
stdoutIsTTY: true,
|
||||
stderr: testIo.io.stderr,
|
||||
now: () => new Date('2026-05-22T14:33:02.000Z'),
|
||||
});
|
||||
|
||||
expect(testIo.stderr()).toBe(`${TELEMETRY_NOTICE}\n`);
|
||||
});
|
||||
|
||||
it('does not create a file when env disables telemetry', async () => {
|
||||
const identity = await loadTelemetryIdentity({
|
||||
homeDir,
|
||||
|
|
|
|||
|
|
@ -25,6 +25,13 @@ export interface TelemetryIdentityEnv {
|
|||
KTX_TELEMETRY_DISABLED?: string;
|
||||
DO_NOT_TRACK?: string;
|
||||
CI?: string;
|
||||
NO_COLOR?: string;
|
||||
TERM?: string;
|
||||
}
|
||||
|
||||
function styleNotice(notice: string, env: TelemetryIdentityEnv): string {
|
||||
if (env.NO_COLOR || env.TERM === 'dumb') return notice;
|
||||
return `[2m${notice}[22m`;
|
||||
}
|
||||
|
||||
export interface LoadTelemetryIdentityOptions {
|
||||
|
|
@ -110,7 +117,7 @@ export async function loadTelemetryIdentity(options: LoadTelemetryIdentityOption
|
|||
};
|
||||
}
|
||||
|
||||
options.stderr.write(`${TELEMETRY_NOTICE}\n`);
|
||||
options.stderr.write(`${styleNotice(TELEMETRY_NOTICE, env)}\n`);
|
||||
|
||||
return {
|
||||
installId: next.installId,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue