-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: enable successive calls in the same process
The `report` module was using a shared report object which was mutated all along the checking process. When calling `ace.js` multiple times sequentially, that shared report object wasn't cleaned and the later runs inherited the assertions from the previous runs. The `report` module now exports a single `EPUB` class, with no shared state. The report is passed along the checking process, up until the `checkSingle` method. After all documents are checked, we consolidate the individual results and add them to the given report object. Also add some integration tests for checking the JSON report.
- Loading branch information
Showing
8 changed files
with
171 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
'use strict'; | ||
|
||
const checker = require('./checker-nightmare.js'); | ||
const report = require('../report/report.js'); | ||
const winston = require('winston'); | ||
|
||
function finalize(results) { | ||
function finalize(results, report) { | ||
// Copy assertions | ||
results | ||
.filter(res => res.assertions != null) | ||
.forEach(res => report.addContentDocAssertion(res.assertions)); | ||
// Get a flat array of all the headings in the documents | ||
const headings = [].concat(...results.map(single => single.outlines.headings)); | ||
const headings = [] | ||
.concat(...results.map(docResult => docResult.outlines.headings)) | ||
.filter(e => e !== undefined); | ||
report.addHeadings(headings); | ||
// Aggregated array of the HTML outlines | ||
const htmlOutlines = results.map(single => single.outlines.html); | ||
const htmlOutlines = results.map(docResult => docResult.outlines.html); | ||
report.addHTMLOutlines(htmlOutlines); | ||
// Get a flat array of the extracted images | ||
const images = [].concat(...results.map(single => single.data.images)); | ||
const images = [] | ||
.concat(...results.map(docResult => docResult.data.images)) | ||
.filter(e => e !== undefined); | ||
report.addImages(images); | ||
return results; | ||
return report; | ||
} | ||
|
||
module.exports.check = function check(epub) { | ||
module.exports.check = function check(epub, report) { | ||
winston.info('Checking documents...'); | ||
return checker.check(epub) | ||
.then(results => finalize(results)); | ||
.then(results => finalize(results, report)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.