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

refactor: use constants for event names instead of string literals #3655

Merged
merged 1 commit into from Feb 4, 2019

Conversation

boneskull
Copy link
Member

  • also a few other string literals got replaced, but not error messages nor codes
  • a couple adjacent refactors:
    • move the suite "GC" function into the Suite prototype
    • move stats collector init to Mocha#run due to circular reference with Runner
    • rename a couple fixture files lacking proper extension
    • rename variable in integration test helpers
  • specifically did NOT refactor event names from Node.js incl. error and uncaughtException

Did not rename any events.

@boneskull boneskull added semver-patch implementation requires increase of "patch" version number; "bug fixes" type: cleanup a refactor labels Jan 4, 2019
@coveralls
Copy link

coveralls commented Jan 5, 2019

Coverage Status

Coverage increased (+0.4%) to 91.498% when pulling 51ec4af on boneskull/refactor/event-constants into 29aa611 on master.

Copy link
Contributor

@craigtaub craigtaub left a comment

Choose a reason for hiding this comment

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

Nice one (auto-complete 👍). Few comments.

Also we should not forget to update the "third party reporters" section of Wiki.

lib/suite.js Outdated Show resolved Hide resolved
lib/reporters/nyan.js Outdated Show resolved Hide resolved
@boneskull boneskull force-pushed the boneskull/refactor/event-constants branch from f55b965 to 246a4de Compare January 7, 2019 23:12
@boneskull
Copy link
Member Author

Instead of the wiki, I've added a tutorial in the API documentation section.

Once this is merged & released we can redirect users to it.

@boneskull boneskull force-pushed the boneskull/refactor/event-constants branch from 11a92c5 to c0d1d92 Compare January 8, 2019 01:22
docs/api-tutorials/custom-reporter.md Outdated Show resolved Hide resolved
docs/api-tutorials/custom-reporter.md Outdated Show resolved Hide resolved
@boneskull boneskull self-assigned this Jan 9, 2019
@boneskull boneskull force-pushed the boneskull/refactor/event-constants branch from 6297486 to 5e55bc8 Compare January 10, 2019 22:48
lib/runner.js Outdated Show resolved Hide resolved
[runner]: /api/mocha.runner
[test]: /api/mocha.test
[hook]: /api/mocha.hook
[suite]: /api/mocha.suite
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was the Wiki page poo-poo'd in favor of this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I would like to consolidate tutorials on the documentation site. It is painful to have to go to separate sites for information.

I am not thrilled about how the tutorial is buried in the navigation, but #3663 should allow us to move the "Tutorials" nav section to the top.

jsdoc.conf.json Outdated Show resolved Hide resolved
test/unit/throw.spec.js Outdated Show resolved Hide resolved
lib/reporters/list.js Outdated Show resolved Hide resolved
@@ -8,6 +8,9 @@

var Base = require('./base');
Copy link
Contributor

@plroebuck plroebuck Jan 12, 2019

Choose a reason for hiding this comment

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

This is a question, not request for change:
As all reporters besides html and json-stream (which can do both) are Node-based, are the non-browser reporters required to retain ES5-compatiblity?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think, simply because they're all pulled in to the bundle. Not pulling them in to would break people using certain headless browser setups.

Ideally we shouldn't have to manage the language level on a file-by-file or directory-by-directory basis, and would have a transpilation step. I don't want to have to think about it, and neither should our contributors.

Copy link
Member Author

Choose a reason for hiding this comment

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

(yes, to pile on w/ the confusion, the node.js-based reporters can and do run in a browser on the command-line)

Copy link
Contributor

Choose a reason for hiding this comment

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

Wish I could say I understand what you just wrote, but I don't. Many are terminal-based (e.g., Nyan) and should fail if attempted to run in browser. I was about to add more error checking which would cause Error to be thrown if terminal cursor positioning was unsupported in a new PR. You saying that won't work due to browser?

Copy link
Member Author

Choose a reason for hiding this comment

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

See what mochify does. Essentially it takes Mocha and pipes it thru a headless browser, but it looks like it's running as it would with Node.js. That means you can use console-based reporters with it.

