Skip to content

Commit

Permalink
facade lib + test reset
Browse files Browse the repository at this point in the history
  • Loading branch information
dearlordylord committed Jan 7, 2024
1 parent 4d3aea7 commit 8d0732b
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
TODO keywords: persistent, (optionally) deterministic
TODO keywords: immutable/functional, (optionally) deterministic, 0 dependency
25 changes: 25 additions & 0 deletions facade/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": ["../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": "error"
}
}
]
}
1 change: 1 addition & 0 deletions facade/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm facade for the project
11 changes: 11 additions & 0 deletions facade/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
displayName: 'facade',
preset: '../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../coverage/facade',
};
11 changes: 11 additions & 0 deletions facade/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@jikan/facade",
"version": "0.0.1",
"dependencies": {
"tslib": "^2.3.0",
"@jikan/fsm": "*"
},
"type": "commonjs",
"main": "./src/index.js",
"typings": "./src/index.d.ts"
}
30 changes: 30 additions & 0 deletions facade/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "facade",
"$schema": "../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "facade/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/facade",
"main": "facade/src/index.ts",
"tsConfig": "facade/tsconfig.lib.json",
"assets": ["facade/*.md"]
}
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"]
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "facade/jest.config.ts"
}
}
},
"tags": []
}
13 changes: 13 additions & 0 deletions facade/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export {
empty,
State,
QueueItem,
isEmpty,
current,
currentNE,
tick,
push,
pop,
restart,
reset,
} from '@jikan/fsm';
22 changes: 22 additions & 0 deletions facade/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
10 changes: 10 additions & 0 deletions facade/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
}
14 changes: 14 additions & 0 deletions facade/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
12 changes: 2 additions & 10 deletions fsm/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
# fsm
core logic for timers

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build fsm` to build the library.

## Running unit tests

Run `nx test fsm` to execute the unit tests via [Jest](https://jestjs.io).
implemented as a queue of intervals and a tick(number)
44 changes: 43 additions & 1 deletion fsm/src/lib/fsm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
isEmpty,
pop,
push,
restart,
QueueItem,
showPrintDuration0QueueItemError,
State,
Expand Down Expand Up @@ -91,7 +92,6 @@ describe('fsm', () => {
{
kind: 'd',
duration: 1,

},
// @ts-expect-error type 'd' won't be accepted here
])(empty<'a' | 'b' | 'c'>());
Expand Down Expand Up @@ -206,6 +206,48 @@ describe('fsm', () => {
expect(s2).toEqual(empty());
});
});
describe('restart', () => {
it('noops', () => {
const s0 = empty<'a'>();
const s1 = push([
{
kind: 'a',
duration: 2,
},
{
kind: 'b',
duration: 3,
},
])(s0);
expect(s1.duration).toBe(2);
const s2 = restart(s1);
expect(s2.duration).toBe(2);
});
it('noops on state0', () => {
const s0 = empty<'a'>();
expect(s0.duration).toBe(0);
const s1 = restart(s0);
expect(s1.duration).toBe(0);
});
it('restarts the current item', () => {
const s0 = empty<'a'>();
const s1 = push([
{
kind: 'a',
duration: 2,
},
{
kind: 'b',
duration: 3,
},
])(s0);
expect(s1.duration).toBe(2);
const s2 = tick(1)(s1)[0];
expect(s2.duration).toBe(1);
const s3 = restart(s2);
expect(s3.duration).toBe(2);
});
});
describe('raw simulation', () => {
const naiveSimulationTest = (program: QueueItem<string>[]) => {
const [state, runLog] = program.reduce<
Expand Down
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"skipDefaultLibCheck": true,
"baseUrl": ".",
"paths": {
"@jikan/facade": ["facade/src/index.ts"],
"@jikan/fsm": ["fsm/src/index.ts"],
"@jikan/utils": ["utils/src/index.ts"]
}
Expand Down

0 comments on commit 8d0732b

Please sign in to comment.