Skip to content

Commit

Permalink
feat: export async tracker, checklist
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Mar 29, 2020
1 parent 6ac9f33 commit e68d7f9
Show file tree
Hide file tree
Showing 15 changed files with 215 additions and 5 deletions.
20 changes: 20 additions & 0 deletions docs/api/js-utils.checklist._constructor_.md
@@ -0,0 +1,20 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [Checklist](./js-utils.checklist.md) &gt; [(constructor)](./js-utils.checklist._constructor_.md)

## Checklist.(constructor)

Constructs a new instance of the `Checklist` class

<b>Signature:</b>

```typescript
constructor(options: ChecklistOptions<T>);
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| options | <code>ChecklistOptions&lt;T&gt;</code> | |

22 changes: 22 additions & 0 deletions docs/api/js-utils.checklist.check.md
@@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [Checklist](./js-utils.checklist.md) &gt; [check](./js-utils.checklist.check.md)

## Checklist.check() method

<b>Signature:</b>

```typescript
check(value: T): boolean;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| value | <code>T</code> | |

<b>Returns:</b>

`boolean`

11 changes: 11 additions & 0 deletions docs/api/js-utils.checklist.data.md
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [Checklist](./js-utils.checklist.md) &gt; [data](./js-utils.checklist.data.md)

## Checklist.data property

<b>Signature:</b>

```typescript
readonly data: Array<T>;
```
31 changes: 31 additions & 0 deletions docs/api/js-utils.checklist.md
@@ -0,0 +1,31 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [Checklist](./js-utils.checklist.md)

## Checklist class

<b>Signature:</b>

```typescript
export declare class Checklist<T> implements ChecklistOptions<T>
```
## Constructors
| Constructor | Modifiers | Description |
| --- | --- | --- |
| [(constructor)(options)](./js-utils.checklist._constructor_.md) | | Constructs a new instance of the <code>Checklist</code> class |
## Properties
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [data](./js-utils.checklist.data.md) | | <code>Array&lt;T&gt;</code> | |
| [mode](./js-utils.checklist.mode.md) | | <code>ChecklistMode</code> | |
## Methods
| Method | Modifiers | Description |
| --- | --- | --- |
| [check(value)](./js-utils.checklist.check.md) | | |
11 changes: 11 additions & 0 deletions docs/api/js-utils.checklist.mode.md
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [Checklist](./js-utils.checklist.md) &gt; [mode](./js-utils.checklist.mode.md)

## Checklist.mode property

<b>Signature:</b>

```typescript
readonly mode: ChecklistMode;
```
19 changes: 19 additions & 0 deletions docs/api/js-utils.checklistmode.md
@@ -0,0 +1,19 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [ChecklistMode](./js-utils.checklistmode.md)

## ChecklistMode enum

<b>Signature:</b>

```typescript
export declare enum ChecklistMode
```

## Enumeration Members

| Member | Value | Description |
| --- | --- | --- |
| EXCLUDE | <code>&quot;exclude&quot;</code> | |
| INCLUDE | <code>&quot;include&quot;</code> | |

11 changes: 11 additions & 0 deletions docs/api/js-utils.checklistoptions.data.md
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [ChecklistOptions](./js-utils.checklistoptions.md) &gt; [data](./js-utils.checklistoptions.data.md)

## ChecklistOptions.data property

<b>Signature:</b>

```typescript
data: Array<T>;
```
19 changes: 19 additions & 0 deletions docs/api/js-utils.checklistoptions.md
@@ -0,0 +1,19 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [ChecklistOptions](./js-utils.checklistoptions.md)

## ChecklistOptions interface

<b>Signature:</b>

```typescript
export interface ChecklistOptions<T>
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [data](./js-utils.checklistoptions.data.md) | <code>Array&lt;T&gt;</code> | |
| [mode](./js-utils.checklistoptions.mode.md) | <code>ChecklistMode</code> | |

11 changes: 11 additions & 0 deletions docs/api/js-utils.checklistoptions.mode.md
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [ChecklistOptions](./js-utils.checklistoptions.md) &gt; [mode](./js-utils.checklistoptions.mode.md)

## ChecklistOptions.mode property

<b>Signature:</b>

```typescript
mode: ChecklistMode;
```
8 changes: 8 additions & 0 deletions docs/api/js-utils.md
Expand Up @@ -10,13 +10,20 @@
| --- | --- |
| [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) | |
| [NotFoundError](./js-utils.notfounderror.md) | |
| [NotImplementedError](./js-utils.notimplementederror.md) | |
| [TimeoutError](./js-utils.timeouterror.md) | |

## Enumerations

| Enumeration | Description |
| --- | --- |
| [ChecklistMode](./js-utils.checklistmode.md) | |

## Functions

| Function | Description |
Expand Down Expand Up @@ -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) | |
Expand Down
4 changes: 2 additions & 2 deletions src/test/AsyncTracker.ts → 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;
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/index.ts
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion 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';

Expand Down
47 changes: 47 additions & 0 deletions 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<string>({
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<string>({
data: TEST_DATA,
mode: ChecklistMode.INCLUDE,
});
expect(list.check(MISSING_ITEM)).to.equal(false);
});
});
});

0 comments on commit e68d7f9

Please sign in to comment.