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

Adds support for loading reporter from an absolute or relative path. #2659

Merged
merged 1 commit into from Jan 10, 2017

Conversation

sul4bh
Copy link
Contributor

@sul4bh sul4bh commented Jan 4, 2017

This closes #2434

Created this PR based on @cletusw comment here: #2453 (comment)

@boneskull Please review.

@jsf-clabot
Copy link

jsf-clabot commented Jan 4, 2017

CLA assistant check
All committers have signed the CLA.

@Munter
Copy link
Member

Munter commented Jan 4, 2017

Looks good to me

@Munter Munter added type: feature enhancement proposal status: needs review a maintainer should (re-)review this pull request labels Jan 4, 2017
@sul4bh
Copy link
Contributor Author

sul4bh commented Jan 4, 2017

Not sure why the build job #3029.7 failed. Probably a one-off failure.

@Munter
Copy link
Member

Munter commented Jan 4, 2017

We've been having some false negatives on the integrations tests lately. I've opened #2660 to try and resolve it. Also restarted the failing travis test

@sul4bh
Copy link
Contributor Author

sul4bh commented Jan 9, 2017

Any update on this?

@Munter Munter merged commit 8a3cab0 into mochajs:master Jan 10, 2017
@Munter Munter removed the status: needs review a maintainer should (re-)review this pull request label Jan 10, 2017
@dasilvacontin
Copy link
Contributor

We should avoid merging new features that do not include tests for it. I'll add some.

@andywer
Copy link

andywer commented Jul 19, 2017

I know this PR has been closed some months ago, but it seems that bin/_mocha hasn't been updated since. Is that a bug?

@ScottFreeCode
Copy link
Contributor

ScottFreeCode commented Jul 19, 2017

Thanks for the heads-up!

