Skip to content

Core: Implement a node stdout reporter#790

Closed
leobalter wants to merge 9 commits into
qunitjs:masterfrom
leobalter:node-reporter
Closed

Core: Implement a node stdout reporter#790
leobalter wants to merge 9 commits into
qunitjs:masterfrom
leobalter:node-reporter

Conversation

@leobalter

Copy link
Copy Markdown
Member

With this reporter we can use QUnit directly on npm environments:

var QUnit = require( "../dist/QUnit" );

QUnit.reporter();

require( "./unit-tests.js" );

QUnit.load();

The stdout reporter is only activated when called, this way we keep the retrocompatibility.

Log example: https://www.dropbox.com/s/07k3funzdwp0y7r/Screenshot%202015-03-19%2016.18.25.png?dl=0

The reporter function also accepts an object with the options, the only current available options is output:

// Will print a minimal report, with only dots for each assertion,
// some extra information comes on failures to help locate the issue
QUnit.reporter({
  output: "minimal"
});
// Will print a more detailed report, listing each passing assertion.
QUnit.reporter({
  output: "verbose"
});

@scottgonzalez

Copy link
Copy Markdown
Contributor

Is the use of chalk the only thing specific to node? You might consider changing this from a node stdout reporter to a console reporter.

@leobalter

Copy link
Copy Markdown
Member Author

The stdout reporter is also using Node's process.stdout and process.error. AFAIK, the use of console.log is limited to one line for each log, which is not what I'm aiming for here.

Maybe, it will be more clear to replace the QUnit.reporter for QUnit.stdout.

My goal in this PR is to provide a full operational reporter for Node, so we may use QUnit without any adapter.

@leobalter

Copy link
Copy Markdown
Member Author

The stdout reporter may be followed by a TAP reporter. The one at Mocha may be used as reference.

I'll take another look to see if I detach this code from the build, and make it an individual module, so we can set it as an separate module and just require the module when QUnit.stdout is called.

@leobalter

Copy link
Copy Markdown
Member Author

The last commit changed this PR to use the stdout reporter feature from an external module. We can turn the module a jQuery project, as you prefer.

Comment thread package.json Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this still needed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

removing it.

Comment thread test/reporter-stdout.js

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How do these tests get access to QUnit? We must be assigning global.QUnit somewhere for that to work, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It will use the QUnit variable assigned above. This current file test/reporter-stdout.js will work as a context module for its following requirements.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Required files in node don't have access to the scope of the file that is requiring it. So the only way for the required file to have QUnit in scope is for a global (right?). Where does the global come from?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See line 3 above.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That var QUnit shouldn't be accessible in the scope of any other files required here. Its a local variable, not made global in any way.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's okay, but still doesn't explain why it was working before.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

as I told before, this looks like an undocumented feature. Node modules seems to be leaking the current file scope to their following required modules.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are you sure about that? QUnit does some crazy stuff with globals and different environments.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, I'm not. I'll check this out on an example repo.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like the this from outro.js refers in node to global, which we then alias as window, and in exports.js we then assign window.QUnit, which in node is the same as global.QUnit. Let's fix that.

@leobalter

Copy link
Copy Markdown
Member Author

bumped the reporter module to 0.2.0 where I included output tests. (the minor version was due to some differences on the stderr output on failing tests)

@jzaefferer jzaefferer mentioned this pull request Apr 14, 2015
leobalter added a commit to leobalter/qunit that referenced this pull request Apr 22, 2015
Ref qunitjs#790

QUnit was found exported to the global object on Node environment
leobalter added a commit to leobalter/qunit that referenced this pull request Aug 11, 2015
Ref qunitjs#790

QUnit was found exported to the global object on Node environment
@leobalter

Copy link
Copy Markdown
Member Author

By several arguments, I'm closing this PR.

We are on the way to have a release of js-reporters, as many improvement ideas came after this PR and now rebasing this is not easy.

@leobalter leobalter closed this Aug 13, 2015
leobalter added a commit to leobalter/qunit that referenced this pull request Aug 16, 2015
Ref qunitjs#790

QUnit was found exported to the global object on Node environment
leobalter added a commit to leobalter/qunit that referenced this pull request Aug 16, 2015
Ref qunitjs#790
Closes qunitjs#813

QUnit was found exported to the global object on Node environment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants