1
0
Fork 0

fix: internal module imports

This commit is contained in:
Sean Sube 2022-10-08 14:10:17 -05:00
parent faeff2c645
commit 95bf7ac982
28 changed files with 103 additions and 123 deletions

View File

@ -1,4 +1,4 @@
import { doesExist, isNone, Maybe } from './Maybe';
import { doesExist, isNone, Maybe } from './Maybe.js';
/**
* Merge arguments, which may or may not be arrays, into one return that is definitely an array.

View File

@ -1,4 +1,4 @@
import { setOrPush } from './Map';
import { setOrPush } from './Map.js';
export interface ArrayMapperOptions {
/**

View File

@ -1,5 +1,5 @@
import { TimeoutError } from './error/TimeoutError';
import { PredicateC0 } from './Predicate';
import { TimeoutError } from './error/TimeoutError.js';
import { PredicateC0 } from './Predicate.js';
/**
* Resolve after a set amount of time.

View File

@ -1,4 +1,4 @@
import { sum } from './Math';
import { sum } from './Math.js';
export type AllowedBufferEncoding = 'ascii' | 'utf-8';

View File

@ -2,10 +2,10 @@ import { ChildProcessWithoutNullStreams, spawn } from 'child_process';
import { BaseError } from 'noicejs';
import { Writable } from 'stream';
import { encode } from './Buffer';
import { ChildProcessError } from './error/ChildProcessError';
import { NameValuePair } from './Map';
import { doesExist, Maybe } from './Maybe';
import { encode } from './Buffer.js';
import { ChildProcessError } from './error/ChildProcessError.js';
import { NameValuePair } from './Map.js';
import { doesExist, Maybe } from './Maybe.js';
export interface ChildProcessOptions {
cwd: string;

View File

@ -1,5 +1,6 @@
import { ConsoleLogger, Logger, NullLogger } from 'noicejs';
import { isDebug } from './Env';
import { isDebug } from './Env.js';
/**
* Get a test logger. Returns a null logger unless `verbose` is true or run under debug mode.

View File

@ -1,6 +1,6 @@
import { mergeArrays, toArray } from './Array';
import { NotFoundError } from './error/NotFoundError';
import { doesExist, isNone, Maybe, mustExist } from './Maybe';
import { mergeArrays, toArray } from './Array.js';
import { NotFoundError } from './error/NotFoundError.js';
import { doesExist, isNone, Maybe, mustExist } from './Maybe.js';
export interface Dict<TVal> {
[key: string]: TVal;

View File

@ -1,5 +1,5 @@
import { NotFoundError } from './error/NotFoundError';
import { PredicateC1 } from './Predicate';
import { NotFoundError } from './error/NotFoundError.js';
import { PredicateC1 } from './Predicate.js';
/**
* Unset value.

View File

@ -1,5 +1,5 @@
// deprecated alternative names for Maybe
import { isNone, Maybe, None } from '.';
import { isNone, Maybe, None } from './Maybe.js';
/**

View File

@ -1,5 +1,5 @@
import { InvalidArgumentError } from './error/InvalidArgumentError';
import { doesExist, isNone } from './Maybe';
import { InvalidArgumentError } from './error/InvalidArgumentError.js';
import { doesExist, isNone } from './Maybe.js';
/* eslint-disable-next-line @typescript-eslint/ban-types */
type Reflectable = object;

View File

