Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix archiver zip issue with node >16 #64

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,5 @@ Third-party libraries
The following third-party libraries are used by this module:

* express: https://github.com/visionmedia/express - to implement the middleware
* archiver: https://github.com/ctalkington/node-archiver - for zip functionality
* admZip: https://www.npmjs.com/package/adm-zip - for zip functionality

39 changes: 17 additions & 22 deletions lib/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ var path = require('path'),
ASSETS_DIR = istanbul.assetsDir,
existsSync = fs.existsSync || path.existsSync,
url = require('url'),
archiver = require('archiver'),
ZipWriter = require('./zip-writer'),
express = require('express'),
Report = istanbul.Report,
Collector = istanbul.Collector,
utils = istanbul.utils,
JS_RE = /\.js$/;

JS_RE = /\.js$/,
AdmZip = require("adm-zip");
/**
* Set default max limit to 100mb for incoming JSON and urlencoded
* @type {String}
Expand Down Expand Up @@ -88,30 +87,26 @@ function createHandler(opts) {

//send self-contained download package with coverage and reports on /download
app.get('/download', function (req, res) {
var stream = archiver.createZip(),
writer = new ZipWriter(stream, process.cwd()),
coverageObject = core.getCoverageObject() || {},
collector = new Collector(),
baseDir = process.cwd(),
reports = [
Report.create('html', { writer: writer, dir: path.join(baseDir, 'lcov-report') }),
Report.create('lcovonly', { writer: writer, dir: baseDir })
];

let stream = new AdmZip();
const coverageObject = core.getCoverageObject() || {};
const collector = new Collector();
const baseDir = process.cwd();
utils.removeDerivedInfo(coverageObject);
collector.add(coverageObject);

res.statusCode = 200;
res.setHeader('Content-type', 'application/zip');
res.setHeader('Content-Disposition', 'attachment; filename=coverage.zip');
stream.pipe(res);
writer.writeFile('coverage.json', function (w) {
w.write(JSON.stringify(coverageObject, undefined, 4));
});
reports.forEach(function (report) {
report.writeReport(collector);
stream.addFile('coverage.json',Buffer.from(JSON.stringify(coverageObject, undefined, 4), "utf8") );
const lcov = Report.create('lcovonly',{ dir: baseDir })
const html= Report.create('html',{ dir: path.join(baseDir, 'lcov-report') })
html.writeReport(collector);
lcov.writeReport(collector);
html.on('done', function () {
stream.addLocalFile(baseDir+'/lcov.info','');
stream.addLocalFolder(baseDir+'/lcov-report','lcov-report');
const output ="coverage.zip";
fs.writeFileSync(output, stream.toBuffer());
res.download(output);
});
writer.done();
});

//merge client coverage posted from browser
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"istanbul": "0.4.x",
"express": "4.x",
"body-parser": "~1.12.3",
"archiver": "0.14.x"
"archiver": "0.14.x",
"adm-zip": "^0.5.9"
},
"devDependencies": {
"mkdirp": "*",
Expand Down