moll / js-must

An assertion library for JavaScript and Node.js with a friendly BDD syntax (awesome.must.be.true()). It ships with many expressive matchers and is test runner and framework agnostic. Follows RFC 2119 with its use of MUST. Good stuff and well tested.
Other
336 stars 35 forks source link

When requiring `demand` or similar functions, `require("must/must")` should be used #64

Closed Ocramius closed 7 years ago

Ocramius commented 7 years ago

Just got this when mixing browserify with must-js: basically, importing must is not sufficient to export all symbols used by must-js itself. Instead, an explicit call to require("must/must") should be done, or import demand from "must/must";.

Just including "must" will cause requirejs/browserify/etc to freak out at runtime.

moll commented 7 years ago

Hey!

Sorry your experiencing some trouble. Would you mind clarifying a tad which things is Browserify not including? I gave a quick try with browserify --require must and it does seem to bundle up must/must.js, too.

Ocramius commented 7 years ago

Sorry your experiencing some trouble.

It's OSS: I'm not a customer, I'm just yet another guy stealing your free time 😋

That said, a block like following doesn't work (my local setup, will try to make an example tomorrow):

import demand from "must";

The above block reports that module "must" could not be found (works in nodejs when running with babel-core/register).

This block works correctly:

import demand from "must/must";

Looking at your package.json, main is pointing at a file that overrides the Object.prototype, but doesn't export any symbols.

moll commented 7 years ago

It's OSS: I'm not a customer, I'm just yet another guy stealing your free time 😋

Come on, throughout my years in OSS I've earned a grand total of $12 thanks to an anonymous donator on Gratipay! :D That's more than can be said for my Monday Calendar, which still has no paid plan. :P

Anyways, the top of the register.js file should have a module.exports line that exports the same must/must file you're directly including. The reason main still points at register.js is for backwards compatibility. Once I get around to finally, years overdue, releasing v1, I'll make the non-Object.prototype mutating version the default and ask all customers to require must/register instead if they wish to use the Object.prototype version. ^_^

Ocramius commented 7 years ago

Having a must/register would be awesome 👍

Also, I'm jealous about your earnings: I'm only at ~5$ on gratipay/gittip.

On 20 Apr 2017 7:19 p.m., "Andri Möll" notifications@github.com wrote:

It's OSS: I'm not a customer, I'm just yet another guy stealing your free time 😋

Come on, throughout my years in OSS I've earned a grand total of $12 thanks to an anonymous donator on Gratipay! :D That's more than can be said for my Monday Calendar, which still has no paid plan. :P

Anyways, the top of the register.js file should have a module.exports line that exports the same must/must file you're directly including. The reason main still points at register.js is for backwards compatibility. Once I get around to finally, years overdue, releasing v1, I'll make the non- Object.prototype mutating version the default and ask all customers to require must/register instead if they wish to use the Object.prototype version. ^_^

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/moll/js-must/issues/64#issuecomment-295822921, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJakPBqz7rNNEu5UFmrpcQ9P5TdCaAkks5rx5O8gaJpZM4NDPNA .

moll commented 7 years ago

must/registser.s exists already, it's just that it won't be the default in v1 for more explicitness. ;) As for your original problem, Browserify or something isn't bundling the must.js file properly? It has to be something else at play there, too, as you were showing the import syntax and I suspect Browserify itself doesn't support that.

Ocramius commented 7 years ago

I suspect Browserify itself doesn't support that.

Using browserify with babelify, as it is impossible to do without in 2017 without encountering even a single NPM dependency not using some newer ES2016/ES2017 feature...

moll commented 7 years ago

Would you mind pasting a oneliner how do you do invoke Browserify with Babelify? I've not used Babelify myself as I'm a ES5-classicist. The other alternative would be to see what's the output of Babelify before Browserify gets a hold of it.

moll commented 7 years ago

Ping, @Ocramius. ;)

Ocramius commented 7 years ago

Hey @moll, sorry for the unresponsiveness.

The team where I tried to introduce browserify/babelify/webpack etc decided that ES6 is "too complicated" and fled back to string concatenation 🤷

I'm trying to reproduce this tonight.

Ocramius commented 7 years ago

Ok, I tried this with webpack again, and it "just works":

import demand from "must";

demand("foo").to.be("bar");

Seems to work just fine, therefore I'm closing this issue as invalid, as this is most likely a browserify issue.

Since the original team is no longer allowing me to dedicate team to the browserify setup, I can't help any further.

Sorry for wasting your time, @moll :-(

moll commented 7 years ago

No prob. Glad it magically started working.

As for ES6, I too am holding on there with classic ES5 pretty much. Not having to need any tooling or preprocessors is a win worthy of giving up the dubious price of a few incoherent features (butchering prototypical inheritance for not-really classical inheritance for one). It's all pretty much string-programming in this dynamic language, but at least with ES5 it's a smaller set of string-programming. Once we liberate browser APIs from JavaScript, we can all hopefully move on. ;)

Ocramius commented 7 years ago

It's all pretty much string-programming in this dynamic language,

Which is why I only do JS when paid a lot to do it ;-)

moll commented 7 years ago

That's the spirit! If only companies realized you could save money by using mature typed languages☨ and not having to spend 4 hours matching up strings in singular and plural...

☨ Not thinking of TypeScript here. ;)

Ocramius commented 7 years ago

@moll btw, 95%+ usage of your library (in the codebase where I introduced it) was instanceOf checks ;-)

Then they dropped it completely because concat()-based JS "compiling" is a suicide when including libraries, so they're back to [Char] -> [Char] -> [Char] programming ;-)

moll commented 7 years ago

98% of mine, I think, is the eql assertion which is like instanceof and equals together, so I do concur. ^_^