Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { join } from 'node:path';
|
|
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
import { makeTempMonorepo, cleanup } from './helpers.mjs';
|
|
import { ensureJunction, isLink } from '../lib/junction.mjs';
|
|
|
|
test('ensureJunction 创建链接后可经链接读到真源文件', () => {
|
|
const mono = makeTempMonorepo();
|
|
try {
|
|
const link = join(mono.games, 'demo-framework');
|
|
const status = ensureJunction(link, mono.framework);
|
|
assert.equal(status, 'created');
|
|
assert.ok(isLink(link));
|
|
assert.equal(readFileSync(join(link, 'README.md'), 'utf8'), '# framework src\n');
|
|
} finally {
|
|
cleanup(mono.root);
|
|
}
|
|
});
|
|
|
|
test('ensureJunction 对已存在链接返回 exists 且不抛错', () => {
|
|
const mono = makeTempMonorepo();
|
|
try {
|
|
const link = join(mono.games, 'demo-framework');
|
|
ensureJunction(link, mono.framework);
|
|
assert.equal(ensureJunction(link, mono.framework), 'exists');
|
|
} finally {
|
|
cleanup(mono.root);
|
|
}
|
|
});
|
|
|
|
test('ensureJunction 目标不存在时抛错', () => {
|
|
const mono = makeTempMonorepo();
|
|
try {
|
|
assert.throws(() => ensureJunction(join(mono.games, 'x'), join(mono.root, 'no-such')), /target 不存在/);
|
|
} finally {
|
|
cleanup(mono.root);
|
|
}
|
|
});
|
|
|
|
test('ensureJunction 拒绝覆盖已存在的真实目录/文件', () => {
|
|
const mono = makeTempMonorepo();
|
|
try {
|
|
const link = join(mono.games, 'realfile');
|
|
writeFileSync(link, 'x');
|
|
assert.throws(() => ensureJunction(link, mono.framework), /非链接/);
|
|
} finally {
|
|
cleanup(mono.root);
|
|
}
|
|
});
|