Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for named exports #28

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

JamieDanielson
Copy link

Which problem is this PR solving?

Short description of the changes

There is some explanation here of the problems we were running into while trying to update our tests to use a new test runner. It seems that this will be resolved by providing named exports, which may help other folks using ESM as well.

  • Use named exports for wrap, unwrap, massWrap, massUnwrap
  • Add tests asserting named imports work, and also that wrap works with a named import
  • Update scripts to include the new test
  • Upgrade tap to v15.2. It needed a later version to allow proper testing of ESM files, but previous versions before 15.0 used a module @std/esm that didn't work as expected in tests. The latest version has some other changes so I opted for 15.2 to minimize overall changes while still allowing this test to work.

@@ -4,7 +4,9 @@
"description": "Safe(r) monkeypatching for JavaScript.",
"main": "index.js",
"scripts": {
"test": "standard && tap test/*.tap.js --coverage"
"test": "npm run test:cjs && npm run test:mjs",
Copy link
Author

Choose a reason for hiding this comment

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

I can see this being condensed into a single line for testing instead of separating out the esm named export test, open to suggestion.

@@ -23,6 +25,6 @@
"devDependencies": {
"sinon": "^7.2.2",
"standard": "^12.0.1",
"tap": "^12.1.1"
"tap": "15.2"
Copy link
Author

Choose a reason for hiding this comment

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

ESM test support was added in 12.5 but used a special module for it. v15.0 dropped that module in favor of native ESM, and 15.2 is the latest minor version of that.

enumerable: false
})

test('should wrap safely with named export in esm', function (t) {
Copy link
Author

Choose a reason for hiding this comment

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

This is lifted from the wrap.tap.js test, with the main difference being the use of the named import. I wasn't sure whether to add tests for each method or if this is sufficient.

'wrapped unenumerable property is still unenumerable')
})

test('should properly import each named export', function (t) {
Copy link
Author

Choose a reason for hiding this comment

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

This second test just confirms the named imports successfully imported. It may not be necessary, open to feedback.

@JamieDanielson
Copy link
Author

Since this is a larger change because of the test updates, I'm more than happy to reduce this to only add the named exports and not make adjustments to tests and updating the tap package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Shimmer cannot wrap ESM Modules
1 participant