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

fix(reporter): allow prefix overrides on win32 #64

Merged
merged 6 commits into from
Apr 11, 2017

Conversation

fluffynuts
Copy link
Contributor

Similar to #57, which seems to have been abandoned, though implemented quite differently.

In addition to adding tests for the functionality I wanted to add, I've also:

  • Made the npm scripts run cross-platform (they were failing on Windows; this has been checked on Linux)
  • Remove the win32-specific branch of color testing as the color package does the right thing now (and this test was failing on win32 before I removed that block)
  • Add a coverage-report npm script to generate the html coverage report as required (which is how I found code to cover)
  • Add coverage for final error reporting, just to bring coverage up a bit, since I've seen warnings in other PRs about coverage dropping and I thought it might be a nice thing to do (:

        - no need to provide path into node_modules
        - remove single-quotes around glob expressions
                - tests were not being run with them in place
        - I'm seeing it automatically brought in on win32, but it's
        missing on Linux
@coveralls
Copy link

Coverage Status

Coverage increased (+14.1%) to 84.444% when pulling 26247ab on fluffynuts:master into 404cb09 on mlex:master.

@fluffynuts
Copy link
Contributor Author

Apologies for the last few trailing commits: it appears as if mocha-runner, with a current Node (7.x) on win32, pulls in mocha; but not with a lower version of Node (4.8.0) on Linux, causing Travis to fail on the coverage script.
I've added an explicit dependency on mocha which makes Travis happy.

@fluffynuts
Copy link
Contributor Author

fluffynuts commented Apr 10, 2017

This PR has been open nearly a month now and I still can't read output on a client's TFS server. I was going to fork on npmjs.com, but I've found a very similar project, karma-mocha-reporter which does what I need.

I'm a little dismayed that no attention was given to this PR. Not only did I fix a long-standing issue (though I'm not the first to provide a patch for the behavior), I added coverage on other areas of code which weren't covered in the past because I saw historical discussions about the desire of the project to maintain decent coverage. It feels a little like the effort was wasted, to be honest.

@tmcgee123
Copy link
Owner

tmcgee123 commented Apr 10, 2017

@fluffynuts It looks like your PR is good to go. Sorry, I've not really paid attention to this repo as I don't use the reporter day to day anymore.

Please don't be discouraged. If you want to help increase coverage I would suggest a separate PR but I'm okay with merging this in if I pull it down and everything works as expected.

Also, it's good to remember that this repo is actually used by a lot of people (~444k downloads on npm this month). So introducing changes has to be tested before things are pushed and published as a new version.

@tmcgee123
Copy link
Owner

tmcgee123 commented Apr 11, 2017

As a note, there are still some tests failing on the Windows 10 machine (this is what I'm developing on locally). I had this problem with a prior PR I merged and a case needs to be explicitly declared for the tests failing only on Windows 10.

Here is the output:

$ npm test

> [email protected] test C:\Users\tjmp68\Projects\karma-spec-reporter
> mocha-runner --reporter spec test/**/*.spec.js

 ▸  [14:09:58] Config: C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\configs\mocha.json


  SpecReporter
    when initializing
      and on a windows machine
        √ SpecReporter should have icons defined appropriately
        √ SpecReporter should allow overriding success icon only
        √ SpecReporter should allow overriding failure icon only
        √ SpecReporter should allow overriding skipped icon only
        √ SpecReporter should allow overriding all icons
      and colors are not defined
        √ SpecReporter should be defined appropriately
        √ should set USE_COLORS to false by default
      and colors are defined
        √ SpecReporter should be defined appropriately
        √ should set USE_COLORS to true
        1) should set the BaseReporter function's colors
      and there are configurations set for the spec reporter
        and suppressFailed is truthy
          √ should return nothing for specSkipped
        and suppressSkipped is truthy
          √ should return nothing for specSkipped
        and suppressPassed is truthy
          √ should return nothing for specSuccess
        and suppressErrorSummary is truthy
          √ should set the suppressErrorSummary flag to true
        and showSpecTiming is truthy
          √ should set the showSpecTiming flag to true
    functionality
      onRunComplete
        with no browsers
          √ should reset failures and currentSuite arrays
          √ should call writeCommonMsg
          √ should call write
        with browsers
          and there are no failures
            √ should call to write all of the successful specs
            √ should reset failures and currentSuite arrays
            √ should call writeCommonMsg
          and there are failures
            and suppressErrorSummary is true
              √ should call to write all of the failed and successful specs
              √ should reset failures and currentSuite arrays
              √ should call writeCommonMsg
              √ should not call to log the final errors
            and suppressErrorSummary is false
              √ should call to write all of the failed and successful specs
              √ should reset failures and currentSuite arrays
              √ should call writeCommonMsg
              √ should call to log the final errors
      logFinalErrors
        2) should write a single failure out
        3) should truncate messages exceding maxLogLines in length
        4) should write out multiple failures
      onSpecFailure
        with FAIL_FAST option
          √ should throw an error


  29 passing (56ms)
  4 failing

  1) SpecReporter when initializing and colors are defined should set the BaseReporter function's colors:

      AssertionError: expected '%s %s FAILED\n' to equal '\u001b[31m%s %s FAILED\u001b[39m\n'
      + expected - actual

      -%s %s FAILED
      +%s %s FAILED

      at Context.<anonymous> (C:\Users\tjmp68\Projects\karma-spec-reporter\test\index.spec.js:179:45)
      at callFn (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runnable.js:326:21)
      at Test.Runnable.run (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runnable.js:319:7)
      at Runner.runTest (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:422:10)
      at C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:528:12
      at next (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:342:14)
      at C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:352:7
      at next (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:284:14)
      at C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:315:7
      at done (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runnable.js:287:5)

  2) SpecReporter functionality logFinalErrors should write a single failure out:

      AssertionError: expected [ Array(5) ] to deeply equal [ Array(5) ]
      + expected - actual

       [
         "\n\n"
      -  "1) should do stuff\n"
      -  "     A B\n"
      -  "     The Error!"
      +  "\u001b[31m1) should do stuff\n\u001b[39m"
      +  "\u001b[31m     A B\n\u001b[39m"
      +  "     \u001b[90mThe Error!\u001b[39m"
         "\n"
       ]

      at Context.<anonymous> (C:\Users\tjmp68\Projects\karma-spec-reporter\test\index.spec.js:433:32)
      at callFn (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runnable.js:326:21)
      at Test.Runnable.run (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runnable.js:319:7)
      at Runner.runTest (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:422:10)
      at C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:528:12
      at next (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:342:14)
      at C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:352:7
      at next (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:284:14)
      at C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:315:7
      at done (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runnable.js:287:5)

  3) SpecReporter functionality logFinalErrors should truncate messages exceding maxLogLines in length:

      AssertionError: expected [ Array(5) ] to deeply equal [ Array(5) ]
      + expected - actual

       [
         "\n\n"
      -  "1) should do stuff\n"
      -  "     A B\n"
      -  "     The Error!"
      +  "\u001b[31m1) should do stuff\n\u001b[39m"
      +  "\u001b[31m     A B\n\u001b[39m"
      +  "     \u001b[90mThe Error!\u001b[39m"
         "\n"
       ]

      at Context.<anonymous> (C:\Users\tjmp68\Projects\karma-spec-reporter\test\index.spec.js:457:32)
      at callFn (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runnable.js:326:21)
      at Test.Runnable.run (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runnable.js:319:7)
      at Runner.runTest (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:422:10)
      at C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:528:12
      at next (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:342:14)
      at C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:352:7
      at next (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:284:14)
      at C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:315:7
      at done (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runnable.js:287:5)

  4) SpecReporter functionality logFinalErrors should write out multiple failures:

      AssertionError: expected [ Array(9) ] to deeply equal [ Array(9) ]
      + expected - actual

       [
         "\n\n"
      -  "1) should do stuff\n"
      -  "     A B\n"
      -  "     The Error!"
      +  "\u001b[31m1) should do stuff\n\u001b[39m"
      +  "\u001b[31m     A B\n\u001b[39m"
      +  "     \u001b[90mThe Error!\u001b[39m"
         "\n"
      -  "2) should do more stuff\n"
      -  "     C D\n"
      -  "     Another error!"
      +  "\u001b[31m2) should do more stuff\n\u001b[39m"
      +  "\u001b[31m     C D\n\u001b[39m"
      +  "     \u001b[90mAnother error!\u001b[39m"
         "\n"
       ]

      at Context.<anonymous> (C:\Users\tjmp68\Projects\karma-spec-reporter\test\index.spec.js:488:32)
      at callFn (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runnable.js:326:21)
      at Test.Runnable.run (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runnable.js:319:7)
      at Runner.runTest (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:422:10)
      at C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:528:12
      at next (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:342:14)
      at C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:352:7
      at next (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:284:14)
      at C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runner.js:315:7
      at done (C:\Users\tjmp68\Projects\karma-spec-reporter\node_modules\mocha-runner\node_modules\mocha\lib\runnable.js:287:5)



 ✘  [14:09:58] undefined
npm ERR! Test failed.  See above for more details.

@fluffynuts
Copy link
Contributor Author

This is strange -- I spent a reasonable amount of time ensuring that the tests worked across windows and linux (hence the changes to the script block in package.json). Also, re-running the tests on my win10 laptop (both from my fork and from a fresh clone of this repository), everything passes.
There must be something different between our machines?
I have been running this with node 7.7.3 (via nvm). What version of node are you using? Perhaps there's a difference in how they output colors, since the failures are only due to color escape codes which would look natural on a *nix term (and are obviously interpreted by something lower down).

I'm currently downloading 7.8.0 (latest stable) and will then try the last stable (6.10.1)

@fluffynuts
Copy link
Contributor Author

(btw, thanks for accepting the PR -- if there is an issue caused by something like expecting too high a node version, I'll sort it out)

@tmcgee123
Copy link
Owner

tmcgee123 commented Apr 11, 2017

It is strange. I had no idea what was happening, but it seemed to take place after the upgrade of the colors dependency PR #59 . I didn't really have time to look into it, but can make an issue for it if need be.

I think you might be on to something, as I am running node 6.10.0. I don't have nvm installed on my machine yet, but can definitely find a way if you need help!

Thanks for your patience 😄 If it makes you feel better I just merged a few PRs a month ago that were sitting for half a year lol

I'll make sure to pay more attention if someone has put in the work for a PR, my apologies again for the delay!

@fluffynuts
Copy link
Contributor Author

Googling around a bit, it looks like this is taken care of by libuv, which node is using to deal with ansi color escape sequences on Windows, where the console has traditionally not dealt with those sequences. I happen to know that traditional win32 color console output is tedious, having done it enough from c and c#.
We get to see the sequences in tests before they are handed off to the system lower down, where they are available. It's reasonable to assume that the workaround may have previously been dealt with higher up in an older version of colors.
The question you have to consider is what minimum version of node you'd like to be supported for running tests (as this obviously doesn't affect runtime). On *nix, it won't matter, and conceivably, sometime in the future, cmd.exe may support these codes since Microsoft is punting the embedded Linux idea.
It's really up to your preference: either adding the information about test running to the README.md to avoid confusion by anyone else down the line, or if we can figure out the exact version at which the switch happens, creating conditional tests based on node version and platform being win32.
Your call.

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.

3 participants