From 4d6fa90b1764f01660311ca1102e8cd576363081 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Thu, 11 Aug 2022 12:19:46 -0400 Subject: [PATCH 1/2] fix(repl): prevent require warning --- src/repl.ts | 3 +++ tests/specs/repl.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/repl.ts b/src/repl.ts index fd36a583..dd8935de 100644 --- a/src/repl.ts +++ b/src/repl.ts @@ -24,6 +24,9 @@ const preEval: REPLEval = async function (code, context, filename, callback) { preserveValueImports: true, }, }, + define: { + require: 'global.require', + }, }, ).catch( (error) => { diff --git a/tests/specs/repl.ts b/tests/specs/repl.ts index f0eab442..453b5b08 100644 --- a/tests/specs/repl.ts +++ b/tests/specs/repl.ts @@ -31,6 +31,32 @@ export default testSuite(async ({ describe }) => { tsxProcess.kill(); }, 5000); + test('doesn\'t error on require', async () => { + const tsxProcess = tsx({ + args: [], + }); + + await new Promise((resolve, reject) => { + tsxProcess.stdout!.on('data', (data: Buffer) => { + const chunkString = data.toString(); + + if (chunkString.includes('unsupported-require-call')) { + return reject(chunkString); + } + + if (chunkString.includes('[Function: resolve]')) { + return resolve(); + } + + if (chunkString.includes('> ')) { + tsxProcess.stdin?.write('require("path")\n'); + } + }); + }); + + tsxProcess.kill(); + }, 2000); + test('errors on import statement', async () => { const tsxProcess = tsx({ args: [], From e2e5e382cca8cdcdc7a19b664805a6d9481e192e Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Thu, 11 Aug 2022 12:31:09 -0400 Subject: [PATCH 2/2] test: increase timeouts --- tests/specs/repl.ts | 4 ++-- tests/specs/watch.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/specs/repl.ts b/tests/specs/repl.ts index 453b5b08..451a9c2c 100644 --- a/tests/specs/repl.ts +++ b/tests/specs/repl.ts @@ -55,7 +55,7 @@ export default testSuite(async ({ describe }) => { }); tsxProcess.kill(); - }, 2000); + }, 5000); test('errors on import statement', async () => { const tsxProcess = tsx({ @@ -77,6 +77,6 @@ export default testSuite(async ({ describe }) => { }); tsxProcess.kill(); - }, 2000); + }, 5000); }); }); diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index aab5f201..6d83f7d3 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -101,7 +101,7 @@ export default testSuite(async ({ describe }, fixturePath: string) => { expect(stdout).toMatch('"--some-flag"'); await tsxProcess; - }, 2000); + }, 5000); describe('help', ({ test }) => { test('shows help', async () => {