From e68d7f97d2d3e1d942d764c42620b0adb7ab5b1c Mon Sep 17 00:00:00 2001 From: ssube Date: Sun, 29 Mar 2020 09:52:40 -0500 Subject: [PATCH] feat: export async tracker, checklist --- docs/api/js-utils.checklist._constructor_.md | 20 +++++++++ docs/api/js-utils.checklist.check.md | 22 +++++++++ docs/api/js-utils.checklist.data.md | 11 +++++ docs/api/js-utils.checklist.md | 31 +++++++++++++ docs/api/js-utils.checklist.mode.md | 11 +++++ docs/api/js-utils.checklistmode.md | 19 ++++++++ docs/api/js-utils.checklistoptions.data.md | 11 +++++ docs/api/js-utils.checklistoptions.md | 19 ++++++++ docs/api/js-utils.checklistoptions.mode.md | 11 +++++ docs/api/js-utils.md | 8 ++++ src/{test => }/AsyncTracker.ts | 4 +- src/{test => }/Logger.ts | 0 src/index.ts | 4 +- test/helpers/async.ts | 2 +- test/utils/TestChecklist.ts | 47 ++++++++++++++++++++ 15 files changed, 215 insertions(+), 5 deletions(-) create mode 100644 docs/api/js-utils.checklist._constructor_.md create mode 100644 docs/api/js-utils.checklist.check.md create mode 100644 docs/api/js-utils.checklist.data.md create mode 100644 docs/api/js-utils.checklist.md create mode 100644 docs/api/js-utils.checklist.mode.md create mode 100644 docs/api/js-utils.checklistmode.md create mode 100644 docs/api/js-utils.checklistoptions.data.md create mode 100644 docs/api/js-utils.checklistoptions.md create mode 100644 docs/api/js-utils.checklistoptions.mode.md rename src/{test => }/AsyncTracker.ts (96%) rename src/{test => }/Logger.ts (100%) create mode 100644 test/utils/TestChecklist.ts diff --git a/docs/api/js-utils.checklist._constructor_.md b/docs/api/js-utils.checklist._constructor_.md new file mode 100644 index 0000000..26db8f4 --- /dev/null +++ b/docs/api/js-utils.checklist._constructor_.md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [@apextoaster/js-utils](./js-utils.md) > [Checklist](./js-utils.checklist.md) > [(constructor)](./js-utils.checklist._constructor_.md) + +## Checklist.(constructor) + +Constructs a new instance of the `Checklist` class + +Signature: + +```typescript +constructor(options: ChecklistOptions); +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| options | ChecklistOptions<T> | | + diff --git a/docs/api/js-utils.checklist.check.md b/docs/api/js-utils.checklist.check.md new file mode 100644 index 0000000..8e07797 --- /dev/null +++ b/docs/api/js-utils.checklist.check.md @@ -0,0 +1,22 @@ + + +[Home](./index.md) > [@apextoaster/js-utils](./js-utils.md) > [Checklist](./js-utils.checklist.md) > [check](./js-utils.checklist.check.md) + +## Checklist.check() method + +Signature: + +```typescript +check(value: T): boolean; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| value | T | | + +Returns: + +`boolean` + diff --git a/docs/api/js-utils.checklist.data.md b/docs/api/js-utils.checklist.data.md new file mode 100644 index 0000000..3d994b9 --- /dev/null +++ b/docs/api/js-utils.checklist.data.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@apextoaster/js-utils](./js-utils.md) > [Checklist](./js-utils.checklist.md) > [data](./js-utils.checklist.data.md) + +## Checklist.data property + +Signature: + +```typescript +readonly data: Array; +``` diff --git a/docs/api/js-utils.checklist.md b/docs/api/js-utils.checklist.md new file mode 100644 index 0000000..063b4c0 --- /dev/null +++ b/docs/api/js-utils.checklist.md @@ -0,0 +1,31 @@ + + +[Home](./index.md) > [@apextoaster/js-utils](./js-utils.md) > [Checklist](./js-utils.checklist.md) + +## Checklist class + +Signature: + +```typescript +export declare class Checklist implements ChecklistOptions +``` + +## Constructors + +| Constructor | Modifiers | Description | +| --- | --- | --- | +| [(constructor)(options)](./js-utils.checklist._constructor_.md) | | Constructs a new instance of the Checklist class | + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [data](./js-utils.checklist.data.md) | | Array<T> | | +| [mode](./js-utils.checklist.mode.md) | | ChecklistMode | | + +## Methods + +| Method | Modifiers | Description | +| --- | --- | --- | +| [check(value)](./js-utils.checklist.check.md) | | | + diff --git a/docs/api/js-utils.checklist.mode.md b/docs/api/js-utils.checklist.mode.md new file mode 100644 index 0000000..eb35a7f --- /dev/null +++ b/docs/api/js-utils.checklist.mode.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@apextoaster/js-utils](./js-utils.md) > [Checklist](./js-utils.checklist.md) > [mode](./js-utils.checklist.mode.md) + +## Checklist.mode property + +Signature: + +```typescript +readonly mode: ChecklistMode; +``` diff --git a/docs/api/js-utils.checklistmode.md b/docs/api/js-utils.checklistmode.md new file mode 100644 index 0000000..78460d7 --- /dev/null +++ b/docs/api/js-utils.checklistmode.md @@ -0,0 +1,19 @@ + + +[Home](./index.md) > [@apextoaster/js-utils](./js-utils.md) > [ChecklistMode](./js-utils.checklistmode.md) + +## ChecklistMode enum + +Signature: + +```typescript +export declare enum ChecklistMode +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| EXCLUDE | "exclude" | | +| INCLUDE | "include" | | + diff --git a/docs/api/js-utils.checklistoptions.data.md b/docs/api/js-utils.checklistoptions.data.md new file mode 100644 index 0000000..948f18d --- /dev/null +++ b/docs/api/js-utils.checklistoptions.data.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@apextoaster/js-utils](./js-utils.md) > [ChecklistOptions](./js-utils.checklistoptions.md) > [data](./js-utils.checklistoptions.data.md) + +## ChecklistOptions.data property + +Signature: + +```typescript +data: Array; +``` diff --git a/docs/api/js-utils.checklistoptions.md b/docs/api/js-utils.checklistoptions.md new file mode 100644 index 0000000..3daad5f --- /dev/null +++ b/docs/api/js-utils.checklistoptions.md @@ -0,0 +1,19 @@ + + +[Home](./index.md) > [@apextoaster/js-utils](./js-utils.md) > [ChecklistOptions](./js-utils.checklistoptions.md) + +## ChecklistOptions interface + +Signature: + +```typescript +export interface ChecklistOptions +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [data](./js-utils.checklistoptions.data.md) | Array<T> | | +| [mode](./js-utils.checklistoptions.mode.md) | ChecklistMode | | + diff --git a/docs/api/js-utils.checklistoptions.mode.md b/docs/api/js-utils.checklistoptions.mode.md new file mode 100644 index 0000000..1217551 --- /dev/null +++ b/docs/api/js-utils.checklistoptions.mode.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [@apextoaster/js-utils](./js-utils.md) > [ChecklistOptions](./js-utils.checklistoptions.md) > [mode](./js-utils.checklistoptions.mode.md) + +## ChecklistOptions.mode property + +Signature: + +```typescript +mode: ChecklistMode; +``` diff --git a/docs/api/js-utils.md b/docs/api/js-utils.md index d568878..422412f 100644 --- a/docs/api/js-utils.md +++ b/docs/api/js-utils.md @@ -10,6 +10,7 @@ | --- | --- | | [ArrayMapper](./js-utils.arraymapper.md) | | | [AsyncTracker](./js-utils.asynctracker.md) | Async resource tracker using node's internal hooks.This probably won't work in a browser. It does not hold references to the resource, to avoid leaks. Adapted from https://gist.github.com/boneskull/7fe75b63d613fa940db7ec990a5f5843\#file-async-dump-js | +| [Checklist](./js-utils.checklist.md) | | | [ChildProcessError](./js-utils.childprocesserror.md) | | | [InvalidArgumentError](./js-utils.invalidargumenterror.md) | | | [MissingKeyError](./js-utils.missingkeyerror.md) | | @@ -17,6 +18,12 @@ | [NotImplementedError](./js-utils.notimplementederror.md) | | | [TimeoutError](./js-utils.timeouterror.md) | | +## Enumerations + +| Enumeration | Description | +| --- | --- | +| [ChecklistMode](./js-utils.checklistmode.md) | | + ## Functions | Function | Description | @@ -65,6 +72,7 @@ | Interface | Description | | --- | --- | | [ArrayMapperOptions](./js-utils.arraymapperoptions.md) | | +| [ChecklistOptions](./js-utils.checklistoptions.md) | | | [ChildOptions](./js-utils.childoptions.md) | | | [ChildResult](./js-utils.childresult.md) | | | [Dict](./js-utils.dict.md) | | diff --git a/src/test/AsyncTracker.ts b/src/AsyncTracker.ts similarity index 96% rename from src/test/AsyncTracker.ts rename to src/AsyncTracker.ts index d2a5005..d2395b7 100644 --- a/src/test/AsyncTracker.ts +++ b/src/AsyncTracker.ts @@ -1,7 +1,7 @@ import { AsyncHook, createHook } from 'async_hooks'; -import { isNil } from '../utils'; -import { isDebug } from '../utils/Env'; +import { isNil } from './utils'; +import { isDebug } from './utils/Env'; export interface TrackedResource { source: string; diff --git a/src/test/Logger.ts b/src/Logger.ts similarity index 100% rename from src/test/Logger.ts rename to src/Logger.ts diff --git a/src/index.ts b/src/index.ts index 75a3ac4..7f673ed 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,11 +7,11 @@ export { TimeoutError } from './error/TimeoutError'; export { AsyncTracker, -} from './test/AsyncTracker'; +} from './AsyncTracker'; export { getTestLogger, spyLogger, -} from './test/Logger'; +} from './Logger'; export { Nil, diff --git a/test/helpers/async.ts b/test/helpers/async.ts index 651ef78..cb3abc4 100644 --- a/test/helpers/async.ts +++ b/test/helpers/async.ts @@ -1,4 +1,4 @@ -import { AsyncTracker } from '../../src/test/AsyncTracker'; +import { AsyncTracker } from '../../src/AsyncTracker'; import { isNil } from '../../src/utils'; import { isDebug } from '../../src/utils/Env'; diff --git a/test/utils/TestChecklist.ts b/test/utils/TestChecklist.ts new file mode 100644 index 0000000..052dcae --- /dev/null +++ b/test/utils/TestChecklist.ts @@ -0,0 +1,47 @@ +import { expect } from 'chai'; + +import { Checklist, ChecklistMode } from '../../src/utils/Checklist'; +import { describeLeaks, itLeaks } from '../helpers/async'; + +const EXISTING_ITEM = 'foo'; +const MISSING_ITEM = 'bin'; +const TEST_DATA = [EXISTING_ITEM, 'bar']; + +// tslint:disable:no-duplicate-functions +describeLeaks('checklist', async () => { + describeLeaks('exclude mode', async () => { + itLeaks('should check for present values', async () => { + const list = new Checklist({ + data: TEST_DATA, + mode: ChecklistMode.EXCLUDE, + }); + expect(list.check(EXISTING_ITEM)).to.equal(false); + }); + + itLeaks('should check for missing values', async () => { + const list = new Checklist({ + data: TEST_DATA, + mode: ChecklistMode.EXCLUDE, + }); + expect(list.check(MISSING_ITEM)).to.equal(true); + }); + }); + + describeLeaks('include mode', async () => { + itLeaks('should check for present values', async () => { + const list = new Checklist({ + data: TEST_DATA, + mode: ChecklistMode.INCLUDE, + }); + expect(list.check(EXISTING_ITEM)).to.equal(true); + }); + + itLeaks('should check for missing values', async () => { + const list = new Checklist({ + data: TEST_DATA, + mode: ChecklistMode.INCLUDE, + }); + expect(list.check(MISSING_ITEM)).to.equal(false); + }); + }); +});