Skip to content

Commit

Permalink
refactor: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranet committed Nov 9, 2023
1 parent fac73db commit f3421dd
Show file tree
Hide file tree
Showing 6 changed files with 375 additions and 460 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ FROM base as builder
ENV NODE_ENV="development"

COPY --chown=node:node tsconfig.base.json tsconfig.base.json
COPY --chown=node:node scripts/ scripts/
COPY --chown=node:node src/ src/

RUN yarn install --immutable
Expand All @@ -44,7 +43,6 @@ ENV NODE_OPTIONS="--enable-source-maps --max_old_space_size=4096"

COPY --chown=node:node --from=builder /usr/src/app/dist dist

COPY --chown=node:node scripts/workerTsLoader.mjs scripts/workerTsLoader.mjs
COPY --chown=node:node src/.env src/.env

RUN yarn workspaces focus --all --production
Expand Down
40 changes: 20 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@
"@sapphire/decorators": "^6.0.2",
"@sapphire/discord.js-utilities": "7.0.2",
"@sapphire/fetch": "^2.4.1",
"@sapphire/framework": "4.7.1",
"@sapphire/plugin-api": "^5.1.1",
"@sapphire/framework": "4.7.2",
"@sapphire/plugin-api": "^5.1.2",
"@sapphire/plugin-editable-commands": "^3.0.3",
"@sapphire/plugin-i18next": "^6.0.1",
"@sapphire/plugin-logger": "^3.0.6",
"@sapphire/plugin-subcommands": "^4.2.2",
"@sapphire/plugin-subcommands": "^5.0.0",
"@sapphire/ratelimits": "^2.4.7",
"@sapphire/snowflake": "^3.5.1",
"@sapphire/stopwatch": "^1.5.0",
"@sapphire/time-utilities": "^1.7.10",
"@sapphire/utilities": "^3.13.0",
"@sentry/hub": "^7.74.1",
"@sentry/integrations": "^7.74.1",
"@sentry/node": "^7.74.1",
"@sentry/hub": "^7.79.0",
"@sentry/integrations": "^7.79.0",
"@sentry/node": "^7.79.0",
"@skyra/ai": "^1.2.0",
"@skyra/char": "^1.0.3",
"@skyra/env-utilities": "^1.2.1",
Expand All @@ -79,39 +79,39 @@
"colorette": "^2.0.20",
"confusables": "^1.1.1",
"diff": "^5.1.0",
"discord-api-types": "~0.37.60",
"discord-api-types": "~0.37.62",
"discord.js": "^14.13.0",
"he": "^1.2.0",
"pg": "^8.11.3",
"typeorm": "0.3.17",
"typeorm-naming-strategies": "^4.1.0",
"zlib-sync": "^0.1.8"
"zlib-sync": "^0.1.9"
},
"devDependencies": {
"0x": "^5.7.0",
"@commitlint/cli": "^17.8.1",
"@commitlint/config-conventional": "^17.8.1",
"@commitlint/cli": "^18.2.0",
"@commitlint/config-conventional": "^18.1.0",
"@sapphire/eslint-config": "^5.0.2",
"@sapphire/prettier-config": "^2.0.0",
"@sapphire/ts-config": "^5.0.0",
"@types/backoff": "^2.5.4",
"@types/diff": "^5.0.7",
"@types/he": "^1.2.2",
"@types/node": "^18.18.6",
"@types/pg": "^8.10.7",
"@types/ws": "^8.5.8",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"@types/backoff": "^2.5.5",
"@types/diff": "^5.0.8",
"@types/he": "^1.2.3",
"@types/node": "^20.9.0",
"@types/pg": "^8.10.9",
"@types/ws": "^8.5.9",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"@vitest/coverage-v8": "^0.34.6",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.52.0",
"eslint": "^8.53.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.1",
"lint-staged": "^15.0.2",
"prettier": "^3.0.3",
"ts-node": "^10.9.1",
"tsc-watch": "^6.0.4",
"tsx": "^3.14.0",
"tsx": "^4.0.0",
"typescript": "^5.2.2",
"vitest": "^0.34.6"
},
Expand Down
8 changes: 0 additions & 8 deletions scripts/workerTsLoader.mjs

This file was deleted.

7 changes: 2 additions & 5 deletions src/lib/moderation/workers/WorkerHandler.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { WorkerResponseHandler } from '#lib/moderation/workers/WorkerResponseHandler';
import { OutgoingType, type IncomingPayload, type NoId, type OutgoingPayload } from '#lib/moderation/workers/types';
import { rootFolder } from '#utils/constants';
import { AsyncQueue } from '@sapphire/async-queue';
import { container } from '@sapphire/framework';
import { envParseString } from '@skyra/env-utilities';
import { cyan, green, red, yellow } from 'colorette';
import { once } from 'node:events';
import { join } from 'node:path';
import { Worker } from 'node:worker_threads';

export class WorkerHandler {
Expand Down Expand Up @@ -63,7 +61,7 @@ export class WorkerHandler {
public spawn() {
this.online = false;
this.lastHeartBeat = 0;
this.worker = new Worker(WorkerHandler.workerTsLoader, {
this.worker = new Worker(WorkerHandler.filename, {
workerData: {
path: WorkerHandler.filename
}
Expand Down Expand Up @@ -132,9 +130,8 @@ export class WorkerHandler {
}
}

private static readonly workerTsLoader = join(rootFolder, 'scripts', 'workerTsLoader.mjs');
private static readonly logsEnabled = process.env.NODE_ENV !== 'test';
private static readonly filename = new URL(`./worker.${envParseString('NODE_ENV') === 'test' ? 't' : 'j'}s`, import.meta.url).href;
private static readonly filename = new URL(`./worker.${envParseString('NODE_ENV') === 'test' ? 't' : 'j'}s`, import.meta.url);

private static readonly maximumId = Number.MAX_SAFE_INTEGER;
}
6 changes: 5 additions & 1 deletion src/lib/moderation/workers/worker.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { IncomingType, OutgoingType, type IncomingPayload, type IncomingRunRegExpPayload, type OutgoingPayload } from '#lib/moderation/workers';
import type { IncomingPayload, IncomingRunRegExpPayload, OutgoingPayload } from '#lib/moderation/workers/types';
import { remove as removeConfusables } from 'confusables';
import { isMainThread, parentPort } from 'node:worker_threads';

if (isMainThread || parentPort === null) throw new Error('The Worker may only be ran via the worker_threads fork method!');

const { IncomingType, OutgoingType } = (await import(
process.env.NODE_ENV === 'test' ? './types.ts' : '#lib/moderation/workers/types'
)) as typeof import('./types.js');

function post(message: OutgoingPayload) {
return parentPort!.postMessage(message);
}
Expand Down
Loading

0 comments on commit f3421dd

Please sign in to comment.