Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: add more core editor tests
  • Loading branch information
hyperz111 committed Feb 16, 2026
commit 6a4ce5d43cf260366a2f4a6ac930d9037878f722
112 changes: 111 additions & 1 deletion packages/core/test/prompts/editor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('EditorPrompt', () => {
input = new MockReadable();
output = new MockWritable();
vol.reset();
vol.fromJSON({ './cache-abc': 'foo' }, '/tmp');
vol.fromJSON({ './tmp/cache-abc': 'foo', './newtmp/cache-123': 'bar' }, '/');
});

afterEach(() => {
Expand Down Expand Up @@ -48,4 +48,114 @@ describe('EditorPrompt', () => {
expect(instance.value).to.equal('hello');
expect(instance.state).to.equal('submit');
});

describe('path', () => {
const UUID_RE = [8, 4, 4, 4, 12].map((len) => `[a-z0-9]{${len}}`).join('-');
const createRegexp = (dir: string, postfix = '') =>
new RegExp(['', dir, `ce-${UUID_RE}${postfix}`].join('[\\\\/]'));

test('default', () => {
const instance = new EditorPrompt({
input,
output,
render: () => 'foo',
});

instance.prompt();

expect(instance.path).to.match(createRegexp('tmp'));
});

test('custom temp dir', () => {
const instance = new EditorPrompt({
input,
output,
render: () => 'foo',
tmpdir: '/newtmp',
});

instance.prompt();

expect(instance.path).to.match(createRegexp('newtmp'));
});

test('custom temp file postfix/extension', () => {
const instance = new EditorPrompt({
input,
output,
render: () => 'foo',
postfix: '.txt',
});

instance.prompt();

expect(instance.path).to.match(createRegexp('tmp', '.txt'));
});
});

describe('executable', () => {
const originalEnv = structuredClone(process.env);
const originalPlatform = process.platform;

afterEach(() => {
process.env = originalEnv;
Object.defineProperty(process, 'platform', { value: originalPlatform });
});

test.each(['linux', 'win32'])('%s default', (platform) => {
Object.defineProperty(process, 'platform', { value: platform });

const instance = new EditorPrompt({
input,
output,
render: () => 'foo',
});

instance.prompt();

expect(instance.bin).to.equal(platform === 'win32' ? 'notepad' : 'nano');
expect(instance.args.length).to.equal(1);
});

test('custom binary', () => {
const instance = new EditorPrompt({
input,
output,
render: () => 'foo',
bin: 'vim',
});

instance.prompt();

expect(instance.bin).to.equal('vim');
});

test('custom binary via env.EDITOR', () => {
process.env.EDITOR = 'nvim';

const instance = new EditorPrompt({
input,
output,
render: () => 'foo',
});

instance.prompt();

expect(instance.bin).to.equal('nvim');
});

test('custom args', () => {
const instance = new EditorPrompt({
input,
output,
render: () => 'foo',
args: (p) => ['--', p],
});

instance.prompt();

expect(instance.args.length).to.equal(2);
expect(instance.args[0]).to.equal('--');
});
});
});
Loading