Skip to content

Commit

Permalink
fix: support checking unpackaged EPUB passed as relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeltour committed Oct 2, 2017
1 parent 54ebf5b commit 2268ba5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/core/ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ module.exports = function ace(epubPath, options) {
winston.verbose("ACE", options);

// Check that the EPUB exists
if (!fs.existsSync(epubPath)) {
const epubPathResolved = path.resolve(options.cwd, epubPath);
if (!fs.existsSync(epubPathResolved)) {
winston.error(`Couldn’t find EPUB file '${epubPath}'`);
return reject(jobId);
}
Expand Down Expand Up @@ -48,7 +49,7 @@ module.exports = function ace(epubPath, options) {
/* eslint-enable no-param-reassign */

// Unzip the EPUB
const epub = new EPUB(epubPath);
const epub = new EPUB(epubPathResolved);
epub.extract()
.then(() => epub.parse())
// initialize the report
Expand Down
16 changes: 14 additions & 2 deletions tests/__tests__/report_files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,30 @@ test('unexisting EPUB fails with an error', () => {
.rejects.toMatch('');
});

test('report dir is correctly created', async () => {
test('packaged EPUB with absolute path', async () => {
expect.assertions(1);
await runAce(path.join(__dirname, '../data/base-epub-30.epub'));
expect(fs.existsSync(path.join(outdir.name, 'report.html'))).toBeTruthy();
});

test('expanded EPUBs are supported', async () => {
test('packaged EPUB with relative path', async () => {
expect.assertions(1);
await ace('tests/data/base-epub-30.epub', { cwd: path.join(__dirname, '../..') });
expect(fs.existsSync(path.join(outdir.name, 'report.html'))).toBeTruthy();
});

test('expanded EPUB with absolute path', async () => {
expect.assertions(1);
await runAce(path.join(__dirname, '../data/base-epub-30'));
expect(fs.existsSync(path.join(outdir.name, 'report.html'))).toBeTruthy();
});

test('expanded EPUB with relative path', async () => {
expect.assertions(1);
await ace('tests/data/base-epub-30', { cwd: path.join(__dirname, '../..') });
expect(fs.existsSync(path.join(outdir.name, 'report.html'))).toBeTruthy();
});

test('files don’t leak outside the report dir', async () => {
// Add another directory level to prevent any leak in the user's temp dir
const outpath = path.join(outdir.name, 'report');
Expand Down

0 comments on commit 2268ba5

Please sign in to comment.