Skip to content

Commit

Permalink
feat(tests): add minimal integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeltour committed Sep 28, 2017
1 parent bd7d6cb commit 7d087cd
Show file tree
Hide file tree
Showing 5 changed files with 665 additions and 234 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module.exports = {
"extends": "airbnb-base",
"env": {
"jest": true
},
"rules": {
"no-console": 0
},
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"eslint": "^3.19.0",
"eslint-config-airbnb-base": "^11.2.0",
"eslint-plugin-import": "^2.3.0",
"jest": "^20.0.3",
"jest": "^21.1.0",
"rimraf": "^2.6.1",
"uglify-js": "^3.0.8",
"watch": "^1.0.2"
Expand All @@ -82,9 +82,12 @@
"build": "yarn run build:js",
"build:js": "cp -R src/ dist",
"build:watch": "watch 'yarn run build' src",
"test": "echo add tests",
"test": "jest",
"docs": "echo add docs",
"lint": "eslint src",
"dist": "echo add dist"
},
"jest": {
"testEnvironment": "node"
}
}
45 changes: 45 additions & 0 deletions tests/__tests__/report_files.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict';

const fs = require('fs');
const path = require('path');
const tmp = require('tmp');

const ace = require('../../src/core/ace.js');

let outdir;
let tmpdir;

tmp.setGracefulCleanup();

beforeEach(() => {
outdir = tmp.dirSync({ prefix: 'ace_out_', unsafeCleanup: true });
tmpdir = tmp.dirSync({ prefix: 'ace_tmp_', unsafeCleanup: true });
});

afterEach(() => {
outdir.removeCallback();
tmpdir.removeCallback();
});

function runAce(epub) {
return ace(epub, {
cwd: process.cwd(),
outdir: outdir.name,
tmpdir: tmpdir.name,
verbose: true,
silent: true,
});
}

test('unexisting EPUB fails with an error', () => {
expect.assertions(1);
return expect(runAce('noepub'))
.rejects.toMatch('');
});

test('report dir is correctly created', async () => {
expect.assertions(1);
return runAce(path.join(__dirname, '../data/base-epub-30.epub')).then(() => {
expect(fs.existsSync(path.join(outdir.name, 'report.html'))).toBeTruthy();
});
});
Binary file added tests/data/base-epub-30.epub
Binary file not shown.
Loading

0 comments on commit 7d087cd

Please sign in to comment.