build: Properly add typecheck tests (#10722)

* build: exclude type tests from running

* refactor: use `tsc`

* test: fix broker test

* test: fix voice test

* test: fix builders test

* test: use vitest typecheck

remove unused test scripts
skip lib check
rm vitest.d.ts

* fix: remove tsd from core and ws

* fix: extend local tsconfig

---------

Co-authored-by: almeidx <github@almeidx.dev>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Jiralite
2025-01-26 14:28:45 +00:00
committed by GitHub
parent b820daadd4
commit 9b8b0f828c
44 changed files with 443 additions and 479 deletions

View File

@@ -5,7 +5,7 @@
"description": "A set of actions that we use for our workflows",
"private": true,
"scripts": {
"test": "vitest run",
"test": "vitest run --config ../../vitest.config.ts",
"build": "tsc --noEmit --lib ESNext,DOM && tsup",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",

View File

@@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true,
"skipLibCheck": true
},
"include": ["__tests__/**/*.ts"],
"exclude": ["node_modules"]
}

View File

@@ -17,7 +17,7 @@ const mockRedisClient = {
test('pubsub with custom encoding', async () => {
const encode = vi.fn((data) => data);
const broker = new PubSubRedisBroker(mockRedisClient, { encode });
const broker = new PubSubRedisBroker(mockRedisClient, { encode, group: 'group' });
await broker.publish('test', 'test');
expect(encode).toHaveBeenCalledWith('test');
});

View File

@@ -4,7 +4,7 @@
"version": "1.0.0",
"description": "Powerful set of message brokers",
"scripts": {
"test": "vitest run",
"test": "vitest run --config ../../vitest.config.ts",
"build": "tsc --noEmit --lib ESNext,DOM && tsup",
"build:docs": "tsc -p tsconfig.docs.json --lib ESNext,DOM",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",

View File

@@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true,
"skipLibCheck": true
},
"include": ["__tests__/**/*.ts"],
"exclude": ["node_modules"]
}

View File

@@ -4,7 +4,7 @@
"version": "1.9.0",
"description": "A set of builders that you can use when creating your bot",
"scripts": {
"test": "vitest run",
"test": "vitest run --config ../../vitest.config.ts",
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",

View File

@@ -5,6 +5,6 @@
"emitDecoratorMetadata": true,
"exactOptionalPropertyTypes": false
},
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.cjs", "src/**/*.mjs", "bin", "__tests__", "../../vitest.d.ts"],
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.cjs", "src/**/*.mjs", "bin"],
"exclude": ["node_modules"]
}

View File

@@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true,
"skipLibCheck": true
},
"include": ["__tests__/**/*.ts"],
"exclude": ["node_modules"]
}

View File

@@ -4,7 +4,7 @@
"version": "2.1.1",
"description": "Utility data structure used in discord.js",
"scripts": {
"test": "vitest run",
"test": "vitest run --config ../../vitest.config.ts",
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",

View File

@@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true,
"skipLibCheck": true
},
"include": ["__tests__/**/*.ts"],
"exclude": ["node_modules"]
}

View File

@@ -0,0 +1,160 @@
import { REST } from '@discordjs/rest';
import type {
APIActionRowComponent,
APIModalActionRowComponent,
RESTPostAPIInteractionCallbackWithResponseResult,
} from 'discord-api-types/v10';
import { expectTypeOf, describe, test } from 'vitest';
import { API } from '../src/index.js';
const rest = new REST();
const api = new API(rest);
const SNOWFLAKE = '123456789012345678' as const;
const TOKEN = 'token' as const;
const MODAL_COMPONENTS: APIActionRowComponent<APIModalActionRowComponent>[] = [] as const;
const boolValue = true as boolean;
describe('Interaction with_response overloads.', () => {
test('Replying returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
expectTypeOf(api.interactions.reply(SNOWFLAKE, TOKEN, { with_response: true })).toEqualTypeOf<
Promise<RESTPostAPIInteractionCallbackWithResponseResult>
>());
test('Replying returns undefined.', () => {
expectTypeOf(api.interactions.reply(SNOWFLAKE, TOKEN, {})).toEqualTypeOf<Promise<undefined>>();
expectTypeOf(api.interactions.reply(SNOWFLAKE, TOKEN, { with_response: false })).toEqualTypeOf<
Promise<undefined>
>();
});
test('Replying returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
expectTypeOf(api.interactions.reply(SNOWFLAKE, TOKEN, { with_response: boolValue })).toEqualTypeOf<
Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>
>();
});
test('Defer returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
expectTypeOf(api.interactions.defer(SNOWFLAKE, TOKEN, { with_response: true })).toEqualTypeOf<
Promise<RESTPostAPIInteractionCallbackWithResponseResult>
>());
test('Defer returns undefined.', () => {
expectTypeOf(api.interactions.defer(SNOWFLAKE, TOKEN)).toEqualTypeOf<Promise<undefined>>();
expectTypeOf(api.interactions.defer(SNOWFLAKE, TOKEN, { with_response: false })).toEqualTypeOf<
Promise<undefined>
>();
});
test('Defer returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
expectTypeOf(api.interactions.defer(SNOWFLAKE, TOKEN, { with_response: boolValue })).toEqualTypeOf<
Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>
>();
});
test('Defer message update returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
expectTypeOf(api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN, { with_response: true })).toEqualTypeOf<
Promise<RESTPostAPIInteractionCallbackWithResponseResult>
>());
test('Defer message update returns undefined.', () => {
expectTypeOf(api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN)).toEqualTypeOf<Promise<undefined>>();
expectTypeOf(api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN, { with_response: false })).toEqualTypeOf<
Promise<undefined>
>();
});
test('Defer message update returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
expectTypeOf(api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN, { with_response: boolValue })).toEqualTypeOf<
Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>
>();
});
test('Update message returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
expectTypeOf(api.interactions.updateMessage(SNOWFLAKE, TOKEN, { with_response: true })).toEqualTypeOf<
Promise<RESTPostAPIInteractionCallbackWithResponseResult>
>());
test('Update message returns undefined.', () => {
expectTypeOf(api.interactions.updateMessage(SNOWFLAKE, TOKEN, {})).toEqualTypeOf<Promise<undefined>>();
expectTypeOf(api.interactions.updateMessage(SNOWFLAKE, TOKEN, { with_response: false })).toEqualTypeOf<
Promise<undefined>
>();
});
test('Update message returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
expectTypeOf(api.interactions.updateMessage(SNOWFLAKE, TOKEN, { with_response: boolValue })).toEqualTypeOf<
Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>
>();
});
test('Create autocomplete response returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
expectTypeOf(api.interactions.createAutocompleteResponse(SNOWFLAKE, TOKEN, { with_response: true })).toEqualTypeOf<
Promise<RESTPostAPIInteractionCallbackWithResponseResult>
>());
test('Create autocomplete response returns undefined.', () => {
expectTypeOf(api.interactions.createAutocompleteResponse(SNOWFLAKE, TOKEN, {})).toEqualTypeOf<Promise<undefined>>();
expectTypeOf(api.interactions.createAutocompleteResponse(SNOWFLAKE, TOKEN, { with_response: false })).toEqualTypeOf<
Promise<undefined>
>();
});
test('Create autocomplete response returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
expectTypeOf(
api.interactions.createAutocompleteResponse(SNOWFLAKE, TOKEN, { with_response: boolValue }),
).toEqualTypeOf<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>();
});
test('Create modal returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
expectTypeOf(
api.interactions.createModal(SNOWFLAKE, TOKEN, {
title: '',
custom_id: '',
components: MODAL_COMPONENTS,
with_response: true,
}),
).toEqualTypeOf<Promise<RESTPostAPIInteractionCallbackWithResponseResult>>());
test('Create modal returns undefined.', () => {
expectTypeOf(
api.interactions.createModal(SNOWFLAKE, TOKEN, { title: '', custom_id: '', components: MODAL_COMPONENTS }),
).toEqualTypeOf<Promise<undefined>>();
expectTypeOf(
api.interactions.createModal(SNOWFLAKE, TOKEN, {
title: '',
custom_id: '',
components: MODAL_COMPONENTS,
with_response: false,
}),
).toEqualTypeOf<Promise<undefined>>();
});
test('Create modal returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
expectTypeOf(
api.interactions.createModal(SNOWFLAKE, TOKEN, {
title: '',
custom_id: '',
components: MODAL_COMPONENTS,
with_response: boolValue,
}),
).toEqualTypeOf<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>();
});
test('Launch activity returns undefined.', () => {
expectTypeOf(api.interactions.launchActivity(SNOWFLAKE, TOKEN, { with_response: false })).toEqualTypeOf<
Promise<undefined>
>();
expectTypeOf(api.interactions.launchActivity(SNOWFLAKE, TOKEN)).toEqualTypeOf<Promise<undefined>>();
});
test('Launch activity returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
expectTypeOf(api.interactions.launchActivity(SNOWFLAKE, TOKEN, { with_response: true })).toEqualTypeOf<
Promise<RESTPostAPIInteractionCallbackWithResponseResult>
>());
test('Launch activity returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () =>
expectTypeOf(api.interactions.launchActivity(SNOWFLAKE, TOKEN, { with_response: boolValue })).toEqualTypeOf<
Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>
>());
});

