ktx/scripts/link-dev-cli.test.mjs

46 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2026-05-10 23:12:26 +02:00
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { linkDevCli } from './link-dev-cli.mjs';
2026-05-10 23:51:24 +02:00
test('linkDevCli writes a ktx-dev launcher by default', async () => {
2026-05-10 23:12:26 +02:00
const writes = [];
const chmods = [];
const result = await linkDevCli({
2026-05-10 23:51:24 +02:00
rootDir: '/workspace/ktx',
2026-05-10 23:12:26 +02:00
globalBin: '/pnpm/bin',
2026-05-10 23:51:24 +02:00
binPath: '/workspace/ktx/packages/cli/dist/bin.js',
2026-05-10 23:12:26 +02:00
execText: async (command, args) => {
2026-05-10 23:51:24 +02:00
assert.equal(command, 'ktx-dev');
2026-05-10 23:12:26 +02:00
assert.deepEqual(args, ['--version']);
2026-05-10 23:51:24 +02:00
return '@ktx/cli 0.0.0-private';
2026-05-10 23:12:26 +02:00
},
writeFile: async (path, content) => writes.push({ path, content }),
chmod: async (path, mode) => chmods.push({ path, mode }),
access: async () => undefined,
});
2026-05-10 23:51:24 +02:00
assert.equal(result.binaryName, 'ktx-dev');
assert.equal(writes[0].path, '/pnpm/bin/ktx-dev');
2026-05-10 23:12:26 +02:00
assert.match(writes[0].content, /packages\/cli\/dist\/bin.js/);
2026-05-10 23:51:24 +02:00
assert.deepEqual(chmods, [{ path: '/pnpm/bin/ktx-dev', mode: 0o755 }]);
2026-05-10 23:12:26 +02:00
});
2026-05-10 23:51:24 +02:00
test('linkDevCli can explicitly write ktx when requested', async () => {
2026-05-10 23:12:26 +02:00
const writes = [];
const result = await linkDevCli({
2026-05-10 23:51:24 +02:00
rootDir: '/workspace/ktx',
binaryName: 'ktx',
2026-05-10 23:12:26 +02:00
globalBin: '/pnpm/bin',
2026-05-10 23:51:24 +02:00
binPath: '/workspace/ktx/packages/cli/dist/bin.js',
execText: async () => '@ktx/cli 0.0.0-private',
2026-05-10 23:12:26 +02:00
writeFile: async (path, content) => writes.push({ path, content }),
chmod: async () => undefined,
access: async () => undefined,
});
2026-05-10 23:51:24 +02:00
assert.equal(result.binaryName, 'ktx');
assert.equal(writes[0].path, '/pnpm/bin/ktx');
2026-05-10 23:12:26 +02:00
});