forked from nodejs/import-in-the-middle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure the hooked module exports has @@toStringTag property
The README example says the Hook callback `exported` arg is "effectively `import * as exported from ${url}`". https://tc39.es/ecma262/#sec-module-namespace-objects specs that a Module Namespace Object has a @@toStringTag property with value "Module" and no constructor. Fixes: nodejs#57
- Loading branch information
Showing
2 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License. | ||
// | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. | ||
|
||
import Hook from '../../index.js' | ||
import { foo as fooMjs } from '../fixtures/something.mjs' | ||
import { foo as fooJs } from '../fixtures/something.js' | ||
import { strictEqual, deepStrictEqual } from 'assert' | ||
|
||
let hookedExports | ||
|
||
Hook((exports, name) => { | ||
hookedExports = exports; | ||
}) | ||
|
||
fooMjs | ||
fooJs | ||
|
||
strictEqual(hookedExports[Symbol.toStringTag], 'Module') | ||
deepStrictEqual(Object.getOwnPropertyDescriptor(hookedExports, Symbol.toStringTag), { | ||
value: 'Module', | ||
enumerable: false, | ||
writable: false, | ||
configurable: false | ||
}) |