View File

@@ -1,149 +0,0 @@
import { REST } from '@discordjs/rest';
import type {
APIActionRowComponent,
APIModalActionRowComponent,
RESTPostAPIInteractionCallbackWithResponseResult,
} from 'discord-api-types/v10';
import { assertType, describe, test } from 'vitest';
import { API } from '../src/index.js';
const rest = new REST();
const api = new API(rest);
const SNOWFLAKE = '123456789012345678' as const;
const TOKEN = 'token' as const;
const MODAL_COMPONENTS: APIActionRowComponent<APIModalActionRowComponent>[] = [] as const;
const boolValue = true as boolean;
describe('Interaction with_response overloads.', () => {
test('Replying returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult>>(
api.interactions.reply(SNOWFLAKE, TOKEN, { with_response: true }),
));
test('Replying returns undefined.', () => {
assertType<Promise<undefined>>(api.interactions.reply(SNOWFLAKE, TOKEN, {}));
assertType<Promise<undefined>>(api.interactions.reply(SNOWFLAKE, TOKEN, { with_response: false }));
});
test('Replying returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>(
api.interactions.reply(SNOWFLAKE, TOKEN, { with_response: boolValue }),
);
});
test('Defer returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult>>(
api.interactions.defer(SNOWFLAKE, TOKEN, { with_response: true }),
));
test('Defer returns undefined.', () => {
assertType<Promise<undefined>>(api.interactions.defer(SNOWFLAKE, TOKEN));
assertType<Promise<undefined>>(api.interactions.defer(SNOWFLAKE, TOKEN, { with_response: false }));
});
test('Defer returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>(
api.interactions.defer(SNOWFLAKE, TOKEN, { with_response: boolValue }),
);
});
test('Defer message update returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult>>(
api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN, { with_response: true }),
));
test('Defer message update returns undefined.', () => {
assertType<Promise<undefined>>(api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN));
assertType<Promise<undefined>>(api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN, { with_response: false }));
});
test('Defer message update returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>(
api.interactions.deferMessageUpdate(SNOWFLAKE, TOKEN, { with_response: boolValue }),
);
});
test('Update message returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult>>(
api.interactions.updateMessage(SNOWFLAKE, TOKEN, { with_response: true }),
));
test('Update message returns undefined.', () => {
assertType<Promise<undefined>>(api.interactions.updateMessage(SNOWFLAKE, TOKEN, {}));
assertType<Promise<undefined>>(api.interactions.updateMessage(SNOWFLAKE, TOKEN, { with_response: false }));
});
test('Update message returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>(
api.interactions.updateMessage(SNOWFLAKE, TOKEN, { with_response: boolValue }),
);
});
test('Create autocomplete response returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult>>(
api.interactions.createAutocompleteResponse(SNOWFLAKE, TOKEN, { with_response: true }),
));
test('Create autocomplete response returns undefined.', () => {
assertType<Promise<undefined>>(api.interactions.createAutocompleteResponse(SNOWFLAKE, TOKEN, {}));
assertType<Promise<undefined>>(
api.interactions.createAutocompleteResponse(SNOWFLAKE, TOKEN, { with_response: false }),
);
});
test('Create autocomplete response returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>(
api.interactions.createAutocompleteResponse(SNOWFLAKE, TOKEN, { with_response: boolValue }),
);
});
test('Create modal returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult>>(
api.interactions.createModal(SNOWFLAKE, TOKEN, {
title: '',
custom_id: '',
components: MODAL_COMPONENTS,
with_response: true,
}),
));
test('Create modal returns undefined.', () => {
assertType<Promise<undefined>>(
api.interactions.createModal(SNOWFLAKE, TOKEN, { title: '', custom_id: '', components: MODAL_COMPONENTS }),
);
assertType<Promise<undefined>>(
api.interactions.createModal(SNOWFLAKE, TOKEN, {
title: '',
custom_id: '',
components: MODAL_COMPONENTS,
with_response: false,
}),
);
});
test('Create modal returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => {
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>(
api.interactions.createModal(SNOWFLAKE, TOKEN, {
title: '',
custom_id: '',
components: MODAL_COMPONENTS,
with_response: boolValue,
}),
);
});
test('Launch activity returns undefined.', () => {
assertType<Promise<undefined>>(api.interactions.launchActivity(SNOWFLAKE, TOKEN, { with_response: false }));
assertType<Promise<undefined>>(api.interactions.launchActivity(SNOWFLAKE, TOKEN));
});
test('Launch activity returns RESTPostAPIInteractionCallbackWithResponseResult.', () =>
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult>>(
api.interactions.launchActivity(SNOWFLAKE, TOKEN, { with_response: true }),
));
test('Launch activity returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () =>
assertType<Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>>(
api.interactions.launchActivity(SNOWFLAKE, TOKEN, { with_response: boolValue }),
));
});

