Skip to content

Commit

Permalink
chore: Minor test fixes (#211)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
dpogue authored Aug 29, 2024
1 parent d7f71e6 commit c85b825
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
13 changes: 12 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions spec/ConfigChanges/ConfigChanges.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand Down
36 changes: 34 additions & 2 deletions spec/FileUpdater.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c85b825

Please sign in to comment.