Skip to content

Commit 51b1bd6

Browse files
committed
Fix headless test failure with zip on exit
1 parent bc2bd20 commit 51b1bd6

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

headless_zip.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,27 +79,31 @@ module.exports.headlessZip = function headlessZip(dirToZip) {
7979
deleteFile(earliest)
8080
}
8181

82-
var zip = new JSZip();
83-
var files = fs.readdirSync(dirToZip)
84-
for (var i = 0, len = files.length; i < len; i++) {
85-
zip.file(files[i], fs.readFileSync(path.join(dirToZip, files[i])), {compression : "DEFLATE"})
82+
if(fs.existsSync(dirToZip)) {
83+
var zip = new JSZip();
84+
var files = fs.readdirSync(dirToZip)
85+
for (var i = 0, len = files.length; i < len; i++) {
86+
zip.file(files[i], fs.readFileSync(path.join(dirToZip, files[i])), {compression : "DEFLATE"})
87+
}
88+
fs.writeFileSync(outputFileName, zip.generate({type:"nodebuffer", compression:'DEFLATE'}));
89+
deleteDir(dirToZip)
8690
}
87-
fs.writeFileSync(outputFileName, zip.generate({type:"nodebuffer", compression:'DEFLATE'}));
88-
deleteDir(dirToZip)
8991
}
9092

9193
module.exports.tryZipOnExit = function tryZipOnExit() {
9294
var outputDir = dirToWriteTo;
9395
if(!outputDir) {
9496
ouputDir = process.cwd().toString()
9597
}
96-
var files = fs.readdirSync(outputDir);
97-
// Search for temporary output directory using pattern matching
98-
for (var i = 0, len = files.length; i < len; i++) {
99-
if(/tmp_(\w+)/.test(files[i].toString())) {
100-
var dirToZip = path.join(outputDir, files[i])
101-
this.headlessZip(dirToZip)
102-
return;
98+
if(fs.existsSync(outputDir)) {
99+
var files = fs.readdirSync(outputDir);
100+
// Search for temporary output directory using pattern matching
101+
for (var i = 0, len = files.length; i < len; i++) {
102+
if(/tmp_(\w+)/.test(files[i].toString())) {
103+
var dirToZip = path.join(outputDir, files[i])
104+
this.headlessZip(dirToZip)
105+
return;
106+
}
103107
}
104108
}
105109
}

tests/headless_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ tap.test('Headless mode should produce a .hcd file', function(t) {
5757
});
5858

5959
function cleanUp() {
60-
app.endRun();
6160
deleteDir(outputDir);
61+
app.endRun();
6262
}
6363

6464
function deleteDir(directory) {

0 commit comments

Comments
 (0)