View File

@@ -4,7 +4,7 @@
"version": "2.0.0",
"description": "A thinly abstracted wrapper around the rest API, and gateway.",
"scripts": {
"test": "vitest run",
"test": "vitest run --config ../../vitest.config.ts",
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src",

View File

@@ -1,6 +1,6 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "../../tsconfig.json",
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.cjs", "src/**/*.mjs", "bin", "__tests__", "../../vitest.d.ts"],
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.cjs", "src/**/*.mjs", "bin"],
"exclude": ["node_modules"]
}

View File

@@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true,
"skipLibCheck": true
},
"include": ["__tests__/**/*.ts"],
"exclude": ["node_modules"]
}

View File

@@ -61,7 +61,6 @@
"@types/node": "^20.17.10",
"@types/prompts": "^2.4.9",
"@types/validate-npm-package-name": "^4.0.2",
"@vitest/coverage-v8": "^2.1.8",
"cross-env": "^7.0.3",
"eslint": "^8.57.1",
"eslint-config-neon": "^0.1.62",
@@ -69,8 +68,7 @@
"prettier": "^3.4.2",
"terser": "^5.37.0",
"tsup": "^8.3.5",
"typescript": "~5.5.4",
"vitest": "^2.1.8"
"typescript": "~5.5.4"
},
"engines": {
"node": ">=20"

View File

@@ -4,7 +4,7 @@
"version": "0.5.0",
"description": "A set of functions to format strings for Discord.",
"scripts": {
"test": "vitest run",
"test": "vitest run --config ../../vitest.config.ts",
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",

View File

@@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true,
"skipLibCheck": true
},
"include": ["__tests__/**/*.ts"],
"exclude": ["node_modules"]
}

View File

@@ -4,7 +4,7 @@
"version": "0.1.0",
"description": "A powerful TypeScript library for interacting with the Discord API",
"scripts": {
"test": "vitest run",
"test": "vitest run --config ../../vitest.config.ts",
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",

View File

@@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true,
"skipLibCheck": true
},
"include": ["__tests__/**/*.ts"],
"exclude": ["node_modules"]
}

View File

@@ -4,7 +4,7 @@
"version": "2.1.1",
"description": "Tools for running an HTTP proxy for Discord's API",
"scripts": {
"test": "vitest run",
"test": "vitest run --config ../../vitest.config.ts",
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",

View File

@@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true,
"skipLibCheck": true
},
"include": ["__tests__/**/*.ts"],
"exclude": ["node_modules"]
}

View File

@@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true,
"skipLibCheck": true
},
"include": ["__tests__/**/*.ts"],
"exclude": ["node_modules"]
}

View File

@@ -75,7 +75,6 @@
"devDependencies": {
"@turbo/gen": "^2.3.3",
"@types/node": "^20.17.10",
"@vitest/coverage-v8": "^2.1.8",
"cross-env": "^7.0.3",
"env-cmd": "^10.1.0",
"eslint": "^8.57.1",
@@ -84,8 +83,7 @@
"prettier": "^3.4.2",
"tsup": "^8.3.5",
"turbo": "^2.3.3",
"typescript": "~5.5.4",
"vitest": "^2.1.8"
"typescript": "~5.5.4"
},
"engines": {
"node": ">=20"

View File

@@ -6,7 +6,7 @@
"scripts": {
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"test": "vitest run",
"test": "vitest run --config ../../vitest.config.ts",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src",
"fmt": "pnpm run format",

View File

@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true
},
"include": ["__tests__/**/*.ts"],
"exclude": ["node_modules"]
}

