Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asamuzaK committed Nov 28, 2024
1 parent ce8025a commit a0eb07f
Show file tree
Hide file tree
Showing 8 changed files with 928 additions and 643 deletions.
414 changes: 222 additions & 192 deletions test/browser.test.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions test/commander.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* api */
import { strict as assert } from 'node:assert';
import fs from 'node:fs';
import path from 'node:path';
import sinon from 'sinon';
import { assert } from 'chai';
import { describe, it } from 'mocha';

/* test */
Expand All @@ -17,7 +17,7 @@ describe('clean directory', () => {
cleanDirectory({ dir });
const { called: rmCalled } = stubRm;
stubRm.restore();
assert.isFalse(rmCalled, 'not called');
assert.strictEqual(rmCalled, false, 'not called');
});

it('should call funtion', () => {
Expand All @@ -29,8 +29,8 @@ describe('clean directory', () => {
const { called: infoCalled } = stubInfo;
stubRm.restore();
stubInfo.restore();
assert.isTrue(rmCalled, 'called');
assert.isFalse(infoCalled, 'not called');
assert.strictEqual(rmCalled, true, 'called');
assert.strictEqual(infoCalled, false, 'not called');
});

it('should call funtion', () => {
Expand All @@ -42,8 +42,8 @@ describe('clean directory', () => {
const { calledOnce: infoCalled } = stubInfo;
stubRm.restore();
stubInfo.restore();
assert.isTrue(rmCalled, 'called');
assert.isTrue(infoCalled, 'not called');
assert.strictEqual(rmCalled, true, 'called');
assert.strictEqual(infoCalled, true, 'called');
});
});

Expand Down
16 changes: 8 additions & 8 deletions test/common.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* api */
import { strict as assert } from 'node:assert';
import sinon from 'sinon';
import { assert } from 'chai';
import { describe, it } from 'mocha';

/* test */
Expand Down Expand Up @@ -42,15 +42,15 @@ describe('isObjectNotEmpty', () => {
it('should get false', () => {
const items = [{}, [], ['foo'], '', 'foo', undefined, null, 1, true];
for (const item of items) {
assert.isFalse(isObjectNotEmpty(item));
assert.strictEqual(isObjectNotEmpty(item), false);
}
});

it('should get true', () => {
const item = {
foo: 'bar'
};
assert.isTrue(isObjectNotEmpty(item));
assert.strictEqual(isObjectNotEmpty(item), true);
});
});

Expand All @@ -74,9 +74,9 @@ describe('logErr', () => {
const res = logErr(new Error(msg));
const { calledOnce } = consoleError;
consoleError.restore();
assert.isTrue(calledOnce);
assert.strictEqual(calledOnce, true);
assert.strictEqual(errMsg, msg);
assert.isFalse(res);
assert.strictEqual(res, false);
});
});

Expand All @@ -90,7 +90,7 @@ describe('logMsg', () => {
const res = logMsg(msg);
const { calledOnce } = consoleLog;
consoleLog.restore();
assert.isTrue(calledOnce);
assert.strictEqual(calledOnce, true);
assert.strictEqual(logMessage, msg);
assert.strictEqual(res, msg);
});
Expand All @@ -106,9 +106,9 @@ describe('logWarn', () => {
const res = logWarn(msg);
const { calledOnce } = consoleWarn;
consoleWarn.restore();
assert.isTrue(calledOnce);
assert.strictEqual(calledOnce, true);
assert.strictEqual(warnMsg, msg);
assert.isFalse(res);
assert.strictEqual(res, false);
});
});

Expand Down
8 changes: 4 additions & 4 deletions test/constant.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* api */
import { assert } from 'chai';
import { strict as assert } from 'node:assert';
import { describe, it } from 'mocha';
import { isString } from '../modules/common.js';

Expand All @@ -10,7 +10,7 @@ describe('string constants', () => {
it('should get string', () => {
const arr = [CHAR];
arr.forEach(i => {
assert.isTrue(isString(i));
assert.strictEqual(isString(i), true);
});
});
});
Expand All @@ -19,7 +19,7 @@ describe('number constants', () => {
it('should get number', () => {
const arr = [INDENT];
arr.forEach(i => {
assert.isTrue(typeof i === 'number');
assert.strictEqual(typeof i, 'number');
});
});
});
Expand All @@ -28,7 +28,7 @@ describe('boolean constants', () => {
it('should get boolean', () => {
const arr = [IS_WIN];
arr.forEach(i => {
assert.isTrue(typeof i === 'boolean');
assert.strictEqual(typeof i, 'boolean');
});
});
});
44 changes: 20 additions & 24 deletions test/file-util.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* api */
import { strict as assert } from 'node:assert';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import process from 'node:process';
import { assert } from 'chai';
import { describe, it } from 'mocha';
import { IS_WIN } from '../modules/constant.js';

Expand Down Expand Up @@ -71,13 +71,13 @@ describe('convertUriToFilePath', () => {
});

