Skip to content

Commit

Permalink
test: fixing test for node 7 / 8
Browse files Browse the repository at this point in the history
  • Loading branch information
mklabs committed Oct 5, 2018
1 parent e477705 commit 1fdaa8c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
17 changes: 16 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"test": "{lib,test}/**/*.js"
},
"devDependencies": {
"assert-rejects": "^1.0.0",
"auto-changelog": "^1.8.0",
"c8": "^3.2.0",
"coveralls": "^3.0.2",
Expand Down
3 changes: 3 additions & 0 deletions test/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const {
} = require('../lib/installer');
const { COMPLETION_DIR } = require('../lib/constants');

// For node 7 / 8
assert.rejects = require('./utils/rejects');

const readFile = promisify(fs.readFile);

describe('installer', () => {
Expand Down
9 changes: 6 additions & 3 deletions test/tabtab-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const { COMPLETION_DIR } = require('../lib/constants');

const readFile = promisify(fs.readFile);

// For node 7 / 8
assert.rejects = require('./utils/rejects');

// inquirer-test needs a little bit more time, or my setup
const TIMEOUT = 500;
const { ENTER } = run;
Expand All @@ -19,18 +22,18 @@ describe('tabtab.install()', () => {
assert.equal(typeof tabtab.install, 'function');
});

it('throws on missing options', async () => {
it('rejects on missing options', async () => {
await assert.rejects(async () => tabtab.install(), TypeError);
});

it('throws on missing name options', async () => {
it('rejects on missing name options', async () => {
await assert.rejects(
async () => tabtab.install({}),
/options\.name is required/
);
});

it('throws on missing completer options', async () => {
it('rejects on missing completer options', async () => {
await assert.rejects(
async () => tabtab.install({ name: 'foo' }),
/options\.completer is required/
Expand Down
27 changes: 27 additions & 0 deletions test/utils/rejects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// For node 7 / 8
module.exports = async (promise, error, message = '') => {
let toThrow;
await promise().catch(err => {
if (error instanceof RegExp) {
const ok = error.test(err.message);
if (!ok) {
toThrow = new Error(
`AssertionError: ${error} is not validated
${message}`
);
}
} else {
const ok = err instanceof error;
if (!ok) {
toThrow = new Error(
`AssertionError: ${err.name} is not an instanceof ${error.name}
${message}`
);
}
}
});

if (toThrow) {
throw toThrow;
}
};

0 comments on commit 1fdaa8c

Please sign in to comment.