View File

@@ -4,7 +4,6 @@
"version": "0.1.0",
"description": "",
"scripts": {
"test": "vitest run --config ../../vitest.config.ts",
"build": "tsc --noEmit && vite build",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src",
@@ -67,14 +66,12 @@
"@storybook/blocks": "^8.4.7",
"@storybook/react": "^8.4.7",
"@storybook/react-vite": "^8.4.7",
"@storybook/testing-library": "^0.2.2",
"@types/node": "^20.17.10",
"@types/react": "^18.3.18",
"@types/react-dom": "^18.3.5",
"@unocss/eslint-plugin": "^0.60.4",
"@unocss/reset": "^0.60.4",
"@vitejs/plugin-react": "^4.3.4",
"@vitest/coverage-v8": "^2.1.8",
"chromatic": "^11.20.2",
"cross-env": "^7.0.3",
"eslint": "^8.57.1",
@@ -87,8 +84,7 @@
"typescript": "~5.5.4",
"unocss": "^0.60.4",
"vite": "^5.4.11",
"vite-plugin-dts": "^3.9.1",
"vitest": "^2.1.8"
"vite-plugin-dts": "^3.9.1"
},
"engines": {
"node": ">=20"

View File

@@ -1,9 +1,9 @@
import { expectType } from 'tsd';
import { expectTypeOf } from 'vitest';
import { isEquatable, type Equatable } from '../../src/index.js';
declare const unknownObj: unknown;
if (isEquatable(unknownObj)) {
expectType<Equatable<unknown>>(unknownObj);
expectType<boolean>(unknownObj.equals(unknownObj));
expectTypeOf(unknownObj).toEqualTypeOf<Equatable<unknown>>();
expectTypeOf(unknownObj.equals(unknownObj)).toEqualTypeOf<boolean>();
}

View File

@@ -1,9 +1,9 @@
import { expectType } from 'tsd';
import { expectTypeOf } from 'vitest';
import { isJSONEncodable, type JSONEncodable } from '../../src/index.js';
declare const unknownObj: unknown;
if (isJSONEncodable(unknownObj)) {
expectType<JSONEncodable<unknown>>(unknownObj);
expectType<unknown>(unknownObj.toJSON());
expectTypeOf(unknownObj).toEqualTypeOf<JSONEncodable<unknown>>();
expectTypeOf(unknownObj.toJSON()).toEqualTypeOf<unknown>();
}

View File

@@ -6,7 +6,7 @@
"scripts": {
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"test": "vitest run && tsd",
"test": "vitest run --config ../../vitest.config.ts",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src",
"fmt": "pnpm run format",
@@ -73,7 +73,6 @@
"eslint-config-neon": "^0.1.62",
"eslint-formatter-pretty": "^6.0.1",
"prettier": "^3.4.2",
"tsd": "^0.31.2",
"tsup": "^8.3.5",
"turbo": "^2.3.3",
"typescript": "~5.5.4",
@@ -85,8 +84,5 @@
"publishConfig": {
"access": "public",
"provenance": true
},
"tsd": {
"directory": "__tests__/types"
}
}

View File

@@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true,
"skipLibCheck": true
},
"include": ["__tests__/**/*.ts"],
"exclude": ["node_modules"]
}

View File