Reviewing the issues/PRs/behavior, I've found:

  • on Mocha 3.0.0
    • mocha --reporter relative/path[.js] works
    • mocha --reporter /absolute/path[.js] works
    • mocha --reporter ./relative/path[.js] fails
  • on Mocha 3.4.2
    • mocha --reporter relative/path[.js] works
    • mocha --reporter /absolute/path[.js] works
    • mocha --reporter ./relative/path[.js] fails
  • After this PR was merged, tests were added for the two behaviors that worked all along: https://github.com/mochajs/mocha/pull/2773/files
  • At a glance, it looks like reporter lookup logic is duplicated between lib/mocha.js and bin/_mocha (if so, this is definitely a "bug" in and of itself simply because it creates maintenance issues like this actual bug).
  • I think (it's hard to be sure without documentation) that
    module.paths.push(cwd, join(cwd, 'node_modules'));
    is what's enabling relative-without-./ path support.
    • I think it's also enabling support for npm i mocha <3rd-party reporter> && node_modules/.bin/mocha --reporter <3rd-party reporter>
    • If I'm not mistaken about that, then it'd be nice to not only get support for ./ reporter paths but to also get support for 3rd-party-in-node_modules reporters without module.paths manipulation, as that would allow us to drop the module.paths manipulation to not only gain compatibility with environments that lack it but bring them up to parity with Mocha on Node.
      • However, we'd need to ensure nothing else is also relying on it (interfaces, --require, --compilers -- anything else?) and/or that everything else relying on it is also corrected to handle the logic without module.paths. (See below.)

My recommendations based on what I've found so far:

  1. Expand the test added in https://github.com/mochajs/mocha/pull/2773/files from including only these cases:
  • local/reporter
  • /absolute/path/to/local/reporter
    ...to including these cases:
  • local/reporter
  • ./local/reporter
  • /absolute/path/to/local/reporter
  • reporter-in-node_modules (this will probably involve temporarily linking or copying a folder into node_modules, preferably using some npm mechanism for doing so safely and cross-platform)
  • <built-in reporter>
    Some of these cases are probably covered in other tests already; if so, we should either consolidate reporter lookup tests, or (in the case of tests that happen to cover this behavior but are primarily testing something else) use the existing tests as a reference when writing tests that are specifically intended to cover this behavior.
  1. Try deleting everything reporter-related in bin/_mocha except the call to the lib/mocha.js reporter load function. If this makes the new tests pass, we're good!
  2. Double-check that we have similar tests for looking up custom/3rd-party interfaces, --require, --compilers, and anything else that Mocha currently supports plugging in. (Is there anything else, or have I covered it all?)
  3. Try deleting module.paths manipulation. If this doesn't break use of custom/3rd-party reporters, interfaces or whatever else, it should resolve We shouldn't rely on the existence of "module.paths" (Meteor) #2505.

@ScottFreeCode
Copy link
Contributor

Updated to add --require and --compilers alongside 3rd-party interfaces as things that may be affected by the module.paths manipulation.

@rodolfo9
Copy link

rodolfo9 commented Sep 5, 2017

Hi,
I couldn't load a local path reporter due to an error in bin/_mocha.
Same as @ScottFreeCodee, I found that the reporter loading code is duplicated in bin/_mocha and lib/mocha.js being the latter much finer.

So I've replaced the following lines in bin/_mocha (215:230)

// reporter

mocha.reporter(program.reporter, reporterOptions)._reporter;

// load reporter

var Reporter = null;
try {
  Reporter = require('../lib/reporters/' + program.reporter);
} catch (err) {
  try {
    Reporter = require(program.reporter);
  } catch (err2) {
    throw new Error('reporter "' + program.reporter + '" does not exist');
  }
}

with:

// reporter

var Reporter = mocha.reporter(program.reporter, reporterOptions)._reporter;

And it worked nicely. I would like to see it fixed on next versions.

Cheers!

jimthedev pushed a commit to commitizen/cz-cli that referenced this pull request May 24, 2018
This Pull Request updates dependency [mocha](https://github.com/mochajs/mocha) from `v3.1.2` to `v3.5.3`



<details>
<summary>Release Notes</summary>

### [`v3.5.3`](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#&#8203;353--2017-09-11)
[Compare Source](mochajs/mocha@v3.5.2...v3.5.3)
#### 🐛 Fixes

- [#&#8203;3003]: Fix invalid entities in xUnit reporter first appearing in v3.5.1 ([@&#8203;jkrems])

[#&#8203;3003]: `mochajs/mocha#3003

---

### [`v3.5.2`](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#&#8203;352--2017-09-10)
[Compare Source](mochajs/mocha@v3.5.1...v3.5.2)
#### 🐛 Fixes

- [#&#8203;3001]: Fix AMD-related failures first appearing in v3.5.1 ([@&#8203;boneskull])

[#&#8203;3001]: `mochajs/mocha#3001

---

### [`v3.5.1`](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#&#8203;351--2017-09-09)
[Compare Source](mochajs/mocha@v3.5.0...v3.5.1)
#### 📰 News

- 📣 Mocha is now sponsoring [PDXNode](http://pdxnode.org)!  If you're in the [Portland](https://wikipedia.org/wiki/Portland,_Oregon) area, come check out the monthly talks and hack nights!
#### 🐛 Fixes

- [#&#8203;2997]: Fix missing `xit` export for "require" interface ([@&#8203;solodynamo])
- [#&#8203;2957]: Fix unicode character handling in XUnit reporter failures ([@&#8203;jkrems])
#### 🔩 Other

- [#&#8203;2986]: Add issue and PR templates ([@&#8203;kungapal])
- [#&#8203;2918]: Drop bash dependency for glob-related tests ([@&#8203;ScottFreeCode])
- [#&#8203;2922]: Improve `--compilers` coverage ([@&#8203;ScottFreeCode])
- [#&#8203;2981]: Fix tpyos and spelling errors ([@&#8203;jsoref])

[#&#8203;2997]: `mochajs/mocha#2997
[#&#8203;2957]: `mochajs/mocha#2957
[#&#8203;2918]: `mochajs/mocha#2918
[#&#8203;2986]: `mochajs/mocha#2986
[#&#8203;2922]: `mochajs/mocha#2922
[#&#8203;2981]: `mochajs/mocha#2981
[@&#8203;solodynamo]: https://github.com/solodynamo
[@&#8203;jkrems]: https://github.com/jkrems
[@&#8203;jsoref]: https://github.com/jsoref

---

### [`v3.5.0`](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#&#8203;350--2017-07-31)
[Compare Source](mochajs/mocha@v3.4.2...v3.5.0)
#### 📰 News

- Mocha now has a [code of conduct](https://github.com/mochajs/mocha/blob/master/.github/CODE_OF_CONDUCT.md) (thanks [@&#8203;kungapal]!).
- Old issues and PRs are now being marked "stale" by [Probot's "Stale" plugin](https://github.com/probot/stale).  If an issue is marked as such, and you would like to see it remain open, simply add a new comment to the ticket or PR.
- **WARNING**: Support for non-ES5-compliant environments will be dropped starting with version 4.0.0 of Mocha!
#### 🔒 Security Fixes

- [#&#8203;2860]: Address [CVE-2015-8315](https://nodesecurity.io/advisories/46) via upgrade of [debug](https://npm.im/debug) ([@&#8203;boneskull])
#### 🎉 Enhancements

- [#&#8203;2696]: Add `--forbid-only` and `--forbid-pending` flags.  Use these in CI or hooks to ensure tests aren't accidentally being skipped! ([@&#8203;charlierudolph])
- [#&#8203;2813]: Support Node.js 8's `--napi-modules` flag ([@&#8203;jupp0r])
#### 🔩 Other

- Various CI-and-test-related fixes and improvements ([@&#8203;boneskull], [@&#8203;dasilvacontin], [@&#8203;PopradiArpad], [@&#8203;Munter], [@&#8203;ScottFreeCode])
- "Officially" support Node.js 8 ([@&#8203;elergy])

[#&#8203;2860]: `mochajs/mocha#2860
[#&#8203;2696]: `mochajs/mocha#2696
[#&#8203;2813]: `mochajs/mocha#2813
[@&#8203;charlierudolph]: https://github.com/charlierudolph
[@&#8203;PopradiArpad]: https://github.com/PopradiArpad
[@&#8203;kungapal]: https://github.com/kungapal
[@&#8203;elergy]: https://github.com/elergy
[@&#8203;jupp0r]: https://github.com/jupp0r

---

### [`v3.4.2`](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#&#8203;342--2017-05-24)
[Compare Source](mochajs/mocha@v3.4.1...v3.4.2)
#### 🐛 Fixes

- [#&#8203;2802]: Remove call to deprecated `os.tmpDir` ([@&#8203;makepanic])
- [#&#8203;2820]: Eagerly set `process.exitCode` ([@&#8203;chrisleck])
#### 🔩 Other

- [#&#8203;2778]: Move linting into an npm script ([@&#8203;Munter])

[@&#8203;chrisleck]: https://github.com/chrisleck
[@&#8203;makepanic]: https://github.com/makepanic
[@&#8203;Munter]: https://github.com/Munter

[#&#8203;2778]: `mochajs/mocha#2778
[#&#8203;2802]: `mochajs/mocha#2802
[#&#8203;2820]: `mochajs/mocha#2820

---

### [`v3.4.1`](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#&#8203;341--2017-05-14)
[Compare Source](mochajs/mocha@v3.3.0...v3.4.1)
Fixed a publishing mishap with git's autocrlf settings.

---

### [`v3.3.0`](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#&#8203;330--2017-04-24)
[Compare Source](mochajs/mocha@v3.2.0...v3.3.0)
Thanks to all our contributors, maintainers, sponsors, and users! ❤️

As highlights:

- We've got coverage now!
- Testing is looking less flaky \o/.
- No more nitpicking about "mocha.js" build on PRs.
#### 🎉 Enhancements

- [#&#8203;2659]: Adds support for loading reporter from an absolute or relative path ([@&#8203;sul4bh])
- [#&#8203;2769]: Support `--inspect-brk` on command-line ([@&#8203;igwejk])
#### 🐛 Fixes

- [#&#8203;2662]: Replace unicode chars w/ hex codes in HTML reporter ([@&#8203;rotemdan])
#### 🔍 Coverage

- [#&#8203;2672]: Add coverage for node tests ([@&#8203;c089], [@&#8203;Munter])
- [#&#8203;2680]: Increase tests coverage for base reporter ([@&#8203;epallerols])
- [#&#8203;2690]: Increase tests coverage for doc reporter ([@&#8203;craigtaub])
- [#&#8203;2701]: Increase tests coverage for landing, min, tap and list reporters ([@&#8203;craigtaub])
- [#&#8203;2691]: Increase tests coverage for spec + dot reporters ([@&#8203;craigtaub])
- [#&#8203;2698]: Increase tests coverage for xunit reporter ([@&#8203;craigtaub])
- [#&#8203;2699]: Increase tests coverage for json-stream, markdown and progress reporters ([@&#8203;craigtaub])
- [#&#8203;2703]: Cover .some() function in utils.js with tests ([@&#8203;seppevs])
- [#&#8203;2773]: Add tests for loading reporters w/ relative/absolute paths ([@&#8203;sul4bh])
#### 🔩 Other

- Remove bin/.eslintrc; ensure execs are linted ([@&#8203;boneskull])
- [#&#8203;2542]: Expand CONTRIBUTING.md ([@&#8203;boneskull])
- [#&#8203;2660]: Double timeouts on integration tests ([@&#8203;Munter])
- [#&#8203;2653]: Update copyright year ([@&#8203;Scottkao85], [@&#8203;Munter])
- [#&#8203;2621]: Update dependencies to enable Greenkeeper ([@&#8203;boneskull], [@&#8203;greenkeeper])
- [#&#8203;2625]: Use trusty container in travis-ci; use "artifacts" addon ([@&#8203;boneskull])
- [#&#8203;2670]: doc(CONTRIBUTING): fix link to org members ([@&#8203;coderbyheart])
- Add Mocha propaganda to README.md ([@&#8203;boneskull])
- [#&#8203;2470]: Avoid test flake in "delay" test ([@&#8203;boneskull])
- [#&#8203;2675]: Limit browser concurrency on sauce ([@&#8203;boneskull])
- [#&#8203;2669]: Use temporary test-only build of mocha.js for browsers tests ([@&#8203;Munter])
- Fix "projects" link in README.md ([@&#8203;boneskull])
- [#&#8203;2678]: Chore(Saucelabs): test on IE9, IE10 and IE11 ([@&#8203;coderbyheart])
- [#&#8203;2648]: Use `semistandard` directly ([@&#8203;kt3k])
- [#&#8203;2727]: Make the build reproducible ([@&#8203;lamby])

[@&#8203;boneskull]: https://github.com/boneskull
[@&#8203;c089]: https://github.com/c089
[@&#8203;coderbyheart]: https://github.com/coderbyheart
[@&#8203;craigtaub]: https://github.com/craigtaub
[@&#8203;epallerols]: https://github.com/epallerols
[@&#8203;greenkeeper]: https://github.com/greenkeeper
[@&#8203;igwejk]: https://github.com/igwejk
[@&#8203;kt3k]: https://github.com/kt3k
[@&#8203;lamby]: https://github.com/lamby
[@&#8203;Munter]: https://github.com/Munter
[@&#8203;rotemdan]: https://github.com/rotemdan
[@&#8203;seppevs]: https://github.com/seppevs
[@&#8203;sul4bh]: https://github.com/sul4bh

[#&#8203;2470]: `mochajs/mocha#2470
[#&#8203;2542]: `mochajs/mocha#2542
[#&#8203;2621]: `mochajs/mocha#2621
[#&#8203;2625]: `mochajs/mocha#2625
[#&#8203;2648]: `mochajs/mocha#2648
[#&#8203;2653]: `mochajs/mocha#2653
[#&#8203;2659]: `mochajs/mocha#2659
[#&#8203;2660]: `mochajs/mocha#2660
[#&#8203;2662]: `mochajs/mocha#2662
[#&#8203;2669]: `mochajs/mocha#2669
[#&#8203;2670]: `mochajs/mocha#2670
[#&#8203;2672]: `mochajs/mocha#2672
[#&#8203;2675]: `mochajs/mocha#2675
[#&#8203;2678]: `mochajs/mocha#2678
[#&#8203;2680]: `mochajs/mocha#2680
[#&#8203;2690]: `mochajs/mocha#2690
[#&#8203;2691]: `mochajs/mocha#2691
[#&#8203;2698]: `mochajs/mocha#2698
[#&#8203;2699]: `mochajs/mocha#2699
[#&#8203;2701]: `mochajs/mocha#2701
[#&#8203;2703]: `mochajs/mocha#2703
[#&#8203;2727]: `mochajs/mocha#2727
[#&#8203;2769]: `mochajs/mocha#2769
[#&#8203;2773]: `mochajs/mocha#2773

---

### [`v3.2.0`](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#&#8203;320--2016-11-24)
[Compare Source](mochajs/mocha@v3.1.2...v3.2.0)
#### 📰 News
##### Mocha is now a JS Foundation Project!

Mocha is proud to have joined the [JS Foundation](https://js.foundation).  For more information, [read the announcement](https://js.foundation/announcements/2016/10/17/Linux-Foundation-Unites-JavaScript-Community-Open-Web-Development/).
##### Contributor License Agreement

Under the foundation, all contributors to Mocha must sign the [JS Foundation CLA](https://js.foundation/CLA/) before their code can be merged.  When sending a PR--if you have not already signed the CLA--a friendly bot will ask you to do so.

Mocha remains licensed under the [MIT license](https://github.com/mochajs/mocha/blob/master/LICENSE).
#### 🐛 Bug Fix

- [#&#8203;2535]: Fix crash when `--watch` encounters broken symlinks ([@&#8203;villesau])
- [#&#8203;2593]: Fix (old) regression; incorrect symbol shown in `list` reporter ([@&#8203;Aldaviva])
- [#&#8203;2584]: Fix potential error when running XUnit reporter ([@&#8203;vobujs])
#### 🎉 Enhancement

- [#&#8203;2294]: Improve timeout error messaging ([@&#8203;jeversmann], [@&#8203;boneskull])
- [#&#8203;2520]: Add info about `--inspect` flag to CLI help ([@&#8203;ughitsaaron])
#### 🔩 Other

- [#&#8203;2570]: Use [karma-mocha](https://npmjs.com/package/karma-mocha) proper ([@&#8203;boneskull])
- Licenses updated to reflect new copyright, add link to license and browser matrix to `README.md` ([@&#8203;boneskull], [@&#8203;ScottFreeCode], [@&#8203;dasilvacontin])

[#&#8203;2294]: `mochajs/mocha#2294
[#&#8203;2535]: `mochajs/mocha#2535
[#&#8203;2520]: `mochajs/mocha#2520
[#&#8203;2593]: `mochajs/mocha#2593
[#&#8203;2584]: `mochajs/mocha#2584
[#&#8203;2570]: `mochajs/mocha#2570
[@&#8203;Aldaviva]: https://github.com/Aldaviva
[@&#8203;jeversmann]: https://github.com/jeversmann
[@&#8203;ughitsaaron]: https://github.com/ughitsaaron
[@&#8203;villesau]: https://github.com/villesau
[@&#8203;vobujs]: https://github.com/vobujs

Thanks to all our contributors, sponsors and backers!  Keep on the lookout for a public roadmap and new contribution guide coming soon.

---

</details>




---

This PR has been generated by [Renovate Bot](https://renovatebot.com).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature enhancement proposal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Project-local custom reporters
7 participants