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

assert.ok needs to be the default export #153

Open
jgonggrijp opened this issue Sep 5, 2022 · 0 comments
Open

assert.ok needs to be the default export #153

jgonggrijp opened this issue Sep 5, 2022 · 0 comments

Comments

@jgonggrijp
Copy link

Thanks for making power-assert possible!

I'm working on a project that uses power-assert together with karma, mocha, rollup and coffeescript. To make it all work together, I needed to make rollup the only preprocessor to karma, use the coffeescript plugin for rollup, and add power-assert support through the babel preset, which in turn I enabled through the babel plugin for rollup. Since everything needs to run in the browser, I'm also using rollup-plugin-node-polyfills, which ends up providing its own version of the Node.js standard assert module.

With this setup, I ran into the following problem. Wherever assert(...) expressions in my test code are instrumented, it is replaced by complex powerAssert(...) expressions. This presumes that powerAssert is a function. However, the source module is assigning a non-callable object to module.exports as well as module.exports.default. Both of these should actually be the assert.ok function.

Using patch-package, I generated the following diff, which solved my problem. Note that this is a non-breaking change: module.exports and module.exports.default still have all the assert.* functions as properties.

diff --git a/node_modules/power-assert/index.js b/node_modules/power-assert/index.js
index acd429a..debd81e 100644
--- a/node_modules/power-assert/index.js
+++ b/node_modules/power-assert/index.js
@@ -62,6 +62,6 @@ function customize (customOptions) {
 }
 
 var defaultAssert = customize();
-define(defaultAssert, { '__esModule': true });
-defaultAssert['default'] = defaultAssert;
-module.exports = defaultAssert;
+define(defaultAssert, { '__esModule': true, 'default': defaultAssert.ok });
+define(defaultAssert.ok, defaultAssert);
+module.exports = defaultAssert.ok;

Note that I also replaced the direct assignment of the default property by a define call. I explained the reason for this in more detail in twada/power-assert-runtime#26.

This issue body was partially generated by patch-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

No branches or pull requests

1 participant