it('should throw if string is not given', () => {
assert.throws(() => convertUriToFilePath(),
assert.throws(() => convertUriToFilePath(), TypeError,
'Expected String but got Undefined');
});

it('should get null if protocol does not match', () => {
const uri = 'http://example.com';
assert.isNull(convertUriToFilePath(uri));
assert.deepEqual(convertUriToFilePath(uri), null);
});
});

Expand All @@ -92,17 +92,15 @@ describe('createDirectory', () => {

it('should throw if given argument is not a string', async () => {
await createDirectory().catch(e => {
assert.instanceOf(e, TypeError, 'error');
assert.strictEqual(e.message, 'Expected String but got Undefined.',
'message');
assert.deepStrictEqual(e,
new TypeError('Expected String but got Undefined.'));
});
});

it('should throw if given second argument is not a number', async () => {
await createDirectory('/foo/bar', 'baz').catch(e => {
assert.instanceOf(e, TypeError, 'error');
assert.strictEqual(e.message, 'Expected Number but got String.',
'message');
assert.deepStrictEqual(e,
new TypeError('Expected Number but got String.'));
});
});
});
Expand All @@ -123,7 +121,8 @@ describe('createFile', () => {

it('should throw if first argument is not a string', () => {
createFile().catch(e => {
assert.strictEqual(e.message, 'Expected String but got Undefined.');
assert.deepStrictEqual(e,
new TypeError('Expected String but got Undefined.'));
});
});

Expand All @@ -132,10 +131,8 @@ describe('createFile', () => {
() => {
const file = path.join(TMPDIR, 'webext-schema', 'test.txt');
createFile(file).catch(e => {
assert.strictEqual(
e.message,
'Expected String, Buffer, Uint8Array but got Undefined.'
);
assert.deepStrictEqual(e,
new TypeError('Expected String, Buffer, Uint8Array but got Undefined.'));
});
}
);
Expand Down Expand Up @@ -169,7 +166,7 @@ describe('removeDir', () => {

it('should ignore if dir is not a directory', () => {
const foo = path.resolve('foo');
assert.isFalse(isDir(foo));
assert.strictEqual(isDir(foo), false);
assert.doesNotThrow(() => removeDir(foo, TMPDIR));
});

Expand All @@ -178,7 +175,7 @@ describe('removeDir', () => {
const foo = path.join(TMPDIR, 'foo');
await fs.mkdirSync(dirPath);
await fs.mkdirSync(foo);
assert.throws(() => removeDir(foo, dirPath),
assert.throws(() => removeDir(foo, dirPath), Error,
`${foo} is not a subdirectory of ${dirPath}.`);
await fs.rmdirSync(dirPath);
await fs.rmdirSync(foo);
Expand Down Expand Up @@ -213,7 +210,7 @@ describe('removeDirectory', () => {

it('should ignore if dir is not a directory', async () => {
const foo = path.resolve('foo');
assert.isFalse(isDir(foo));
assert.strictEqual(isDir(foo), false);
await removeDirectory(foo, TMPDIR).catch(e => {
assert.isUndefined(e);
});
Expand All @@ -225,9 +222,8 @@ describe('removeDirectory', () => {
await fs.mkdirSync(dirPath);
await fs.mkdirSync(foo);
await removeDirectory(foo, dirPath).catch(e => {
assert.instanceOf(e, Error);
assert.strictEqual(e.message,
`${foo} is not a subdirectory of ${dirPath}.`);
assert.deepStrictEqual(e,
new Error(`${foo} is not a subdirectory of ${dirPath}.`));
});
await fs.rmdirSync(dirPath);
await fs.rmdirSync(foo);
Expand Down Expand Up @@ -274,7 +270,7 @@ describe('getFileNameFromFilePath', () => {
describe('getFileTimestamp', () => {
it('should get positive integer', () => {
const p = path.resolve(path.join('test', 'file', 'test.sh'));
assert.isAbove(getFileTimestamp(p), 0);
assert.strictEqual(getFileTimestamp(p) > 0, true);
});

it('should get 0 if file does not exist', () => {
Expand All @@ -286,16 +282,16 @@ describe('getFileTimestamp', () => {
describe('getStat', () => {
it('should be an object', () => {
const p = path.resolve(path.join('test', 'file', 'test.sh'));
assert.property(getStat(p), 'mode');
assert.strictEqual(typeof getStat(p), 'object');
});

it('should get null if given argument is not string', () => {
assert.isNull(getStat());
assert.deepEqual(getStat(), null);
});

it('should get null if file does not exist', () => {
const p = path.resolve(path.join('test', 'file', 'foo.txt'));
assert.isNull(getStat(p));
assert.deepEqual(getStat(p), null);
});
});

Expand Down
4 changes: 2 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* api */
import { assert } from 'chai';
import { strict as assert } from 'node:assert';
import { describe, it } from 'mocha';

/* test */
Expand All @@ -8,6 +8,6 @@ import { Schema } from '../index.js';
describe('Schema', () => {
it('should be instance of Schema', () => {
const schema = new Schema();
assert.instanceOf(schema, Schema);
assert.strictEqual(schema instanceof Schema, true);
});
});
Loading

0 comments on commit a0eb07f

Please sign in to comment.