Skip to content

Commit 2609f2d

Browse files
fix(repl): specify ts loader (#46)
Co-authored-by: Hiroki Osame <hiroki.osame@gmail.com>
1 parent bb00ef9 commit 2609f2d

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

src/repl.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ const nodeRepl = repl.start();
1414
const { eval: defaultEval } = nodeRepl;
1515

1616
const preEval: REPLEval = async function (code, context, filename, callback) {
17-
const transformed = await transform(code, '.ts').catch(
17+
const transformed = await transform(
18+
code,
19+
filename,
20+
{ loader: 'ts' },
21+
).catch(
1822
(error) => {
1923
console.log(error.message);
2024
return { code: '\n' };

tests/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const nodeVersions = [
4242
import('./specs/watch'),
4343
fixture.path,
4444
);
45+
runTestSuite(import('./specs/repl'));
4546
});
4647

4748
for (const nodeVersion of nodeVersions) {

tests/specs/repl.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { testSuite } from 'manten';
2+
import { tsx } from '../utils/tsx';
3+
4+
export default testSuite(async ({ describe }) => {
5+
describe('repl', ({ test }) => {
6+
test('handles ts', async () => {
7+
const tsxProcess = tsx({
8+
args: [],
9+
});
10+
11+
const commands = [
12+
'const message: string = "SUCCESS"',
13+
'message',
14+
];
15+
16+
await new Promise<void>((resolve) => {
17+
tsxProcess.stdout!.on('data', (data: Buffer) => {
18+
const chunkString = data.toString();
19+
20+
if (chunkString.includes('SUCCESS')) {
21+
return resolve();
22+
}
23+
24+
if (chunkString.includes('> ') && commands.length > 0) {
25+
const command = commands.shift();
26+
tsxProcess.stdin?.write(`${command}\n`);
27+
}
28+
});
29+
});
30+
31+
tsxProcess.kill();
32+
}, 5000);
33+
});
34+
});

0 commit comments

Comments
 (0)