From 78ce1e5fca492b7ab6b47bcfa0f34bf0d98ce2cf Mon Sep 17 00:00:00 2001 From: William Marlow Date: Wed, 29 Sep 2021 10:51:42 +0100 Subject: [PATCH 1/2] Fix unit test failure when running on macOS 11 --- .gitignore | 3 +++ tests/api_tests.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 197a8326..446d606a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,6 @@ headlesstestoutput* .nyc_output/ package-lock.json resourceRegistry.log +libagentcore.dylib +nodejs_dc.log +nodejs_restclient.log diff --git a/tests/api_tests.js b/tests/api_tests.js index d136181e..39dc5fe1 100644 --- a/tests/api_tests.js +++ b/tests/api_tests.js @@ -237,7 +237,7 @@ monitor.once('initialized', function() { function runCommonEnvTests(commonEnvData, t) { var ARCHS = ['x86', 'x86_64', 'ppc32', 'ppc64', 'ppc64le', 's390', 's390x']; var ZOS_ARCHS = ['3906', '2964', '2965', '2827', '2828', '2817', '2818']; - var OSES = ['AIX', 'Linux', 'Windows', 'Mac OS X', 'OS/390']; + var OSES = ['AIX', 'Linux', 'Windows', 'Mac OS X', 'macOS', 'OS/390']; t.ok(ARCHS.indexOf(commonEnvData['os.arch']) != -1, 'Contains a recognised value for os.arch', skipIfzOS); t.ok(ZOS_ARCHS.indexOf(commonEnvData['os.arch']) != -1, 'Contains a recognised value for z/OS os.arch', skipIfNotzOS); From d392ab0dfe90955b519502fe8a8460cc6b8588e7 Mon Sep 17 00:00:00 2001 From: William Marlow Date: Wed, 29 Sep 2021 10:52:14 +0100 Subject: [PATCH 2/2] Upgrade jszip to 3.x. Fixes #655 --- .eslintrc | 3 ++- headless_zip.js | 22 ++++++++++++++-------- package.json | 6 +++--- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/.eslintrc b/.eslintrc index 9f9ba6b9..f96d0095 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,7 +1,8 @@ { "extends": "strongloop", "env": { - "node": true + "node": true, + "es6": true }, "parserOptions": { "ecmaVersion": 6 }, "rules": { diff --git a/headless_zip.js b/headless_zip.js index dfb49037..9dab1964 100644 --- a/headless_zip.js +++ b/headless_zip.js @@ -16,6 +16,7 @@ 'use strict'; var fs = require('fs'); +var fsPromise = require('fs/promises'); var path = require('path'); var JSZip = require('jszip'); @@ -85,14 +86,19 @@ module.exports.headlessZip = function headlessZip(dirToZip) { if (fs.existsSync(dirToZip)) { var zip = new JSZip(); - var files = fs.readdirSync(dirToZip); - for (var i = 0, len = files.length; i < len; i++) { - zip.file(files[i], fs.readFileSync(path.join(dirToZip, files[i])), { - compression: 'DEFLATE', - }); - } - fs.writeFileSync(outputFileName, zip.generate({ type: 'nodebuffer', compression: 'DEFLATE' })); - deleteDir(dirToZip); + + fsPromise.readdir(dirToZip) + .then(files => { + let getFileAndContents = file => fsPromise.readFile(path.join(dirToZip, file)) + .then(contents => { return { file, contents }; }); + return Promise.all(files.map(getFileAndContents)); + }) + .then(files => { + files.forEach(({file, contents}) => zip.file(file, contents, {compression: 'DEFLATE'})); + return zip.generateAsync({type: 'nodebuffer', compression: 'DEFLATE'}); + }) + .then(buffer => fsPromise.writeFile(outputFileName, buffer)) + .then(() => { deleteDir(dirToZip); }); } }; diff --git a/package.json b/package.json index d7c5c817..dedca4ae 100644 --- a/package.json +++ b/package.json @@ -6,12 +6,12 @@ }, "description": "Node Application Metrics", "dependencies": { + "ibmapm-embed": ">=19.9.0", + "jszip": "^3.7.1", "nan": "2.x", "node-gyp": "5.x", - "tar": "4.x", "semver": "^5.3.0", - "jszip": "2.5.x", - "ibmapm-embed": ">=19.9.0" + "tar": "4.x" }, "devDependencies": { "codecov": "^3.1.0",