@ -1,4 +1,4 @@
import { VERSION_INFO } from './version';
import { VERSION_INFO } from './version.js';
export async function main(argv: Array<string>): Promise<number> {
/* eslint-disable-next-line no-console */

View File

@ -1,4 +1,4 @@
import { NotFoundError } from './NotFoundError';
import { NotFoundError } from './NotFoundError.js';
/**
* Error indicating that a required key did not exist in a map-like.

View File

@ -1,9 +1,9 @@
export { ChildProcessError } from './error/ChildProcessError';
export { InvalidArgumentError } from './error/InvalidArgumentError';
export { MissingKeyError } from './error/MissingKeyError';
export { NotFoundError } from './error/NotFoundError';
export { NotImplementedError } from './error/NotImplementedError';
export { TimeoutError } from './error/TimeoutError';
export { ChildProcessError } from './error/ChildProcessError.js';
export { InvalidArgumentError } from './error/InvalidArgumentError.js';
export { MissingKeyError } from './error/MissingKeyError.js';
export { NotFoundError } from './error/NotFoundError.js';
export { NotImplementedError } from './error/NotImplementedError.js';
export { TimeoutError } from './error/TimeoutError.js';
export {
mergeArray,
@ -15,28 +15,28 @@ export {
filterZip,
lengthOf,
toArray,
} from './Array';
} from './Array.js';
export {
ArrayMapper,
ArrayMapperOptions,
} from './ArrayMapper';
} from './ArrayMapper.js';
export {
defer,
deferUntil,
deferValue,
timeout,
waitFor,
} from './Async';
} from './Async.js';
export {
AllowedBufferEncoding,
concat,
encode,
} from './Buffer';
} from './Buffer.js';
export {
Checklist,
ChecklistMode,
ChecklistOptions,
} from './Checklist';
} from './Checklist.js';
export {
ChildOptions,
ChildResult,
@ -45,14 +45,14 @@ export {
waitForChild,
writeInput,
writeValue,
} from './Child';
} from './Child.js';
export {
isDebug
} from './Env';
} from './Env.js';
export {
getTestLogger,
spyLogger,
} from './Logger';
} from './Logger.js';
export {
Dict,
MapLike,
@ -68,10 +68,10 @@ export {
pairsToMap,
pushMergeMap,
setOrPush,
} from './Map';
} from './Map.js';
export {
sum,
} from './Math';
} from './Math.js';
export {
Maybe,
None,
@ -84,24 +84,24 @@ export {
mustExist,
mustFind,
removeNone,
} from './Maybe';
} from './Maybe.js';
export {
Nil,
Optional,
isNil,
} from './Optional';
} from './Optional.js';
export {
constructorName,
getConstructor,
getMethods,
} from './Reflect';
} from './Reflect.js';
export {
SIGNAL_RELOAD,
SIGNAL_RESET,
SIGNAL_STOP,
signal,
} from './Signal';
} from './Signal.js';
export {
leftPad,
trim,
} from './String';
} from './String.js';

View File

@ -1,7 +1,7 @@
import { expect } from 'chai';
import sinon from 'sinon';
import { main } from '../src/app';
import { main } from '../src/app.js';
const { spy } = sinon;

View File

@ -1,23 +1,23 @@
import { expect } from 'chai';
import { ConsoleLogger, NullLogger } from 'noicejs';
import { getTestLogger, spyLogger } from '../src/Logger';
import { getTestLogger, spyLogger } from '../src/Logger.js';
describe('logger utils', () => {
describe('get test logger helper', () => {
it('should return console logger in verbose mode', () => {
it('should return console logger in verbose mode', async () => {
expect(getTestLogger(true)).to.equal(ConsoleLogger.global);
});
it('should return console logger in debug mode');
it('should return null logger otherwise', () => {
it('should return null logger otherwise', async () => {
expect(getTestLogger()).to.equal(NullLogger.global);
});
});
describe('spy logger helper', () => {
it('should return itself as a child', () => {
it('should return itself as a child', async () => {
const logger = spyLogger({});
expect(logger.child({})).to.equal(logger);
});

View File

@ -1,11 +1,11 @@
import { expect } from 'chai';
import { ChildProcessError } from '../../../js-utils/src/error/ChildProcessError';
import { InvalidArgumentError } from '../../../js-utils/src/error/InvalidArgumentError';
import { MissingKeyError } from '../../../js-utils/src/error/MissingKeyError';
import { NotFoundError } from '../../src/error/NotFoundError';
import { NotImplementedError } from '../../../js-utils/src/error/NotImplementedError';
import { TimeoutError } from '../../../js-utils/src/error/TimeoutError';
import { ChildProcessError } from '../../src/error/ChildProcessError.js';
import { InvalidArgumentError } from '../../src/error/InvalidArgumentError.js';
import { MissingKeyError } from '../../src/error/MissingKeyError.js';
import { NotFoundError } from '../../src/error/NotFoundError.js';
import { NotImplementedError } from '../../src/error/NotImplementedError.js';
import { TimeoutError } from '../../src/error/TimeoutError.js';
const errors = [
ChildProcessError,
@ -19,18 +19,18 @@ const errors = [
describe('errors', () => {
for (const errorType of errors) {
describe(errorType.name, () => {
it('should have a message', () => {
it('should have a message', async () => {
const err = new errorType();
expect(err.message).to.not.equal('');
});
it('should include nested errors in the stack trace', () => {
it('should include nested errors in the stack trace', async () => {
const inner = new Error('inner error');
const err = new errorType('outer error', inner);
expect(err.stack).to.include('inner', 'inner error message').and.include('outer', 'outer error message');
});
it('should have the nested error', () => {
it('should have the nested error', async () => {
const inner = new Error('inner error');
const err = new errorType('outer error', inner);
expect(err.cause()).to.equal(inner);

View File

@ -1,22 +0,0 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import sinonChai from 'sinon-chai';
import sourceMapSupport from 'source-map-support';
sourceMapSupport.install({
environment: 'node',
handleUncaughtExceptions: true,
hookRequire: true,
});
/**
* This will break the whole test run if any test leaks an unhandled rejection.
*/
process.on('unhandledRejection', (reason, _promise) => {
// eslint-disable-next-line no-console
console.error('unhandled error during tests', reason);
process.exit(1);
});
chai.use(chaiAsPromised);
chai.use(sinonChai);

View File

@ -4,9 +4,9 @@ import { array, falsy, integer } from 'fast-check';
import { over } from 'mocha-foam';
import sinon from 'sinon';
import { isNone } from '../../src';
import { ensureArray, filterZip, hasItems, isEmpty, lengthOf, mergeArray, toArray } from '../../src/Array';
import { sum } from '../../src/Math';
import { isNone } from '../../src/index.js';
import { ensureArray, filterZip, hasItems, isEmpty, lengthOf, mergeArray, toArray } from '../../src/Array.js';
import { sum } from '../../src/Math.js';
const { match, stub } = sinon;

View File

@ -1,6 +1,6 @@
import { expect } from 'chai';
import { ArrayMapper } from '../../src/ArrayMapper';
import { ArrayMapper } from '../../src/ArrayMapper.js';
describe('utils', async () => {
describe('array mapper', async () => {

View File

@ -1,7 +1,7 @@
import { expect } from 'chai';
import { defer, deferValue, timeout } from '../../src/Async';
import { TimeoutError } from '../../src/error/TimeoutError';
import { defer, deferValue, timeout } from '../../src/Async.js';
import { TimeoutError } from '../../src/error/TimeoutError.js';
const TEST_DEFER = 10;
const TEST_TOO_LONG = 25;

View File

@ -2,8 +2,8 @@ import { expect } from 'chai';
import { array, uint8Array } from 'fast-check';
import { over } from 'mocha-foam';
import { concat, encode } from '../../src/Buffer';
import { sum } from '../../src/Math';
import { concat, encode } from '../../src/Buffer.js';
import { sum } from '../../src/Math.js';
describe('buffer utils', async () => {
describe('concat', async () => {

View File

@ -2,7 +2,7 @@ import { expect } from 'chai';
import { array, constant, integer, record } from 'fast-check';
import { over } from 'mocha-foam';
import { Checklist, ChecklistMode } from '../../src/Checklist';
import { Checklist, ChecklistMode } from '../../src/Checklist.js';
const EXISTING_ITEM = 'foo';
const MISSING_ITEM = 'bin';

View File

@ -1,9 +1,9 @@
import { expect } from 'chai';
import sinon from 'sinon';
import { ChildProcessError } from '../../src';
import { ChildStreams, childResult } from '../../src/Child';
import { Maybe, mustExist } from '../../src/Maybe';
import { ChildProcessError } from '../../src/error/ChildProcessError.js';
import { ChildStreams, childResult } from '../../src/Child.js';
import { Maybe, mustExist } from '../../src/Maybe.js';
const { match, stub } = sinon;

View File

@ -3,7 +3,7 @@ import { expect } from 'chai';
import { array, dictionary, integer, nat, record, string, tuple } from 'fast-check';
import { over } from 'mocha-foam';
import { NotFoundError } from '../../src/error/NotFoundError';
import { NotFoundError } from '../../src/error/NotFoundError.js';
import {
entriesOf,
getHead,
@ -17,7 +17,7 @@ import {
pairsToMap,
pushMergeMap,
setOrPush,
} from '../../src/Map';
} from '../../src/Map.js';
const DEFAULT_VALUE = 'default';
const mapKey = 'key';
@ -115,22 +115,22 @@ describe('map utils', async () => {
});
describe('get or default helper', () => {
it('should get the item for existing keys', () => {
it('should get the item for existing keys', async () => {
expect(getOrDefault(singleItem, mapKey, DEFAULT_VALUE)).to.equal(mapValue);
});
it('should get the item for missing keys', () => {
it('should get the item for missing keys', async () => {
expect(getOrDefault(singleItem, 'missing', DEFAULT_VALUE)).to.equal(DEFAULT_VALUE);
});
it('should return the default for nil values', () => {
it('should return the default for nil values', async () => {
expect(getOrDefault(multiItem, 'nilKey', DEFAULT_VALUE)).to.equal(DEFAULT_VALUE);
});
xit('should return falsy values for existing keys');
over('map with truthy values', array(tuple(string(), nat()), { minLength: 1 }).map((t) => new Map(t)), (it) => {
it('should return a value other than missing', (val) => {
it('should return a value other than missing', async (val) => {
const missing = -1;
for (const [key, _value] of val) {
expect(getOrDefault(val, key, missing)).not.to.equal(missing);
@ -140,7 +140,7 @@ describe('map utils', async () => {
});
describe('pairs to map helper', () => {
it('should convert pairs', () => {
it('should convert pairs', async () => {
const result = pairsToMap([{
name: 'foo',
value: 3,
@ -152,7 +152,7 @@ describe('map utils', async () => {
name: string(),
value: integer(),
})), (it) => {
it('should include each unique key', (val) => {
it('should include each unique key', async (val) => {
const keys = new Set(val.map((pair) => pair.name));
const map = pairsToMap(val);
expect(map.size).to.equal(keys.size);
@ -161,7 +161,7 @@ describe('map utils', async () => {
});
describe('entries of helper', () => {
it('should return entries for maps', () => {
it('should return entries for maps', async () => {
const input: Array<[string, number]> = [['foo', 1], ['bar', 3]];
const value = new Map(input);
const result = entriesOf(value);
@ -169,7 +169,7 @@ describe('map utils', async () => {
expect(result).to.deep.equal(input);
});
it('should return entries for objects', () => {
it('should return entries for objects', async () => {
const result = entriesOf({
bar: 3,
foo: 1,
@ -178,14 +178,14 @@ describe('map utils', async () => {
expect(result[0][0]).to.equal('bar');
});
it('should return empty entries for nil values', () => {
it('should return empty entries for nil values', async () => {
/* eslint-disable-next-line no-null/no-null */
expect(entriesOf(null)).to.deep.equal([]);
expect(entriesOf(undefined)).to.deep.equal([]);
});
over('dict objects', dictionary(string(), integer()), (it) => {
it('should list the properties', (val) => {
it('should list the properties', async (val) => {
const props = entriesOf(val);
for (const [key, value] of props) {
expect(val[key]).to.equal(value);
@ -197,7 +197,7 @@ describe('map utils', async () => {
describe('set or push helper', () => {
xit('should insert new lists');
it('should wrap new items', () => {
it('should wrap new items', async () => {
const values = new Map<string, Array<string>>([]);
setOrPush(values, mapKey, 'fin');
@ -205,7 +205,7 @@ describe('map utils', async () => {
expect(mustGet(values, mapKey).length).to.equal(1);
});
it('should append to existing items', () => {
it('should append to existing items', async () => {
const values = new Map(multiItem);
setOrPush(values, mapKey, 'fin');
@ -215,7 +215,7 @@ describe('map utils', async () => {
});
describe('merge map helper', () => {
it('should combine two maps', () => {
it('should combine two maps', async () => {
const firstValue = new Map([[mapKey, mapValue]]);
const otherValue = new Map([['foo', 'bar']]);
@ -226,7 +226,7 @@ describe('map utils', async () => {
});
describe('push merge map helper', () => {
it('should combine two overlapping maps', () => {
it('should combine two overlapping maps', async () => {
const firstValue = new Map([[mapKey, [1]]]);
const otherValue = new Map([[mapKey, [2, 3]]]);
@ -237,17 +237,17 @@ describe('map utils', async () => {
});
describe('make map helper', () => {
it('should make an empty map', () => {
it('should make an empty map', async () => {
expect(makeMap(undefined).size).to.equal(0);
});
it('should copy an existing map', () => {
it('should copy an existing map', async () => {
const copy = makeMap(singleItem);
expect(copy).to.deep.equal(singleItem);
expect(copy).not.to.equal(singleItem);
});
it('should copy a dict', () => {
it('should copy a dict', async () => {
expect(makeMap({
[mapKey]: mapValue,
})).to.deep.equal(singleItem);
@ -255,7 +255,7 @@ describe('map utils', async () => {
});
describe('normalize map helper', () => {
it('should convert values into arrays of strings', () => {
it('should convert values into arrays of strings', async () => {
const banVal = [Symbol()];
const initial = new Map<string, unknown>([
['bar', 'bin'],
@ -274,7 +274,7 @@ describe('map utils', async () => {
expect(normalized.toad).to.deep.equal(['too']);
});
it('should convert number arguments into string values', () => {
it('should convert number arguments into string values', async () => {
const INPUT_VALUE = 123;
const input = new Map([
['foo', INPUT_VALUE],
@ -284,7 +284,7 @@ describe('map utils', async () => {
expect(normalized.foo).to.deep.equal([INPUT_VALUE.toString()]);
});
it('should convert object arguments into string values', () => {
it('should convert object arguments into string values', async () => {
const OUTPUT_VALUE = 'bar';
const input = new Map([
['foo', {

View File

@ -3,9 +3,9 @@ import { expect } from 'chai';
import { anything, array, boolean, integer, tuple } from 'fast-check';
import { over } from 'mocha-foam';
import { NotFoundError } from '../../src/error/NotFoundError';
import { defaultWhen, doesExist, isNone, isSome, mustCoalesce, mustDefault, mustFind, removeNone } from '../../src/Maybe';
import { isNil } from '../../src/Optional';
import { NotFoundError } from '../../src/error/NotFoundError.js';
import { defaultWhen, doesExist, isNone, isSome, mustCoalesce, mustDefault, mustFind, removeNone } from '../../src/Maybe.js';
import { isNil } from '../../src/Optional.js';
describe('maybe utils', () => {
describe('remove none', () => {

View File

@ -1,6 +1,7 @@
import { expect } from 'chai';
import { InvalidArgumentError } from '../../src';
import { getMethods, getConstructor, constructorName } from '../../src/Reflect';
import { InvalidArgumentError } from '../../src/error/InvalidArgumentError.js';
import { constructorName, getConstructor, getMethods } from '../../src/Reflect.js';
class Test {
public foo() { /* noop */ }
@ -9,7 +10,7 @@ class Test {
describe('reflect utils', () => {
describe('get methods helper', () => {
it('should collect method functions', () => {
it('should collect method functions', async () => {
const methods = getMethods(new Test()).values();
/* eslint-disable @typescript-eslint/unbound-method */
@ -19,19 +20,19 @@ describe('reflect utils', () => {
});
describe('get constructor helper', () => {
it('should get the constructor from an instance', () => {
it('should get the constructor from an instance', async () => {
const instance = new Test();
expect(getConstructor(instance)).to.equal(Test);
});
});
describe('get constructor name helper', () => {
it('should get the constructor name from an instance', () => {
it('should get the constructor name from an instance', async () => {
const instance = new Test();
expect(constructorName(instance)).to.equal(Test.name);
});
it('should throw when value has no prototype', () => {
it('should throw when value has no prototype', async () => {
/* eslint-disable-next-line no-null/no-null */
const protoless = Object.create(null, {});
expect(() => constructorName(protoless)).to.throw(InvalidArgumentError);

View File

@ -1,7 +1,7 @@
import { expect } from 'chai';
import { timeout } from '../../src/Async';
import { signal, SIGNAL_RESET } from '../../src/Signal';
import { timeout } from '../../src/Async.js';
import { signal, SIGNAL_RESET } from '../../src/Signal.js';
const MAX_SIGNAL_TIME = 500;

View File

@ -3,7 +3,7 @@ import { expect } from 'chai';
import { integer, nat, string, tuple } from 'fast-check';
import { over } from 'mocha-foam';
import { leftPad, trim } from '../../src/String';
import { leftPad, trim } from '../../src/String.js';
const TEST_SHORT = 'hello';
const TEST_LONG = 'hello world';