Skip to content

Commit

Permalink
convert test/integration/regression.spec.js to unexpected
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Hiller <boneskull@boneskull.com>
  • Loading branch information
boneskull committed Apr 21, 2018
1 parent e9eb05e commit 77203bf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 38 deletions.
4 changes: 2 additions & 2 deletions test/integration/fixtures/regression/issue-1417.fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ it('fails exactly once when a global error is thrown synchronously and done erro
done(new Error('test error'));
}, 1); // Not 0 - it will 'succeed', but won't test the breaking condition

throw new Error('sync error');
throw new Error('sync error a');
});

it('fails exactly once when a global error is thrown synchronously and done completes', function (done) {
setTimeout(function () {
done();
}, 1); // Not 0 - it will 'succeed', but won't test the breaking condition

throw new Error('sync error');
throw new Error('sync error b');
});
64 changes: 28 additions & 36 deletions test/integration/regression.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

var assert = require('assert');
var fs = require('fs');
var path = require('path');
var run = require('./helpers').runMocha;
Expand All @@ -19,20 +18,19 @@ describe('regressions', function () {
done(err);
return;
}
assert.equal(occurences('testbody1'), 1);
assert.equal(occurences('testbody2'), 1);
assert.equal(occurences('testbody3'), 1);

assert.equal(res.code, 1);
expect(res, 'to have failed');
expect(occurences('testbody1'), 'to be', 1);
expect(occurences('testbody2'), 'to be', 1);
expect(occurences('testbody3'), 'to be', 1);
done();
});
});

it('should not duplicate mocha.opts args in process.argv', function () {
var processArgv = process.argv.join('');
var mochaOpts = fs.readFileSync(path.join(__dirname, '..', 'mocha.opts'), 'utf-8').split(/[\s]+/).join('');
assert.notEqual(processArgv.indexOf(mochaOpts), -1, 'process.argv missing mocha.opts');
assert.equal(processArgv.indexOf(mochaOpts), processArgv.lastIndexOf(mochaOpts), 'process.argv contains duplicated mocha.opts');
expect(processArgv.indexOf(mochaOpts), 'not to be', -1)
.and('to be', processArgv.lastIndexOf(mochaOpts));
});

it('issue-1794: Can\'t --require custom UI and use it', function (done) {
Expand All @@ -43,7 +41,7 @@ describe('regressions', function () {
done(err);
return;
}
assert.equal(res.code, 0, 'Custom UI should be loaded');
expect(res, 'to have passed');
done();
});
});
Expand All @@ -58,21 +56,21 @@ describe('regressions', function () {
done(err);
return;
}
assert.equal(/process out of memory/.test(res.output), false, 'fixture\'s process out of memory!');
assert.equal(res.code, 0, 'Runnable fn (it/before[Each]/after[Each]) references should be deleted to avoid memory leaks');
expect(res, 'not to contain output', 'process out of memory')
.and('to have passed');
done();
});
});

describe('issue-2286: after doesn\'t execute if test was skipped in beforeEach', function () {
describe("issue-2286: after doesn't execute if test was skipped in beforeEach", function () {
var afterWasRun = false;
describe('suite with skipped test for meta test', function () {
beforeEach(function () { this.skip(); });
after(function () { afterWasRun = true; });
it('should be pending', function () {});
});
after('meta test', function () {
expect(afterWasRun).to.be.ok();
expect(afterWasRun, 'to be', true);
});
});

Expand All @@ -82,10 +80,9 @@ describe('regressions', function () {
done(err);
return;
}
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 0);
assert.equal(res.stats.failures, 1);
assert.equal(res.code, 1);
expect(res, 'to have failed')
.and('not to have pending tests')
.and('to have failed test count', 1);
done();
});
});
Expand All @@ -97,10 +94,9 @@ describe('regressions', function () {
done(err);
return;
}
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 2);
assert.equal(res.stats.failures, 0);
assert.equal(res.code, 0);
expect(res, 'to have passed')
.and('not to have pending tests')
.and('to have passed test count', 2);
done();
});
});
Expand All @@ -111,10 +107,9 @@ describe('regressions', function () {
done(err);
return;
}
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 1);
assert.equal(res.stats.failures, 0);
assert.equal(res.code, 0);
expect(res, 'to have passed')
.and('not to have pending tests')
.and('to have passed test count', 1);
done();
});
});
Expand All @@ -125,17 +120,14 @@ describe('regressions', function () {
done(err);
return;
}
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 0);
assert.equal(res.stats.failures, 2);

assert.equal(res.failures[0].title,
'fails exactly once when a global error is thrown synchronously and done errors');
assert.equal(res.failures[0].err.message, 'sync error');
assert.equal(res.failures[1].title,
'fails exactly once when a global error is thrown synchronously and done completes');
assert.equal(res.failures[1].err.message, 'sync error');
assert.equal(res.code, 2);
expect(res, 'to have failed with errors', 'sync error a', 'sync error b')
.and('to have exit code', 2)
.and('not to have passed tests')
.and('not to have pending tests')
.and('to have failed test order', [
'fails exactly once when a global error is thrown synchronously and done errors',
'fails exactly once when a global error is thrown synchronously and done completes'
]);
done();
});
});
Expand Down

0 comments on commit 77203bf

Please sign in to comment.