Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(test): cover pid file, signal helpers, improve coverage for others
- Loading branch information
Showing
16 changed files
with
212 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@apextoaster/js-utils](./js-utils.md) > [AsyncTracker](./js-utils.asynctracker.md) > [filter](./js-utils.asynctracker.filter.md) | ||
|
||
## AsyncTracker.filter property | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
filter: Optional<StackFilter>; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
<b>Signature:</b> | ||
|
||
```typescript | ||
static getStack(): string; | ||
getStack(): string; | ||
``` | ||
<b>Returns:</b> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
|
||
## isNil() function | ||
|
||
Check if a value is nil. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
|
||
Return the first value that is not nil. | ||
|
||
TODO: rename to mustDefault | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { expect } from 'chai'; | ||
import mockFS from 'mock-fs'; | ||
|
||
import { removePid, writePid } from '../../src'; | ||
import { describeLeaks, itLeaks } from '../helpers/async'; | ||
|
||
const PID_PATH = 'foo'; | ||
const PID_NAME = 'foo/test.pid'; | ||
|
||
describeLeaks('pid file utils', async () => { | ||
beforeEach(() => { | ||
mockFS({ | ||
[PID_PATH]: mockFS.directory(), | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
mockFS.restore(); | ||
}); | ||
|
||
itLeaks('should create a marker', async () => { | ||
await writePid(PID_NAME); | ||
|
||
mockFS.restore(); | ||
}); | ||
|
||
itLeaks('should not replace an existing marker', async () => { | ||
await writePid(PID_NAME); | ||
return expect(writePid(PID_PATH)).to.eventually.be.rejectedWith(Error); | ||
}); | ||
|
||
itLeaks('should remove an existing marker', async () => { | ||
await writePid(PID_NAME); | ||
await removePid(PID_NAME); | ||
|
||
mockFS.restore(); | ||
}); | ||
|
||
itLeaks('should fail to remove a missing marker', async () => | ||
expect(removePid(PID_PATH)).to.eventually.be.rejectedWith(Error) | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,33 @@ | ||
import { expect } from 'chai'; | ||
import { getMethods } from '../../src/utils/Reflect'; | ||
import { getMethods, getConstructor, constructorName } from '../../src/utils/Reflect'; | ||
|
||
class Test { | ||
public foo() { /* noop */ } | ||
public bar() { /* noop */ } | ||
} | ||
|
||
describe('reflect utils', () => { | ||
describe('get methods helper', () => { | ||
it('should collect method functions', () => { | ||
class Test { | ||
public foo() { /* noop */ } | ||
public bar() { /* noop */ } | ||
} | ||
|
||
const methods = getMethods(new Test()).values(); | ||
|
||
/* eslint-disable @typescript-eslint/unbound-method */ | ||
expect(methods).to.include(Test.prototype.foo); | ||
expect(methods).to.include(Test.prototype.bar); | ||
}); | ||
}); | ||
|
||
describe('get constructor helper', () => { | ||
it('should get the constructor from an instance', () => { | ||
const instance = new Test(); | ||
expect(getConstructor(instance)).to.equal(Test); | ||
}); | ||
}); | ||
|
||
describe('get constructor name helper', () => { | ||
it('should get the constructor name from an instance', () => { | ||
const instance = new Test(); | ||
expect(constructorName(instance)).to.equal(Test.name); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { timeout } from '../../src/utils/Async'; | ||
import { signal, SIGNAL_RESET } from '../../src/utils/Signal'; | ||
import { describeLeaks, itLeaks } from '../helpers/async'; | ||
|
||
const MAX_SIGNAL_TIME = 500; | ||
|
||
describeLeaks('signal utils', async () => { | ||
itLeaks('should wait for a signal', async () => { | ||
const signalPromise = signal(SIGNAL_RESET); | ||
|
||
process.kill(process.pid, SIGNAL_RESET); | ||
await timeout(MAX_SIGNAL_TIME, signalPromise); | ||
|
||
const signalValue = await signalPromise; | ||
|
||
expect(signalValue).to.equal(SIGNAL_RESET); | ||
}); | ||
}); |
Oops, something went wrong.