Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
**/.idea

!test/cli_coverage/node_modules
!test/cli_typescript_esm_dep/node_modules
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't add random stuff here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused here... 🤔

If you mean it literally, then I need to explain that this is needed to reproduce the scenario in which the code breaks. Those node_modules are created manually, not installed from registry.

If you speak generally, for future usage, I agree that we shouldn't touch this file or drop anything into those node_modules.

Please clarify: can this stay as is or I need to remove it? If the later, do you have a suggestion how to add tests files that can reproduce this issue?

test_runner
test/cli/test/leaks.js
2 changes: 1 addition & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ internals.addTsEsmHook = function () {

Module._resolveFilename = function (request, parent, ...rest) {

if (request.endsWith('.js') && (parent.filename.endsWith('.ts') || parent.filename.endsWith('.tsx'))) {
if (request.endsWith('.js') && parent && (parent.filename.endsWith('.ts') || parent.filename.endsWith('.tsx'))) {
const target = Path.join(parent.path, request);
const tsEquivalent = `${target.slice(0, -3)}.ts`;

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/cli_typescript_esm_dep/node_modules/esm-dep/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions test/cli_typescript_esm_dep/node_modules/esm-dep/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/cli_typescript_esm_dep/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "type": "module" }
15 changes: 15 additions & 0 deletions test/cli_typescript_esm_dep/simple.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect } from '@hapi/code';
import * as _Lab from '../../test_runner/index.js';

import { add } from 'esm-dep';


const { describe, it } = exports.lab = _Lab.script();

describe('Test CLI', () => {

it('imports from an ESM dependency', () => {

expect(add(1, 1)).to.equal(2);
});
});
8 changes: 8 additions & 0 deletions test/cli_typescript_esm_dep/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "es2021",
"module": "commonjs",
"moduleResolution": "node",
"removeComments": true
}
}
10 changes: 10 additions & 0 deletions test/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const Fs = require('fs');
const Path = require('path');

const Code = require('@hapi/code');
const Somever = require('@hapi/somever');
const _Lab = require('../test_runner');
const RunCli = require('./run_cli');
const Ts = require('typescript');
Expand Down Expand Up @@ -44,6 +45,15 @@ describe('TypeScript', () => {
expect(result.output.split('Test duration').length - 1).to.equal(1);
});

it('supports TypeScript with ESM dependencies', { skip: !Somever.match(process.version, '>=20') }, async () => {

process.chdir(Path.join(__dirname, 'cli_typescript_esm_dep'));
const result = await RunCli(['simple.ts', '-m', '2000', '--typescript']);
expect(result.errorOutput).to.equal('');
expect(result.code).to.equal(0);
expect(result.output).to.contain('1 tests complete');
});

it('handles errors', async () => {

process.chdir(Path.join(__dirname, 'cli_typescript'));
Expand Down
Loading