Browse Source

consistent error determination

The child processes determine whether the test had an error based on its `error`
property not being `undefined`. However they then change this property to an
empty object if there was no error.

The API determines whether a test had an error based on its (empty) error object
having a `message` property. If a test did not have an error, its `error`
property is set to `null`. This prevents errors without messages from being
reported correctly.

Instead set `error` to `null` in the child processes and rely on that in the
API.

I've added a test to validate errors without messages get reported.
babel-plugin-for-integration-tests
Mark Wubben 9 years ago
parent
commit
2bd6ab848b
  1. 6
      api.js
  2. 7
      index.js
  3. 11
      test/api.js
  4. 5
      test/fixture/error-without-message.js
  5. 2
      test/hooks.js

6
api.js

@ -114,9 +114,7 @@ Api.prototype._handleStats = function (stats) {
Api.prototype._handleTest = function (test) {
test.title = this._prefixTitle(test.file) + test.title;
var isError = test.error.message;
if (isError) {
if (test.error) {
if (test.error.powerAssertContext) {
var message = formatter(test.error.powerAssertContext);
@ -132,8 +130,6 @@ Api.prototype._handleTest = function (test) {
}
this.errors.push(test);
} else {
test.error = null;
}
this.emit('test', test);

7
index.js

@ -46,11 +46,14 @@ function test(props) {
return;
}
props.error = hasError ? serializeError(props.error) : {};
if (hasError) {
props.error = serializeError(props.error);
if (props.error.stack) {
props.error.stack = beautifyStack(props.error.stack);
}
} else {
props.error = null;
}
send('test', props);

11
test/api.js

@ -279,6 +279,17 @@ test('uncaught exception will throw an error', function (t) {
});
});
test('errors can occur without messages', function (t) {
t.plan(2);
var api = new Api([path.join(__dirname, 'fixture/error-without-message.js')]);
api.run()
.then(function () {
t.is(api.failCount, 1);
t.is(api.errors.length, 1);
});
});
test('stack traces for exceptions are corrected using a source map file', function (t) {
t.plan(4);

5
test/fixture/error-without-message.js

@ -0,0 +1,5 @@
import test from '../../';
test('throw an error without a message', () => {
throw new Error();
});

2
test/hooks.js

@ -309,7 +309,7 @@ test('don\'t display hook title if it did not fail', function (t) {
fork(path.join(__dirname, 'fixture', 'hooks-passing.js'))
.run()
.on('test', function (test) {
t.same(test.error, {});
t.same(test.error, null);
t.is(test.title, 'pass');
})
.then(function () {

Loading…
Cancel
Save