Skip to content

Commit 56bdf30

Browse files
committed
fix(@inquirer/testing): resolve xterm CJS named export error under native Node ESM
@xterm/headless v6 is CJS-only; importing via named ESM syntax fails under Node's native loader. Switch to default import + property access. Also update relative imports in testing/src to use .ts extensions, aligning with the monorepo's allowImportingTsExtensions convention and allowing Node 24 to load the source natively in ESM integration tests. Add a regression test in integration/esm to catch this in future.
1 parent 58d3bf0 commit 56bdf30

8 files changed

Lines changed: 15 additions & 8 deletions

File tree

integration/esm/integration.test.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { input } from '@inquirer/prompts';
88
import defaultInput from '@inquirer/input';
99
import { createPrompt } from '@inquirer/core';
1010
import inquirer, { createPromptModule } from 'inquirer';
11+
import { render } from '@inquirer/testing';
1112
import fixturePrompt from './fixturePrompt.mjs';
1213

1314
const exec = promisify(child_process.exec);
@@ -25,6 +26,10 @@ describe('ESM Integration', () => {
2526
assert.ok(typeof createPrompt === 'function');
2627
});
2728

29+
it('@inquirer/testing render should be exported', () => {
30+
assert.ok(typeof render === 'function');
31+
});
32+
2833
it('works when prompt throws an error', async () => {
2934
await assert.rejects(() => fixturePrompt({}), {
3035
message: `Prompt functions must return a string.\n at file://${path.join(import.meta.dirname, './fixturePrompt.mjs')}`,

integration/esm/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"@inquirer/core": "workspace:*",
1212
"@inquirer/input": "workspace:*",
1313
"@inquirer/prompts": "workspace:*",
14+
"@inquirer/testing": "workspace:*",
1415
"inquirer": "workspace:*"
1516
},
1617
"engines": {

packages/testing/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import MuteStream from 'mute-stream';
33
import type { Prompt, Context } from '@inquirer/type';
44

55
type RenderOptions = Omit<Context, 'input' | 'output'>;
6-
import { BufferedStream } from './buffered-stream.js';
7-
import { interpretTerminalOutput } from './terminal.js';
6+
import { BufferedStream } from './buffered-stream.ts';
7+
import { interpretTerminalOutput } from './terminal.ts';
88

99
export async function render<Value, const Config>(
1010
prompt: Prompt<Value, Config>,

packages/testing/src/jest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Note: Jest's requireActual returns `any` by design, unlike Vitest's typed importOriginal
33

44
import type { Prompt } from '@inquirer/type';
5-
import { Screen } from './screen.js';
5+
import { Screen } from './screen.ts';
66

77
// Global screen instance - exported for tests
88
const screenInstance: Screen = new Screen();

packages/testing/src/screen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { stripVTControlCharacters } from 'node:util';
22
import MuteStream from 'mute-stream';
3-
import { BufferedStream } from './buffered-stream.js';
4-
import { interpretTerminalOutput } from './terminal.js';
3+
import { BufferedStream } from './buffered-stream.ts';
4+
import { interpretTerminalOutput } from './terminal.ts';
55

66
export type KeypressEvent = {
77
name?: string;

packages/testing/src/terminal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { Terminal } from '@xterm/headless';
1+
import xterm from '@xterm/headless';
22

33
export async function interpretTerminalOutput(
44
rawOutput: string,
55
cols: number = 10_000,
66
rows: number = 4000,
77
): Promise<string> {
8-
const term = new Terminal({ cols, rows, allowProposedApi: true, convertEol: true });
8+
const term = new xterm.Terminal({ cols, rows, allowProposedApi: true, convertEol: true });
99
await new Promise<void>((resolve) => term.write(rawOutput, resolve));
1010

1111
const lines: string[] = [];

packages/testing/src/vitest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { vi, beforeEach } from 'vitest';
22
import type { Prompt } from '@inquirer/type';
3-
import { Screen } from './screen.js';
3+
import { Screen } from './screen.ts';
44

55
// Global screen instance - exported for tests
66
const screenInstance: Screen = new Screen();

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ __metadata:
580580
"@inquirer/core": "workspace:*"
581581
"@inquirer/input": "workspace:*"
582582
"@inquirer/prompts": "workspace:*"
583+
"@inquirer/testing": "workspace:*"
583584
inquirer: "workspace:*"
584585
languageName: unknown
585586
linkType: soft

0 commit comments

Comments
 (0)