Skip to content

Conversation

@MoLow
Copy link
Member

@MoLow MoLow commented Dec 19, 2022

No description provided.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/modules

@nodejs-github-bot nodejs-github-bot added dont-land-on-v14.x needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem. labels Dec 19, 2022
const kDefaultReporter = 'tap';
const kDefaultDestination = 'stdout';

let paerentModule = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let paerentModule = null;
let parentModule = null;

Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

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

Should we make it "anything that's accepted byimport" so we can support loading from e.g. https: URLs in the future?

@ljharb
Copy link
Member

ljharb commented Dec 20, 2022

I'm confused; why wouldn't this just work exactly like --require?

If node lacks an --import then please add it, but why would it be appropriate for the test runner to add such a critical feature in a non-holistic way?

* @returns {any}
* requireOrImport imports a module if the file is an ES module, otherwise it requires it.
*/
function requireOrImport(filePath) {
Copy link
Member

Choose a reason for hiding this comment

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

esmLoader.import‘s second parameter is parentURL, but you haven’t updated that call (on line 45 here) like you have for Module._load. If there were a test where the reporter were ESM (rather than the single new test in this PR, with reporter r as CommonJS) this would have been caught.

Why do we need this utility? Node.js has --import, which accepts either CommonJS or ESM. Can’t --test-reporter be an alias for that, or map to it?

});
});

it('should support a custom reporter from node_modules', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Please add a test for a similar reporter that’s written in ESM.

@GeoffreyBooth GeoffreyBooth mentioned this pull request Dec 20, 2022
3 tasks
@GeoffreyBooth
Copy link
Member

See #45923; under that PR, it should already be possible to load a test reporter from inside node_modules, since ESMLoader.import applies the module resolution algorithm which will look there. Is there another problem that this PR was intending to solve—something about preserving the parent module when loading from within node_modules? If there’s an issue with that, that would be good to fix in general for all module loading, rather than as a fix specific to test reporters.

@MoLow
Copy link
Member Author

MoLow commented Dec 20, 2022

closing in favor of #45923

@MoLow MoLow closed this Dec 20, 2022
@MoLow MoLow deleted the fix-test-reporter-from-node-modules branch December 20, 2022 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants