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

feat(reporter): add config formatError function #2313

Merged

Conversation

levithomason
Copy link
Contributor

Fixes #2119. This PR allows a formatError config function. The function receives the entire error message as its only argument. It returns the new error message.

@@ -41,6 +41,10 @@ var processArgs = function (argv, options, fs, path) {
options.failOnEmptyTestSuite = options.failOnEmptyTestSuite === 'true'
}

if (helper.isString(options.formatError)) {
options.formatError = options.formatError = require(options.formatError)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

CLI support via requiring a path that exports a formatError() function.

@levithomason
Copy link
Contributor Author

I'd fix/add tests if I could, but they are failing when I run them on master as well:

Error: Cannot find module 'karma/lib/preprocessor'

The file is clearly there, so I'm not sure what is going on. I'm running node v6.2.1/npm v3.9.3.

Full output:

Running "test:unit" (test) task

Running "mochaTest:unit" (mochaTest) task


  ․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․
  ․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․
  ․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․
  ․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․
  ․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․
  ․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․
  ․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․
  ․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․

  454 passing (2s)
  3 pending

Running "test:client" (test) task
Running /Users/levithomason/src/karma/bin/karma start test/client/karma.conf.js --single-run --no-auto-watch --reporters=dots
failed to add custom browserify preprocessor
{ Error: Cannot find module 'karma/lib/preprocessor'
  at Function.Module._resolveFilename (module.js:440:15)
  at Function.Module._load (module.js:388:25)
  at Module.require (module.js:468:17)
  at require (internal/module.js:20:19)
  at Object.<anonymous> (/Users/levithomason/src/karma/node_modules/karma-browserify/lib/preprocessor.js:3:20)
  at Module._compile (module.js:541:32)
  at Object.Module._extensions..js (module.js:550:10)
  at Module.load (/Users/levithomason/src/karma/node_modules/coffee-script/lib/coffee-script/register.js:45:36)
  at tryModuleLoad (module.js:417:12)
  at Function.Module._load (module.js:409:3)
  at Module.require (module.js:468:17)
  at require (internal/module.js:20:19)
  at Object.<anonymous> (/Users/levithomason/src/karma/node_modules/karma-browserify/index.js:29:44)
  at Module._compile (module.js:541:32)
  at Object.Module._extensions..js (module.js:550:10)
  at Module.load (/Users/levithomason/src/karma/node_modules/coffee-script/lib/coffee-script/register.js:45:36)
  at tryModuleLoad (module.js:417:12)
  at Function.Module._load (module.js:409:3)
  at Module.require (module.js:468:17)
  at require (internal/module.js:20:19)
  at requirePlugin (/Users/levithomason/src/karma/lib/plugin.js:15:20)
  at /Users/levithomason/src/karma/lib/plugin.js:30:9
  at Array.forEach (native)
  at Object.exports.resolve (/Users/levithomason/src/karma/lib/plugin.js:27:11)
  at new Server (/Users/levithomason/src/karma/lib/server.js:90:35)
  at Object.exports.run (/Users/levithomason/src/karma/lib/cli.js:266:7)
  at Object.<anonymous> (/Users/levithomason/src/karma/bin/karma:3:23)
  at Module._compile (module.js:541:32)
  at Object.Module._extensions..js (module.js:550:10)
  at Module.load (module.js:458:32)
  at tryModuleLoad (module.js:417:12)
  at Function.Module._load (module.js:409:3)
  at Function.Module.runMain (module.js:575:10)
  at startup (node.js:160:18)
  at node.js:456:3
 code: 'MODULE_NOT_FOUND' }

@levithomason
Copy link
Contributor Author

levithomason commented Aug 15, 2016

It might be worth it to include an option for removing node_modules, and another for removing compiled sources. This are the most common use cases and complaints. We could accept an array or a function. There would be a filter function each option and we'd just map through them. It might look something like:

// some pre-bundled filters
{ formatError: ['remove-node-modules', 'remove-compiled-sources'] }

// or your own function
{ formatError: (msg) => msg }
--format-error remove-node-modules,remove-compiled-sources
--format-error ./some-error-formatter.js

@kahwee
Copy link
Contributor

kahwee commented Aug 16, 2016

Hi @levithomason, I encountered the issue with Error: Cannot find module 'karma/lib/preprocessor' as well and I think one of the steps I did managed to resolve this.

Most likely this is it:

npm run init

@levithomason
Copy link
Contributor Author

Hm, I've never used npm init except to initialize a package.json. Gave it a shot anyway, no luck though.

@kahwee
Copy link
Contributor

kahwee commented Aug 16, 2016

It's npm run init. I forgot you have to run grunt browserify as well.

There are similar instructions in the contribution guide http://karma-runner.github.io/1.0/dev/making-changes.html

Try this:

$ npm install
$ rm -rf node_modules/karma
$ cd node_modules
$ ln -s ../ karma
$ cd ../
$ grunt browserify

@dignifiedquire
Copy link
Member

Yes, to get all the tests being actually run properly make sure to do the linking part as mentioned above.

@levithomason levithomason deleted the feature/format-error branch August 16, 2016 15:33
@levithomason levithomason restored the feature/format-error branch August 16, 2016 15:42
@levithomason levithomason reopened this Aug 16, 2016
@levithomason levithomason force-pushed the feature/format-error branch 3 times, most recently from b78e306 to caec040 Compare August 16, 2016 18:29
@levithomason
Copy link
Contributor Author

@dignifiedquire I believe it's ready for review. Tests and linting passed locally, just rebased to master.

@levithomason
Copy link
Contributor Author

@dignifiedquire I understand busy. Do you have any ETA on this PR?

@dignifiedquire
Copy link
Member

Sorry for the delay, will review this week

@levithomason
Copy link
Contributor Author

Much appreciated, thanks.

@levithomason
Copy link
Contributor Author

Rebased to latest master.

@@ -41,6 +41,16 @@ var processArgs = function (argv, options, fs, path) {
options.failOnEmptyTestSuite = options.failOnEmptyTestSuite === 'true'
}

if (helper.isString(options.formatError)) {
var required = require(options.formatError)
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to wrap this into a try catch and provide a helpful error message if it fails.

@levithomason
Copy link
Contributor Author

@dignifiedquire ready for review

@levithomason
Copy link
Contributor Author

Tests pass locally and the CI failure seem odd Uncaught CancellationError: cancellation error.

@levithomason
Copy link
Contributor Author

Retried the build via PR close/open to no avail, still getting this:

The command "if [ "${VALIDATE_COMMIT_MSG}" != "TRUE" ]; then npm run travis; else ./scripts/validate-commit-msg.sh "${TRAVIS_COMMIT}"; fi" exited with 1.

I edited the commit that removed the package.json git hooks and force pushed it. I'm wondering if CI is somehow confused on the force pushed history?

@dignifiedquire
Copy link
Member

Looking at the CI failures they look like valid test failures

@levithomason
Copy link
Contributor Author

Hm, the only change was replacing the package.json hooks. Also, tests pass locally. So I'm not sure what else to try there. Ideas?

@dignifiedquire
Copy link
Member

Restarted them, lets see what happens

@levithomason
Copy link
Contributor Author

@dignifiedquire looks like we're good to go.

@levithomason
Copy link
Contributor Author

@dignifiedquire bump, this is labeled needs feedback but actually needs review.

@dignifiedquire dignifiedquire merged commit 98a4fbf into karma-runner:master Sep 7, 2016
@dignifiedquire
Copy link
Member

@levithomason sorry about that, forgot that it was already green :)

@levithomason
Copy link
Contributor Author

No worries, thanks for the quick response and merge. When do you suspect this will get released?

@levithomason levithomason deleted the feature/format-error branch September 7, 2016 15:54
@dignifiedquire
Copy link
Member

I think I will make a release later today

@levithomason
Copy link
Contributor Author

Fantastic, thanks much. This is going to improve our workflow dramatically.

@donaldpipowitch
Copy link

This is awesome!

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.

4 participants