@testring/test-utils
Advanced tools
+16
| # `@testring/test-utils` | ||
| ## Install | ||
| Using npm: | ||
| ``` | ||
| npm install --save-dev @testring/test-utils | ||
| ``` | ||
| or using yarn: | ||
| ``` | ||
| yarn add @testring/test-utils --dev | ||
| ``` |
@@ -6,6 +6,7 @@ "use strict"; | ||
| const fs = require("fs"); | ||
| exports.fileResolverFactory = (...root) => { | ||
| const fileResolverFactory = (...root) => { | ||
| return (...file) => path.resolve(...root, ...file); | ||
| }; | ||
| exports.fileReaderFactory = (...root) => { | ||
| exports.fileResolverFactory = fileResolverFactory; | ||
| const fileReaderFactory = (...root) => { | ||
| const resolver = exports.fileResolverFactory(...root); | ||
@@ -25,1 +26,2 @@ return (source) => { | ||
| }; | ||
| exports.fileReaderFactory = fileReaderFactory; |
+1
-0
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.fileResolverFactory = exports.fileReaderFactory = exports.BrowserProxyControllerMock = exports.TestWorkerMock = exports.TransportMock = void 0; | ||
| var transport_mock_1 = require("./transport.mock"); | ||
@@ -4,0 +5,0 @@ Object.defineProperty(exports, "TransportMock", { enumerable: true, get: function () { return transport_mock_1.TransportMock; } }); |
+2
-2
| { | ||
| "name": "@testring/test-utils", | ||
| "version": "0.5.36", | ||
| "version": "0.6.0", | ||
| "main": "./dist/index.js", | ||
@@ -13,4 +13,4 @@ "types": "./src/index.ts", | ||
| "dependencies": { | ||
| "@testring/types": "0.5.36" | ||
| "@testring/types": "0.6.0" | ||
| } | ||
| } |
@@ -1,2 +0,2 @@ | ||
| import { IBrowserProxyController, IBrowserProxyCommand } from '@testring/types'; | ||
| import {IBrowserProxyController, IBrowserProxyCommand} from '@testring/types'; | ||
@@ -3,0 +3,0 @@ export class BrowserProxyControllerMock implements IBrowserProxyController { |
+11
-7
@@ -13,11 +13,15 @@ import * as path from 'path'; | ||
| return new Promise((resolve, reject) => { | ||
| fs.readFile(resolver(source), 'utf8', (err: Error, file: string) => { | ||
| if (err) { | ||
| reject(err); | ||
| } else { | ||
| resolve(file); | ||
| } | ||
| }); | ||
| fs.readFile( | ||
| resolver(source), | ||
| 'utf8', | ||
| (err: Error, file: string) => { | ||
| if (err) { | ||
| reject(err); | ||
| } else { | ||
| resolve(file); | ||
| } | ||
| }, | ||
| ); | ||
| }); | ||
| }; | ||
| }; |
+4
-4
@@ -1,4 +0,4 @@ | ||
| export { TransportMock } from './transport.mock'; | ||
| export { TestWorkerMock } from './test-worker.mock'; | ||
| export { BrowserProxyControllerMock } from './browser-proxy-controller.mock'; | ||
| export { fileReaderFactory, fileResolverFactory } from './file-reader'; | ||
| export {TransportMock} from './transport.mock'; | ||
| export {TestWorkerMock} from './test-worker.mock'; | ||
| export {BrowserProxyControllerMock} from './browser-proxy-controller.mock'; | ||
| export {fileReaderFactory, fileResolverFactory} from './file-reader'; |
+20
-17
@@ -1,2 +0,2 @@ | ||
| import { ITestWorker, ITestWorkerInstance } from '@testring/types'; | ||
| import {ITestWorker, ITestWorkerInstance} from '@testring/types'; | ||
@@ -11,3 +11,2 @@ const ERROR_INSTANCE = { | ||
| class TestWorkerMockInstance implements ITestWorkerInstance { | ||
| private timeout: ReturnType<typeof setTimeout> | null = null; | ||
@@ -20,4 +19,3 @@ private callback: executionCallback | null = null; | ||
| constructor(private shouldFail: boolean, private executionDelay: number) { | ||
| } | ||
| constructor(private shouldFail: boolean, private executionDelay: number) {} | ||
@@ -33,19 +31,20 @@ getWorkerID() { | ||
| if (this.executionDelay > 0) { | ||
| return new Promise((resolve, reject) => { | ||
| return new Promise<void>((resolve, reject) => { | ||
| this.callback = () => resolve(); | ||
| this.timeout = setTimeout(() => reject(this.$getErrorInstance()), this.executionDelay); | ||
| this.timeout = setTimeout( | ||
| () => reject(this.$getErrorInstance()), | ||
| this.executionDelay, | ||
| ); | ||
| }); | ||
| } | ||
| return Promise.reject(this.$getErrorInstance()); | ||
| } | ||
| return Promise.reject(this.$getErrorInstance()); | ||
| } | ||
| if (this.executionDelay > 0) { | ||
| return new Promise((resolve) => { | ||
| return new Promise<void>((resolve) => { | ||
| this.callback = () => resolve(); | ||
| this.timeout = setTimeout(resolve, this.executionDelay); | ||
| }); | ||
| } | ||
| return Promise.resolve(); | ||
| } | ||
| return Promise.resolve(); | ||
| } | ||
@@ -82,10 +81,14 @@ | ||
| export class TestWorkerMock implements ITestWorker { | ||
| private spawnedInstances: Array<TestWorkerMockInstance> = []; | ||
| constructor(private shouldFail: boolean = false, private executionDelay: number = 0) { | ||
| } | ||
| constructor( | ||
| private shouldFail: boolean = false, | ||
| private executionDelay: number = 0, | ||
| ) {} | ||
| spawn() { | ||
| const instance = new TestWorkerMockInstance(this.shouldFail, this.executionDelay); | ||
| const instance = new TestWorkerMockInstance( | ||
| this.shouldFail, | ||
| this.executionDelay, | ||
| ); | ||
@@ -92,0 +95,0 @@ this.spawnedInstances.push(instance); |
+25
-10
@@ -1,8 +0,5 @@ | ||
| import { EventEmitter } from 'events'; | ||
| import { ITransport, IWorkerEmitter } from '@testring/types'; | ||
| import {EventEmitter} from 'events'; | ||
| import {ITransport, IWorkerEmitter} from '@testring/types'; | ||
| export class TransportMock extends EventEmitter implements ITransport { | ||
| private processes: Map<string, IWorkerEmitter> = new Map(); | ||
@@ -22,3 +19,7 @@ | ||
| public broadcastFrom<T = any>(messageType: string, payload: T, processID: string) { | ||
| public broadcastFrom<T = any>( | ||
| messageType: string, | ||
| payload: T, | ||
| processID: string, | ||
| ) { | ||
| this.emit(messageType, payload, processID); | ||
@@ -39,3 +40,7 @@ } | ||
| public send<T = any>(src: string, messageType: string, payload: T): Promise<void> { | ||
| public send<T = any>( | ||
| src: string, | ||
| messageType: string, | ||
| payload: T, | ||
| ): Promise<void> { | ||
| this.emit(messageType, payload); | ||
@@ -46,3 +51,6 @@ | ||
| public on<T = any>(messageType: string, callback: (m: T, source?: string) => void): any { | ||
| public on<T = any>( | ||
| messageType: string, | ||
| callback: (m: T, source?: string) => void, | ||
| ): any { | ||
| super.on(messageType, callback); | ||
@@ -54,3 +62,6 @@ | ||
| // eslint-disable-next-line sonarjs/no-identical-functions | ||
| public once<T = any>(messageType: string, callback: (m: T, source?: string) => void): any { | ||
| public once<T = any>( | ||
| messageType: string, | ||
| callback: (m: T, source?: string) => void, | ||
| ): any { | ||
| super.on(messageType, callback); | ||
@@ -61,3 +72,7 @@ | ||
| public onceFrom<T = any>(processID: string, messageType: string, callback: (m: T, source?: string) => void): any { | ||
| public onceFrom<T = any>( | ||
| processID: string, | ||
| messageType: string, | ||
| callback: (m: T, source?: string) => void, | ||
| ): any { | ||
| const handler = (message, source) => { | ||
@@ -64,0 +79,0 @@ if (processID === source) { |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
15490
4.81%13
8.33%435
7.94%1
-50%16
Infinity%+ Added
+ Added
- Removed
Updated