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

Update Mocha to v8, drop Phantomic, run browser tests in Chromium #35

Merged
merged 5 commits into from May 23, 2021

Conversation

m90
Copy link
Collaborator

@m90 m90 commented May 17, 2021

As discussed over in mantoni/mochify.js#213, this updates Mocha to the most recent version.

As more and more packages (e.g. Mocha reporters) seem to use syntax that Phantom.js does not seem to handle well anymore, this PR also moves the browser based test to a Chromium based setup that is pretty close to what is happening in Mochify itself (which is probably a good canary here too in case something goes wrong).

I would assume this will be a new major version, so I also went ahead and changed the Node versions used in Travis to all currently supported ones.

@@ -44,6 +44,11 @@ module.exports = function (b, opts) {
return { main : pkg.browser };
}
});
var broutPath = path.relative(process.cwd(), broutFile);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This change is not strictly necessary, but it's a leftover from moving things around and I felt the order is now easier to understand. It could also just be reverted again.

@@ -139,7 +138,9 @@ module.exports = function (b, opts) {
var self = this;
listener.then(function (err, res) {
if (!err) {
setupSource = (res.mocha || '') + res.setup;
setupSource = (opts.node ? '' : 'require(\'brout\');\n')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Mocha 6.2.0 starts adding behavior to console.log mochajs/mocha#3725 so it's now needed to require brout before requiring mocha. I'm not sure if this ad-hoc string doing it here for us is the most elegant way to do it, but then I also didn't want to add a single line file. Any opinions?

Copy link
Owner

Choose a reason for hiding this comment

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

My opinion is that any hack that get's us there is fine 😆

if (Mocha.reporters['{{REPORTER}}']) {
mocha.reporter('{{REPORTER}}', '{{REPORTER_OPTIONS}}');
} else {
mocha.reporter(require('{{REPORTER}}'), '{{REPORTER_OPTIONS}}');
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Mocha is now bundled using Rollup which does not support dynamic requires for CommonJS. This way we pass in the reporter module instead of its name so that Mocha doesn't have to do any module resolution anymore.

@@ -22,7 +22,7 @@ if ('{{INVERT}}' === true) { // eslint-disable-line no-constant-condition
}
_mocha.reporter('{{REPORTER}}', '{{REPORTER_OPTIONS}}');
_mocha.timeout('{{TIMEOUT}}');
_mocha.useColors('{{USE_COLORS}}');
_mocha.color('{{USE_COLORS}}');
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

useColors seems to have been deprecated a while ago and was removed in Mocha 8 mochajs/mocha#4178

});
s.pipe(p.stdin);
} else if (proc === 'chromium') {
b.bundle(function (err, result) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a stripped down version of what is happening in Mochify.

+ '# tests 1\n'
+ '# pass 1\n'
+ '# fail 0\n');
+ '# fail 0\n'
+ '1..1\n');
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't know too much about the TAP spec, but it seems the plan seems to get printed after the results now? I think it's this commit: mochajs/mocha@2078c32#diff-e8a8c7ad26fed3d12b4bd90577d2fb603f34e78ac146e603c043964f96f5a37e that is causing it. I have no idea if this will be a problem when using this in Mochify?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When linking this version of mocaccino into my local version of mochify this will also make quite a few tests fail because they assert the previous format.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Seems TAP is fine with the plan being either printed at the beginning or the end of the output https://testanything.org/tap-specification.html#the-plan so this is not a bug or anything.

Copy link
Owner

Choose a reason for hiding this comment

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

Thank you for researching. This will be a major release, and also a major of mochify, so it's fine if the output format changes.

run('phantomic', [], b, passOutputAssert(done));
});

it('passes --brout test', function (done) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I removed these tests as we do not pass any flags to Chromium in any way.

@m90 m90 requested a review from mantoni May 17, 2021 06:23
@mantoni mantoni merged commit c29813f into master May 23, 2021
@mantoni mantoni deleted the mocha-update branch May 23, 2021 10:17
@mantoni
Copy link
Owner

mantoni commented May 23, 2021

Awesome! This is great 🥇

📦 Released in v5.0.0.

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.

None yet

2 participants