@@ -256,12 +256,9 @@ describe('State transitions', () => {
expect(connection.dispatchAudio).toHaveBeenCalledTimes(6);
await wait();
player['_stepPrepare']();
const prepareAudioPacket = connection.prepareAudioPacket as unknown as Mock<
[Buffer],
typeof connection.prepareAudioPacket
>;
const prepareAudioPacket = connection.prepareAudioPacket as unknown as Mock<typeof connection.prepareAudioPacket>;
expect(prepareAudioPacket).toHaveBeenCalledTimes(6);
expect(prepareAudioPacket.mock.calls[5][0]).toEqual(silence().next().value);
expect(prepareAudioPacket.mock.calls[5]![0]).toEqual(silence().next().value);
player.stop(true);
expect(player.state.status).toEqual(AudioPlayerStatus.Idle);
@@ -314,10 +311,7 @@ describe('State transitions', () => {
await wait();
expect(player.checkPlayable()).toEqual(false);
const prepareAudioPacket = connection.prepareAudioPacket as unknown as Mock<
[Buffer],
typeof connection.prepareAudioPacket
>;
const prepareAudioPacket = connection.prepareAudioPacket as unknown as Mock<typeof connection.prepareAudioPacket>;
expect(prepareAudioPacket).toHaveBeenCalledTimes(5);
expect(player.state.status).toEqual(AudioPlayerStatus.Idle);
@@ -348,10 +342,7 @@ describe('State transitions', () => {
expect(addAudioPlayer).toBeCalledTimes(1);
expect(player.checkPlayable()).toEqual(true);
const prepareAudioPacket = connection.prepareAudioPacket as unknown as Mock<
[Buffer],
typeof connection.prepareAudioPacket
>;
const prepareAudioPacket = connection.prepareAudioPacket as unknown as Mock<typeof connection.prepareAudioPacket>;
// Run through a few packet cycles
for (let index = 1; index <= 5; index++) {
@@ -363,7 +354,7 @@ describe('State transitions', () => {
expect(connection.dispatchAudio).toHaveBeenCalledTimes(index);
player['_stepPrepare']();
expect(prepareAudioPacket).toHaveBeenCalledTimes(index);
expect(prepareAudioPacket.mock.calls[index - 1][0]).toEqual(silence().next().value);
expect(prepareAudioPacket.mock.calls[index - 1]![0]).toEqual(silence().next().value);
}
expect(player.state.status).toEqual(AudioPlayerStatus.Idle);

View File

@@ -8,5 +8,12 @@ test.skip('Does not throw error with a package installed', async () => {
// The async loop in Secretbox will not have finished importing unless we wait
await secretboxLoadPromise;
expect(() => methods.crypto_aead_xchacha20poly1305_ietf_decrypt()).not.toThrowError();
expect(() =>
methods.crypto_aead_xchacha20poly1305_ietf_decrypt(
Buffer.from(''),
Buffer.from(''),
Buffer.from(''),
Buffer.from(''),
),
).not.toThrowError();
});

View File

@@ -6,7 +6,7 @@
"scripts": {
"build": "tsc --noEmit && tsup && node scripts/postbuild.mjs",
"build:docs": "tsc -p tsconfig.docs.json",
"test": "vitest run",
"test": "vitest run --config ../../vitest.config.ts",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__",
"fmt": "pnpm run format",

View File

@@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true,
"skipLibCheck": true
},
"include": ["__tests__/**/*.ts"],
"exclude": ["node_modules"]
}

View File

@@ -1,15 +1,13 @@
import type { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';
import { expectType, expectAssignable } from 'tsd';
import { expectTypeOf } from 'vitest';
import type { ManagerShardEventsMap, WebSocketShardEventsMap, WebSocketManager } from '../../src/index.js';
declare const manager: WebSocketManager;
declare const eventMap: ManagerShardEventsMap;
type AugmentedShardEventsMap = {
[K in keyof WebSocketShardEventsMap]: [
WebSocketShardEventsMap[K] extends [] ? { shardId: number } : WebSocketShardEventsMap[K][0] & { shardId: number },
];
[K in keyof WebSocketShardEventsMap]: [...WebSocketShardEventsMap[K], shardId: number];
};
expectType<AugmentedShardEventsMap>(eventMap);
expectAssignable<AsyncEventEmitter<AugmentedShardEventsMap>>(manager);
expectTypeOf(eventMap).toEqualTypeOf<AugmentedShardEventsMap>();
expectTypeOf(manager).toMatchTypeOf<AsyncEventEmitter<AugmentedShardEventsMap>>();

View File

@@ -4,7 +4,7 @@
"version": "2.0.0",
"description": "Wrapper around Discord's gateway",
"scripts": {
"test": "vitest run",
"test": "vitest run --config ../../vitest.config.ts",
"build": "tsc --noEmit && tsup",
"build:docs": "tsc -p tsconfig.docs.json",
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__",
@@ -96,7 +96,6 @@
"eslint-formatter-pretty": "^6.0.1",
"mock-socket": "^9.3.1",
"prettier": "^3.4.2",
"tsd": "^0.31.2",
"tsup": "^8.3.5",
"turbo": "^2.3.3",
"typescript": "~5.5.4",

View File

@@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true,
"skipLibCheck": true
},
"include": ["__tests__/**/*.ts"],
"exclude": ["node_modules"]
}