-
Notifications
You must be signed in to change notification settings - Fork 782
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
CLI: Introduce QUnit CLI #1115
CLI: Introduce QUnit CLI #1115
Conversation
bin/qunitjs
Outdated
var walkSync = require( "walk-sync" ); | ||
var run = require( "./run" ); | ||
|
||
var pkg = fs.readJsonSync( path.resolve( __dirname, "..", "package.json" ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would require( '../package.json' );
work here? I believe require, unlike fs, is always scoped to where the code is authored, so it shouldn't need __dirname
.
bin/run.js
Outdated
|
||
module.exports = function run( files ) { | ||
var QUnitFile = path.resolve( __dirname, "../dist/qunit.js" ); | ||
var QUnit = require( QUnitFile ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here :)
A few design questions. EnvironmentDo we want to make individual test suites executable (even if just optional), or should we require a custom environment with certain predefined globals? Source codeHow will source code be called from the test suite? If we target Node.js only, then we can just prescribe users to call Or would it? That depends on the use case for running tests in Node.js:
In case 1, you'd expect the source code to have built-in support for On the other hand, if the alternative trying to specify in a declarative way which modules to load in which variables, that may be even less desirable. Here's a quick sketch: // tests/.qunitrc.js
module.exports = {
reporter: 'tap',
predef: {
MyLib: require( '../' )
}
}; # tests/.qunitrc.yml
reporter: tap
predef:
MyLib: '../' We can learn from ESLint with regards to supporting arbitrary names as |
Thanks for the review and input on the design!
Not entirely sure what you mean by this in relation to the rest of your point.
Yes, this is something I have had specific requests for. It may not be as necessary in the future where ES module import/export is supported in all environments, but I think that is a long way off. So for now, I think having it as an implicit global will be fine, especially since we dropped many globals with the 2.x release.
Yes, Mocha works this way as well, and I think it makes sense. That said, I would like to also support something like a |
I meant the difference between With regards to debugging (and other Node.js or V8 command-line flags, like
|
Ah, okay, I see now. There is nothing to preclude users from setting up their own boilerplate. If this is a feature that winds up being needed/wanted, we could likely enable a mode where we don't do any global injections. As for the debugging aspect, I agree that the extra overhead is a bit annoying, but it's the same for all Node CLIs that I've used. If you ideas/opinions on the best way to support that, I'm all ears! |
8cb509b
to
33b8eba
Compare
Yeah. Manual wrapping will work for now. And upstream may provide an environment variable in the future to make this easier to trigger in situations where it's not feasible to pass command-line flags directly to the Node process. |
ccb52af
to
705fa22
Compare
bin/utils.js
Outdated
let globs = args.slice(); | ||
|
||
if ( !globs.length ) { | ||
globs.push( "test/*.js" ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion, maybe we should include: test/**/*.js
, *.jsx
and .mjs
(node es modules filename, it's ugly, yes)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good to do the recursive thing.
For the other extensions:
- Is
.mjs
officially supported yet? - Can you actually
require
.jsx
files? I was under the impression they needed to be compiled first.
bin/utils.js
Outdated
} catch ( e ) {} | ||
|
||
if ( stat && stat.isDirectory() ) { | ||
return `${glob}/*.js`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
bin/utils.js
Outdated
let stat; | ||
|
||
try { | ||
stat = fs.statSync( glob ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can explore async + await features?
bin/utils.js
Outdated
|
||
if ( !files.length ) { | ||
error( "No files were found matching: " + args.join( ", " ) ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not care about it. If files is empty, we should not log errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually think this is useful feedback for users and ensures the process properly exits with a non-zero code in case they accidentally mess up an input path.
@@ -58,13 +68,15 @@ | |||
"browserstack": "grunt build && sh build/run-browserstack.sh", | |||
"build": "grunt build", | |||
"test": "grunt", | |||
"coverage": "grunt coverage" | |||
"coverage": "grunt coverage", | |||
"test:cli": "grunt build && npm link && qunit test/cli/*.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a noob on npm features, this will call qunit
set in the bin
property in this same file, here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, by calling npm link
we can call qunit
as actual users will after installing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trentmwillis You shouldn't need npm link
: npm will prepend ./node_modules/.bin
to PATH when this npm script is run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It failed on a previous run. We can mess around with it after this lands, but for now I don't feel it is worth digging into.
test/cli/main.js
Outdated
|
||
assert.equal( execution.code, 0 ); | ||
assert.equal( execution.stderr, "" ); | ||
assert.equal( execution.stdout, "TAP version 13\nok 1 1\nok 2 1\n1..2" ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow (the whole test)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems great for a MVP. I left a few suggestions but they should not block this PR, we can work on follow ups if preferred.
On the walk paths, I remember some work from test262-harness to capture files glob.
I've updated this. I think we'll be good to land once a new version of I'm not super pleased with the tests being coupled to the output format of the |
Could I get a quick explanation of the rationale for setting the exit code equal to the number of test failures? I ask because I've seen another project (ESLint) make a decision about exit codes and then refusing to change that logic when it otherwise seemed worthwhile due to the possibility of breaking CI integration scripts that depend on exit code values too heavily. I'm questioning whether there is a lot of value in having the exit code be the number of test failures, when that information should be available in stdout (i.e., in the reporter's output). I'd much rather use exit codes to actually distinguish between a few different failure scenarios. For example:
So personally I'd rather just use codes for specific types of issues/errors and let consumers read the output for further information. But I could definitely be missing something. |
As in ES specs, it would be nice to have some max-min approach. If we land this only with 1 in the exit, we can defer this discussion on the exit values for later and still have the CLI ready. I'm in between the two approaches. Returning the number of tests or having some other sort of meaningful error codes. Both looks nice but I tend to prefer the one suggested by @platinumazure. We can already consume the failures but it's nice if QUnit can tell it's an unexpected exit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use tab indentation instead of two-space indentation? This would conform to the jQuery style guide.
Just the first thing I did, no super special reason for it. I'm fine with using specific error codes, so I'll update this. |
Okay, I've updated with the new |
I'm amazed to see this work. This is one of the most anticipated features for QUnit. |
@platinumazure sorry to ping again, but if you can't get to it this evening, I'm planning on merging and can address any potential concerns in follow up PRs. Need this one to land so I can do the other features. |
+1 for this.
…On Thu, Mar 23, 2017 at 5:39 PM Trent Willis ***@***.***> wrote:
@platinumazure <https://github.com/platinumazure> sorry to ping again,
but if you can't get to it this evening, I'm planning on merging and can
address any potential concerns in follow up PRs. Need this one to land so I
can do the other features.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1115 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AASYkWq_TcYDl1sHtVVnVIZNad4xMuuyks5roxC-gaJpZM4Mf8Bj>
.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. LGTM, thanks!
As discussed in #1024. This PR will introduce the bare-bones functionality of running tests.
Demo:
Todo:
js-reporters
for a betterTapReporter
(which is what tests are assuming)