Skip to content

Commit

Permalink
feat(*): update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
neki-dev committed Sep 13, 2024
1 parent 4f258c8 commit 37f06da
Show file tree
Hide file tree
Showing 30 changed files with 580 additions and 617 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ jobs:
node-version: '20.x'
- name: Install
run: yarn install
- name: Build
run: yarn build:worker
- name: Test
run: yarn test
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.git
.idea
node_modules/
.tmp
.temp
.DS_Store
45 changes: 5 additions & 40 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,5 @@
import { Worker } from 'worker_threads';
import { PathfindingEvents } from './events';
import { PathfindingLayer } from './layer';
import type { PathfindingTaskCallback, PathfindingTaskResult } from './task/types';
import type { PathfindingGrid, PathfindingConfig, PathfindingPoint } from './types';
export declare class Pathfinding {
readonly worker: Worker;
readonly events: PathfindingEvents;
private readonly layers;
/**
* Create pathfinding worker thread.
*
* @param config - Pathfinding configuration
*/
constructor({ loopRate, resourceLimits }?: PathfindingConfig);
/**
* Terminate worker thread.
*/
destroy(): Promise<number>;
/**
* Create a new layer of grid.
*
* @param grid - Grid with walkable tiles
*/
createLayer(grid: PathfindingGrid): PathfindingLayer;
/**
* Check for layer presence.
*
* @param id - Layer id
*/
hasLayer(id: string): boolean;
/**
* Remove layer of grid.
*
* @param id - Layer id
*/
removeLayer(id: string): void;
private unflatPath;
}
export type { PathfindingGrid, PathfindingPoint, PathfindingLayer, PathfindingTaskCallback, PathfindingTaskResult, };
export { Pathfinding } from './pathfinding';
import type { PathfindingLayer } from './layer';
import type { PathfindingTaskCallback, PathfindingTaskConfig, PathfindingTaskResult } from './task/types';
import type { PathfindingGrid, PathfindingPoint } from './types';
export type { PathfindingGrid, PathfindingPoint, PathfindingLayer, PathfindingTaskCallback, PathfindingTaskConfig, PathfindingTaskResult, };
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/layer/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Pathfinding } from '..';
import type { PathfindingTaskCallback } from '../task/types';
import type { PathfindingGrid, PathfindingPoint, PathfindingTaskConfig } from '../types';
import type { Pathfinding } from '../pathfinding';
import type { PathfindingTaskCallback, PathfindingTaskConfig } from '../task/types';
import type { PathfindingGrid, PathfindingPoint } from '../types';
export declare class PathfindingLayer {
readonly uuid: string;
readonly id: string;
private readonly pathfinding;
private readonly grid;
private readonly weights;
Expand Down
39 changes: 39 additions & 0 deletions dist/pathfinding/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Worker } from 'worker_threads';
import { PathfindingEvents } from '../events';
import { PathfindingLayer } from '../layer';
import type { PathfindingConfig } from './types';
import type { PathfindingGrid } from '../types';
export declare class Pathfinding {
readonly worker: Worker;
readonly events: PathfindingEvents;
private readonly layers;
/**
* Create pathfinding worker thread.
*
* @param config - Pathfinding configuration
*/
constructor({ loopRate, resourceLimits }?: PathfindingConfig);
/**
* Terminate worker thread.
*/
destroy(): Promise<number>;
/**
* Create a new layer of grid.
*
* @param grid - Grid with walkable tiles
*/
createLayer(grid: PathfindingGrid): PathfindingLayer;
/**
* Check for layer presence.
*
* @param id - Layer id
*/
hasLayer(id: string): boolean;
/**
* Remove layer of grid.
*
* @param id - Layer id
*/
removeLayer(id: string): void;
private static unflatPath;
}
12 changes: 12 additions & 0 deletions dist/pathfinding/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { ResourceLimits } from 'worker_threads';
export type PathfindingConfig = {
/**
* Finding process loop rate
* Default: 200 ms
*/
loopRate?: number;
/**
* Worker resource limits
*/
resourceLimits?: ResourceLimits;
};
17 changes: 17 additions & 0 deletions dist/task/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
import type { PathfindingPoint } from '../types';
/**
* Parameters for task create
*/
export type PathfindingTaskConfig = {
/**
* Begin tile position
*/
from: PathfindingPoint;
/**
* End tile position
*/
to: PathfindingPoint;
/**
* Allow diagonal directions
*/
diagonals?: boolean;
};
/**
* Task result
*/
Expand Down
26 changes: 0 additions & 26 deletions dist/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
import type { ResourceLimits } from 'worker_threads';
export type PathfindingConfig = {
/**
* Finding process loop rate
* Default: 200 ms
*/
loopRate?: number;
/**
* Worker resource limits
*/
resourceLimits?: ResourceLimits;
};
export type PathfindingTaskConfig = {
/**
* Begin tile position
*/
from: PathfindingPoint;
/**
* End tile position
*/
to: PathfindingPoint;
/**
* Allow diagonal directions
*/
diagonals?: boolean;
};
/**
* Grid cell position
*/
Expand Down
File renamed without changes.
6 changes: 0 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,4 @@ module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
verbose: true,
setupFilesAfterEnv: [
'<rootDir>/src/__mocks__/worker-module.ts',
],
moduleNameMapper: {
'.*\\.inline\\.js': '<rootDir>/src/__mocks__/inline.ts',
},
};
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
},
"main": "./dist/index.js",
"scripts": {
"build": "yarn build:worker && yarn build:entrypoint && yarn clear",
"build": "yarn build:worker && yarn build:entrypoint",
"build:worker": "webpack --config ./webpack/worker.config.js --mode production",
"build:entrypoint": "webpack --config ./webpack/entrypoint.config.js --mode production",
"clear": "rm -R ./.tmp",
"test": "jest",
"lint": "eslint \"./src/**/*.ts\" --fix"
},
Expand Down
13 changes: 0 additions & 13 deletions src/__mocks__/worker-module.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/__mocks__/worker.ts

This file was deleted.

157 changes: 0 additions & 157 deletions src/index.test.ts

This file was deleted.

Loading

0 comments on commit 37f06da

Please sign in to comment.