It's unclear to me if what you're doing would cause a problem. My suggestion is to download Mochify and npm link it against your mocha working copy & see what happens.

lib/runner.js Outdated Show resolved Hide resolved
@@ -2,14 +2,22 @@

/**
* Provides a factory function for a {@link StatsCollector} object.
* @private
* @module
Copy link
Contributor

Choose a reason for hiding this comment

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

 * @module StatsCollector

Copy link
Member Author

Choose a reason for hiding this comment

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

...StatsCollector is a typedef. we don't want to conflicting names. it seems like it should refer to what you'd actually call require with: require('mocha/lib/stats-collector'), so stats-collector.

it defaults to lib/stats-collector, which is fine for now, I guess.

Copy link
Member Author

Choose a reason for hiding this comment

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

I mean, the docstrings need cleanup. I am not convinced we're all on the same page about what belongs in the API docs and how best to present it. ...or even how to come to that decision. Maybe someone can just propose something and throw it in a PR and we can go from there?

lib/interfaces/bdd.js Outdated Show resolved Hide resolved
lib/interfaces/tdd.js Outdated Show resolved Hide resolved
lib/runner.js Outdated Show resolved Hide resolved
lib/runner.js Outdated Show resolved Hide resolved
@boneskull boneskull force-pushed the boneskull/refactor/event-constants branch from d3571ed to 9642e60 Compare January 22, 2019 19:47

[Base] is an "abstract" class. It contains console-specific settings and utilities, commonly used by built-in reporters. Browsing the built-in reporter implementations, you may often see static properties of [Base] referenced.

It's often useful--but not necessary--for a custom reporter to extend [Base].
Copy link
Contributor

@plroebuck plroebuck Jan 23, 2019

Choose a reason for hiding this comment

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

Add spaces on both sides of dbl-hyphens so spelling can be checked more easily

Copy link
Member Author

Choose a reason for hiding this comment

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

I've never heard of that issue before, can you explain more?

I can say with certainty that I don't love double-hyphens! Maybe there's a smart hyphen transformation...

Copy link
Contributor

Choose a reason for hiding this comment

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

Would prefer:
It's often useful--but not necessary--for
changed to:
It's often useful -- but not necessary -- for
or
It's often useful (but not necessary) for

@boneskull boneskull force-pushed the boneskull/refactor/event-constants branch from 9642e60 to 4b90caa Compare January 25, 2019 22:25
@boneskull boneskull mentioned this pull request Jan 25, 2019
@boneskull boneskull force-pushed the boneskull/refactor/event-constants branch from 0c76c95 to 50bfcd7 Compare February 1, 2019 23:38
package-scripts.js Outdated Show resolved Hide resolved
- also a few other string literals got replaced, but not error messages nor codes
- supporting refactors:
  - move the suite "GC" function into the `Suite` prototype
  - move stats collector init to `Mocha#run` due to circular reference with `Runner`
  - rename a couple fixture files lacking proper extension
  - rename variable in integration test helpers
  - add `utils.createMap()` and `utils.defineConstants()`
  - add `test/integration/fixtures` to `.eslintignore` so no fixture linting occurs whatsoever
  - consolidated use of `object.assign` polyfill into `utils` module
  - some docstring fixes/consistency
  - adds `EVENT_DELAY_END` emitted from `Runner` for reporter use
- specifically did NOT refactor event names from Node.js incl. `error` and `uncaughtException`
- add custom reporter tutorial to API documentation
    - automatically injects reporter example into tutorial via `markdown-magic`
    - add `docs.preprocess.api` script
    - add JSDoc configuration to support tutorials
    - sort JSDoc config object because fussy
- fix broken custom assertion
@boneskull boneskull force-pushed the boneskull/refactor/event-constants branch from bd114f0 to 51ec4af Compare February 4, 2019 23:28
@boneskull
Copy link
Member Author

squashed, going to merge it

@boneskull boneskull merged commit 52b9a5f into master Feb 4, 2019
@boneskull boneskull deleted the boneskull/refactor/event-constants branch February 4, 2019 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-patch implementation requires increase of "patch" version number; "bug fixes" type: cleanup a refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants