Skip to content

Commit

Permalink
fix(repl): specify ts loader (#46)
Browse files Browse the repository at this point in the history
Co-authored-by: Hiroki Osame <[email protected]>
  • Loading branch information
vaakian and privatenumber authored Jun 23, 2022
1 parent bb00ef9 commit 2609f2d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ const nodeRepl = repl.start();
const { eval: defaultEval } = nodeRepl;

const preEval: REPLEval = async function (code, context, filename, callback) {
const transformed = await transform(code, '.ts').catch(
const transformed = await transform(
code,
filename,
{ loader: 'ts' },
).catch(
(error) => {
console.log(error.message);
return { code: '\n' };
Expand Down
1 change: 1 addition & 0 deletions tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const nodeVersions = [
import('./specs/watch'),
fixture.path,
);
runTestSuite(import('./specs/repl'));
});

for (const nodeVersion of nodeVersions) {
Expand Down
34 changes: 34 additions & 0 deletions tests/specs/repl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { testSuite } from 'manten';
import { tsx } from '../utils/tsx';

export default testSuite(async ({ describe }) => {
describe('repl', ({ test }) => {
test('handles ts', async () => {
const tsxProcess = tsx({
args: [],
});

const commands = [
'const message: string = "SUCCESS"',
'message',
];

await new Promise<void>((resolve) => {
tsxProcess.stdout!.on('data', (data: Buffer) => {
const chunkString = data.toString();

if (chunkString.includes('SUCCESS')) {
return resolve();
}

if (chunkString.includes('> ') && commands.length > 0) {
const command = commands.shift();
tsxProcess.stdin?.write(`${command}\n`);
}
});
});

tsxProcess.kill();
}, 5000);
});
});

0 comments on commit 2609f2d

Please sign in to comment.