Skip to content

Commit

Permalink
feat: add @acot/mock package
Browse files Browse the repository at this point in the history
  • Loading branch information
wadackel committed Dec 28, 2020
1 parent 64078da commit fb6e4ba
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/mock/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/lib
15 changes: 15 additions & 0 deletions packages/mock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# @acot/mock

acot mock modules.

## Installation

Install via npm:

```bash
$ npm install --save @acot/mock
```

## Usage

_T.B.A_
32 changes: 32 additions & 0 deletions packages/mock/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@acot/mock",
"version": "0.0.1",
"description": "acot mock modules.",
"homepage": "https://github.com/acot-a11y/acot/tree/main/packages/mock",
"bugs": {
"url": "https://github.com/acot-a11y/acot/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/acot-a11y/acot.git",
"directory": "packages/mock"
},
"license": "MIT",
"author": "wadackel <wadackel@gmail.com>",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": ["lib", "!__mocks__", "!__tests__"],
"scripts": {
"build": "tsc"
},
"dependencies": {
"@acot/factory": "0.0.3",
"emittery": "^0.7.1"
},
"devDependencies": {
"@acot/types": "0.0.3"
},
"publishConfig": {
"access": "public"
}
}
50 changes: 50 additions & 0 deletions packages/mock/src/core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type {
Core,
CoreEventMap,
TestDescriptor,
EventListener,
Summary,
} from '@acot/types';
import { createSummary } from '@acot/factory';
import Emittery from 'emittery';

export class MockCore implements Core {
public version = 'mock';
public cases: [path: string, descriptor: TestDescriptor][] = [];
public summary: Summary = createSummary();
public emitter = new Emittery();

public add(path: string, descriptor: TestDescriptor): void {
this.cases.push([path, descriptor]);
}

public async audit(): Promise<Summary> {
this.emitter.emit('launch:start', []);
this.emitter.emit('launch:complete', []);
this.emitter.emit('audit:start', []);
this.emitter.emit('audit:complete', []);
this.emitter.emit('test:start', []);
this.emitter.emit('test:complete', []);
await this.close();
return this.summary;
}

public async close(): Promise<void> {
this.emitter.emit('close:start', []);
this.emitter.emit('close:complete', []);
}

public on<T extends keyof CoreEventMap>(
eventName: T,
listener: EventListener<CoreEventMap, T>,
): void {
this.emitter.on(eventName as any, listener as any);
}

public off<T extends keyof CoreEventMap>(
eventName: T,
listener?: EventListener<CoreEventMap, T>,
): void {
this.emitter.off(eventName as any, listener as any);
}
}
1 change: 1 addition & 0 deletions packages/mock/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './core';
7 changes: 7 additions & 0 deletions packages/mock/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "@acot/tsconfig",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src"
}
}

0 comments on commit fb6e4ba

Please sign in to comment.