Git Product home page Git Product logo

ember-qunit-nice-errors's Introduction

ember-qunit-nice-errors

Build Status

Because expected true, result false is not enough!

This addon aims to improve the testing experience by defining a nice message on those asserts that don't have one set by you.

Installation

As easy as ember install ember-qunit-nice-errors

Example

When you have a test with a failing assertion and no custom message, the default error doesn't say much. As you can see by the following example test and the default ouput below:

import { module, test } from 'qunit';

module('Unit | ok test');

test('it works', function(assert) {
  assert.ok(1===3);
});

Test failed output without addon

But with ember-qunit-nice-errors the message is way nicer! Test failed output with addon

Configuration

showFileInfo

If you want your error messages to include the original test file, line and column where the failed assertion is, just add the following configuration on your config/environment.js file:

ENV['ember-qunit-nice-errors'] = {
  showFileInfo: true
};
Before
assert.ok(false)
After
assert.ok(false) at my-app/tests/unit/ok-test.js:17:2

Also note you can enable this only for certain environments:

if (environment === 'development') {
  ENV['ember-qunit-nice-errors'] = {
    showFileInfo: true
  };
}

completeExistingMessages

If you fully trust us you can add this option to replace all assertions within your project tests, just add this to your configuration on your config/environment.js file:

ENV['ember-qunit-nice-errors'] = {
  completeExistingMessages: true
};

Don't worry, the override will still show your orginal messages, it is not a destructive operation!

The following example illustrates what is the result of using the option completeExistingMessages.

Before
assert.ok(1 === 1, 'one should be one');
After
assert.ok(1 === 1, "assert.ok(1 === 1, 'one should be one')");

include

By default only test files that match the glob **/*-test.js are processed by the addon. You can include/exclude files from being processed by setting custom glob rules.

ENV['ember-qunit-nice-errors'] = {
  include: ["**/*-foo.js"]
};

Note that by changing the include configuration you are overriding the default glob **/*-test.js. If you want to include files and keep the default rules, you can write it as follows.

ENV['ember-qunit-nice-errors'] = {
  include: [
    "**/*-test.js",
    "**/*-foo.js",
  ]
};

You can use any expression supported by minimatch, see https://www.npmjs.com/package/minimatch for more info.

exclude

You can exclude specific test files from beign processed by adding exclude rules.

ENV['ember-qunit-nice-errors'] = {
  exclude: ["**/my-special-test.js"]
};

You can use any expression supported by minimatch, see https://www.npmjs.com/package/minimatch for more info.

Supported assertions

We are currently supporting all the assertions provided by QUnit, those are:

  • ok
  • notOk
  • equal
  • notEqual
  • deepEqual
  • notDeepEqual
  • propEqual
  • notPropEqual
  • strictEqual
  • notStrictEqual

Maintainers

Credits

We got inspiration from

License

ember-qunit-nice-errors is licensed under the MIT license.

See LICENSE for the full license text.

ember-qunit-nice-errors's People

Contributors

acostami avatar ember-tomster avatar fedekau avatar jmbejar avatar knownasilya avatar marpo60 avatar panthony avatar patocallaghan avatar san650 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ember-qunit-nice-errors's Issues

Add option to add human readable messages to assertions

Right now messages are ok for developers, but probable not so good for normal people (Developers are not normal by default, and you know that!), for example assert.equal('Hello', 'Good bye') could be replaced by Comparing if 'Hello' is equal to 'Good bye'.

This would play nicely with this amazing addon telling-stories

Doesn't work properly with ember-cli-chai

Problem

Chai assertion expect(3).to.equal(3); replaces with expect(3).to.equal('expect(3).to.equal(3) at my-app/tests/unit/mixins/foo-test.js:x:x');

I don't pretend to have nice errors for chai assertions, at least ember-qunit-nice-errors shouldn't touch them.

Details

$ npm ls ember-cli-chai ember-qunit-nice-errors
├── [email protected] 
└── [email protected] 
// config/environment.js
'ember-qunit-nice-errors': {
  showFileInfo: true,
  completeExistingMessages: true
},
// /tests/unit/mixins/foo-test.js
import { module, test } from 'qunit';
import { withChai } from 'ember-cli-chai/qunit';

module('Unit | Mixin | foo');

test('it works', withChai(function(expect, assert) {
  expect(3).to.equal(3);
}));
$ ember test -> 

Failed.
expected 3 to equal 'expect(3).to.equal(3) at my-app/tests/unit/mixins/foo-test.js:x:x'@ 5 ms
Expected: "expect(3).to.equal(3) at my-app/tests/unit/mixins/foo-test.js:x:x"
Result: 3

Publish security updates

Currently the latest release is version 1.2.0 which dates back to January 2018. Between then and now some commits were made to this repository, mostly regarding package updates. Some of these updates also resolved active security issues. Unfortunately these changes aren't published. Would it maybe be possible to create a new release from the current master branch? Therefore enabling consumers to update and benefit from these changes.

Ignore files where parsing error occur

It would be nice to have an option, for example ignoreOnError, that forces the addon to ignore files where parsing errors occur.

This in combination with #20 would allow to use the addon even if some files can't be processed.

Any thoughts? Should this option be true by default?

