You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by dp...@apache.org on 2024/08/29 09:33:12 UTC
(cordova-common) branch master updated: chore: Minor test fixes (#211)
This is an automated email from the ASF dual-hosted git repository.
dpogue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-common.git
The following commit(s) were added to refs/heads/master by this push:
new c85b825 chore: Minor test fixes (#211)
c85b825 is described below
commit c85b82585d81cd2806d52a86753c1a3046bddad2
Author: Darryl Pogue <da...@dpogue.ca>
AuthorDate: Thu Aug 29 02:33:08 2024 -0700
chore: Minor test fixes (#211)
* chore(ci): Silence fs.Stats ctor deprecation warning
Do this in the worst way possible because stuff depends on it being an
instance of fs.Stats with the right prototype, but also there's no
supported way to mock create an object of that type... so __proto__
hackery will have to suffice 😬
* chore(ci): Safer temp dir for testing
This should ensure that the directory is always cleaned up after tests
run.
---
package-lock.json | 13 +++++++++++-
package.json | 3 ++-
spec/ConfigChanges/ConfigChanges.spec.js | 7 +++++--
spec/FileUpdater.spec.js | 36 ++++++++++++++++++++++++++++++--
4 files changed, 53 insertions(+), 6 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index 4fcf2b7..e89a873 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -27,7 +27,8 @@
"jasmine": "^4.5.0",
"jasmine-spec-reporter": "^7.0.0",
"nyc": "^15.1.0",
- "rewire": "^6.0.0"
+ "rewire": "^6.0.0",
+ "tmp": "^0.2.3"
},
"engines": {
"node": ">=16.0.0"
@@ -4644,6 +4645,16 @@
"integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==",
"dev": true
},
+ "node_modules/tmp": {
+ "version": "0.2.3",
+ "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.3.tgz",
+ "integrity": "sha512-nZD7m9iCPC5g0pYmcaxogYKggSfLsdxl8of3Q/oIbqCqLLIO9IAF0GWjX1z9NZRHPiXv8Wex4yDCaZsgEw0Y8w==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=14.14"
+ }
+ },
"node_modules/to-fast-properties": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
diff --git a/package.json b/package.json
index 018281b..56b0f2b 100644
--- a/package.json
+++ b/package.json
@@ -35,7 +35,8 @@
"jasmine": "^4.5.0",
"jasmine-spec-reporter": "^7.0.0",
"nyc": "^15.1.0",
- "rewire": "^6.0.0"
+ "rewire": "^6.0.0",
+ "tmp": "^0.2.3"
},
"nyc": {
"all": true,
diff --git a/spec/ConfigChanges/ConfigChanges.spec.js b/spec/ConfigChanges/ConfigChanges.spec.js
index 0d6a241..6085591 100644
--- a/spec/ConfigChanges/ConfigChanges.spec.js
+++ b/spec/ConfigChanges/ConfigChanges.spec.js
@@ -18,9 +18,11 @@
*/
const fs = require('node:fs');
-const os = require('node:os');
const path = require('node:path');
const et = require('elementtree');
+const tmp = require('tmp');
+
+tmp.setGracefulCleanup();
const configChanges = require('../../src/ConfigChanges/ConfigChanges');
const mungeutil = require('../../src/ConfigChanges/munge-util');
@@ -54,7 +56,8 @@ const varplugin = path.join(fixturePath, 'plugins/com.adobe.vars');
const plistplugin = path.join(fixturePath, 'plugins/org.apache.plist');
const bplistplugin = path.join(fixturePath, 'plugins/org.apache.bplist');
-const temp = path.join(os.tmpdir(), 'plugman');
+const tempdir = tmp.dirSync({ unsafeCleanup: true });
+const temp = path.join(tempdir.name, 'plugman');
const plugins_dir = path.join(temp, 'cordova', 'plugins');
const cfg = new ConfigParser(xml);
diff --git a/spec/FileUpdater.spec.js b/spec/FileUpdater.spec.js
index 3f342a6..3e8d74b 100644
--- a/spec/FileUpdater.spec.js
+++ b/spec/FileUpdater.spec.js
@@ -39,10 +39,42 @@ FileUpdater.__set__('updatePathWithStats', function () {
// Create mock fs.Stats to simulate file or directory attributes.
function mockFileStats (modified) {
- return new Stats(0, 32768, 0, 0, 0, 0, 0, 0, 0, 0, null, modified, modified, null);
+ return {
+ __proto__: Stats.prototype,
+ dev: 0,
+ mode: 32768,
+ nlink: 0,
+ uid: 0,
+ gid: 0,
+ rdev: 0,
+ blksize: 0,
+ ino: 0,
+ size: 0,
+ blocks: 0,
+ atime: null,
+ mtime: modified,
+ ctime: modified,
+ birthtime: null
+ };
}
function mockDirStats () {
- return new Stats(0, 16384, 0, 0, 0, 0, 0, 0, 0, 0, null, null, null, null);
+ return {
+ __proto__: Stats.prototype,
+ dev: 0,
+ mode: 16384,
+ nlink: 0,
+ uid: 0,
+ gid: 0,
+ rdev: 0,
+ blksize: 0,
+ ino: 0,
+ size: 0,
+ blocks: 0,
+ atime: null,
+ mtime: null,
+ ctime: null,
+ birthtime: null
+ };
}
class SystemError extends Error {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org