Skip to content

Commit

Permalink
test: improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ahwayakchih committed Feb 8, 2025
1 parent 347fe46 commit 2d26b3d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
8 changes: 8 additions & 0 deletions test/lib/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,13 @@ test('configuration', t => {
t.strictEqual(c.zipPath, path.join(CWD, `${dirName}.zip`), 'Should find and use manifest.json directory name as ZIP file name');
t.strictEqual(c.xmlPath, path.join(CWD, `${dirName}.xml`), 'Should find and use manifest.json directory name as XML file name');

// c = config().setFromArgv();
// t.ok(c.crxPath, 'Should use default CRX file path when no args are used (setFromArgv)');
// t.ok(c.crxPath.startsWith(CWD), 'Default CRX file path should be in current work directory');

// t.ok(!c.keyPath, 'Should not set key file path by default when no args are used (setFromArgv)');
// t.ok(!c.zipPath, 'Should not set ZIP file path by default when no args are used (setFromArgv)');
// t.ok(!c.xmlPath, 'Should not set XML file path by default when no args are used (setFromArgv)');

t.end();
});
1 change: 1 addition & 0 deletions test/lib/findCommonPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test('findCommonPath', t => {
const abce = path.join('a', 'b', 'c', 'example.txt');
t.strictEqual(findCommonPath(), '', 'Should return empty string when called without arguments');
t.strictEqual(findCommonPath([]), '', 'Should return empty string when files array is empty');
t.strictEqual(findCommonPath([path.sep]), path.sep, 'Should return path separator when files array include "root" dorectory');
t.strictEqual(findCommonPath(['example.txt']), '', 'Should return empty string when no file has separator in path');
t.strictEqual(findCommonPath([a]), a, 'Should return directory when the files contain just a directory');
t.strictEqual(findCommonPath([ae]), a, 'Should return directory when the files contain one path');
Expand Down
5 changes: 4 additions & 1 deletion test/lib/getFilePaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ test('getFilePaths', t => {
t.ok(Array.isArray(temp) && temp.length === 0, 'Should return empty array when called without arguments');

temp = getFilePaths('test');
t.ok(Array.isArray(temp) && temp.length === 0, 'Should return empty array when called with string instead of array');
t.ok(Array.isArray(temp) && temp.length === 0, 'Should return empty array when called with a string instead of array');

temp = getFilePaths(['non-existent-file-path']);
t.ok(Array.isArray(temp) && temp.length === 0, 'Should return empty array when files in list do not exist');

const parentDirname = path.dirname(__dirname);
temp = getFilePaths([parentDirname]);
Expand Down
17 changes: 15 additions & 2 deletions test/lib/keypair.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test('keypair', t => {
fs.unlinkSync(keyPath);
}

const mask = process.umask(0o000);
let mask = process.umask(0o000);
const failPath = 'forbidden';
const writeOnly = 0o200;
fs.writeFileSync(failPath, '', {mode: writeOnly});
Expand All @@ -51,5 +51,18 @@ test('keypair', t => {
t.strictEqual(fail, null, 'Should return `null` if key file exists but could not be read');
fs.unlinkSync(failPath);

t.end();
mask = process.umask(0o000);
const failDirPath = 'forbidden';
const readOnly = 0o400;
fs.mkdir(failDirPath, {mode: readOnly}, (err) => {
process.umask(mask);
t.strictEqual(err, null, 'Should be able to create directory for testing');
const failKeyPath = failDirPath + '/test';
const failWriteDir = keypair(failKeyPath);
t.strictEqual(fail, null, 'Should return `null` if key file exists but could not be read');
fs.rmdir(failDirPath, () => {
// We ignore possible error when trying to remove test directory
t.end();
});
});
});

0 comments on commit 2d26b3d

Please sign in to comment.