Doesn't work with async/await in Ember 3.0 tests

file changed integration/components/primary-nav/component-test.js
Build Error (TestTransformFilter) in map/tests/integration/components/primary-nav/component-test.js

Line 13: Unexpected identifier

Arrow functions

It doesn't seem to work in Acceptance tests with Ember 3.9 + ember-qunit: 3.5.3

Does not support async/await

There was some test files that were completely ignored by ember-qunit-nice-errors and I did not understood why.

It turned out that is silently fails during transform:

{ Error: Line 42: Unexpected identifier
    at ErrorHandler.constructError (/Users/anthony/dev/cogniteev/oncrawl-web-client/node_modules/ember-qunit-nice-errors/node_modules/esprima/dist/esprima.js:3396:22)
    at ErrorHandler.createError (/Users/anthony/dev/cogniteev/oncrawl-web-client/node_modules/ember-qunit-nice-errors/node_modules/esprima/dist/esprima.js:3414:27)
    at JSXParser.Parser.unexpectedTokenError (/Users/anthony/dev/cogniteev/oncrawl-web-client/node_modules/ember-qunit-nice-errors/node_modules/esprima/dist/esprima.js:542:39)
    at JSXParser.Parser.throwUnexpectedToken (/Users/anthony/dev/cogniteev/oncrawl-web-client/node_modules/ember-qunit-nice-errors/node_modules/esprima/dist/esprima.js:552:21)
    at JSXParser.Parser.consumeSemicolon (/Users/anthony/dev/cogniteev/oncrawl-web-client/node_modules/ember-qunit-nice-errors/node_modules/esprima/dist/esprima.js:845:23)
    at JSXParser.Parser.parseLexicalDeclaration (/Users/anthony/dev/cogniteev/oncrawl-web-client/node_modules/ember-qunit-nice-errors/node_modules/esprima/dist/esprima.js:1892:15)
    at JSXParser.Parser.parseStatementListItem (/Users/anthony/dev/cogniteev/oncrawl-web-client/node_modules/ember-qunit-nice-errors/node_modules/esprima/dist/esprima.js:1815:69)
    at JSXParser.Parser.parseFunctionSourceElements (/Users/anthony/dev/cogniteev/oncrawl-web-client/node_modules/ember-qunit-nice-errors/node_modules/esprima/dist/esprima.js:2586:29)
    at JSXParser.Parser.parseFunctionExpression (/Users/anthony/dev/cogniteev/oncrawl-web-client/node_modules/ember-qunit-nice-errors/node_modules/esprima/dist/esprima.js:2763:26)
    at JSXParser.Parser.parsePrimaryExpression (/Users/anthony/dev/cogniteev/oncrawl-web-client/node_modules/ember-qunit-nice-errors/node_modules/esprima/dist/esprima.js:931:38)
  index: 1717,
  lineNumber: 42,
  description: 'Unexpected identifier' }

On lines such as:

  let model = await subject.model();

The currently used version of recast is using [email protected] whereas the async/await support was introduced (from what I found) in [email protected].

The latest version of recast does use [email protected].

Is there a way to remove the stack trace and improve the actual/expected messages?

Today errors look like this:

Integration | Component | x-form/x-radio-set: it should render a label if provided
    ✘ assert.equal(this.$('[for$="-input"]').text().trim(), 'Subject') at dummy/tests/integration/components/x-form/x-radio-set-test.js:60:4
            at Object.<anonymous> (http://localhost:7357/assets/tests.js:802:10)
            at runTest (http://localhost:7357/assets/test-support.js:4108:30)
            at Test.run (http://localhost:7357/assets/test-support.js:4094:6)
            at http://localhost:7357/assets/test-support.js:4300:12
            at Object.advance (http://localhost:7357/assets/test-support.js:3746:26)
            at begin (http://localhost:7357/assets/test-support.js:5567:20)
         expected Subject

Would be nicer and cleaner to show something like this:

Integration | Component | x-form/x-radio-set: it should render a label if provided
    ✘ assert.equal(this.$('[for$="-input"]').text().trim(), 'Subject') at dummy/tests/integration/components/x-form/x-radio-set-test.js:60:4
         expected Subject

Also would be even nicer to force it to always show the "Actual" value, even if it's null, undefined or '', wrapping it in " so we can tell there is actually a string, or even to tell the difference between 123 and "123".

Integration | Component | x-form/x-radio-set: it should render a label if provided
    ✘ assert.equal(this.$('[for$="-input"]').text().trim(), 'Subject') at dummy/tests/integration/components/x-form/x-radio-set-test.js:60:4
         actual ""
         expected "Subject"

Update examples to use the new testing API

To avoid confusing people, it would be great if we update the examples to use the new ember's testing API

import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

module('Unit | Service | some thing', function(hooks) {
  setupTest(hooks);

  test('should correctly concat foo', function(assert) {
    const someThing = this.owner.lookup('service:some-thing');
    someThing.set('foo', 'baz');

    assert.equal(someThing.get('computedFoo'), 'computed baz');
  });
});

Add override option

Add an option to override all asserts (even if they have a custom message). This would be extremely helpful for large projects that want to use use the messages provided by the addon but don't want to change all the asserts by hand.

Something like:

nicer.json = {
    "override": "true"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.