Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Properly add typecheck tests #10722

Merged
merged 9 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions apps/guide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"description": "Imagine a guide... that explores the many possibilities for your discord.js bot",
"private": true,
"scripts": {
"test": "vitest run",
"build:check": "tsc --noEmit",
"build:local": "pnpm run build:prod",
"build:prod": "next build",
Expand Down Expand Up @@ -66,8 +65,6 @@
"sharp": "^0.33.5"
},
"devDependencies": {
"@testing-library/react": "^15.0.7",
"@testing-library/user-event": "^14.5.2",
"@types/html-escaper": "^3.0.2",
"@types/node": "^18.19.68",
"@types/react": "^18.3.18",
Expand All @@ -76,7 +73,6 @@
"@unocss/postcss": "^0.60.4",
"@unocss/reset": "^0.60.4",
"@vitejs/plugin-react": "^4.3.4",
"@vitest/coverage-v8": "^2.1.8",
"cross-env": "^7.0.3",
"eslint": "^8.57.1",
"eslint-config-neon": "^0.1.62",
Expand All @@ -90,8 +86,7 @@
"turbo": "^2.3.3",
"typescript": "~5.5.4",
"unocss": "^0.60.4",
"vercel": "^37.14.0",
"vitest": "^2.1.8"
"vercel": "^37.14.0"
},
"engines": {
"node": ">=18"
Expand Down
7 changes: 1 addition & 6 deletions apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"description": "Imagine a bot... the most popular way to build discord bots",
"private": true,
"scripts": {
"test": "vitest run",
"build:copy_readme": "cpy \"../../packages/(discord.js|brokers|builders|collection|core|formatters|next|proxy|rest|util|voice|ws)/README.md\" \"src/assets/readme\" --rename='home-{{basename}}'",
"build:check": "tsc --noEmit",
"build:local": "cross-env NEXT_PUBLIC_LOCAL_DEV=true pnpm run build:prod",
Expand Down Expand Up @@ -73,13 +72,10 @@
"devDependencies": {
"@shikijs/rehype": "^1.24.4",
"@tailwindcss/typography": "^0.5.15",
"@testing-library/react": "^15.0.7",
"@testing-library/user-event": "^14.5.2",
"@types/node": "^20.17.10",
"@types/react": "^18.3.18",
"@types/react-dom": "^18.3.5",
"@vitejs/plugin-react": "^4.3.4",
"@vitest/coverage-v8": "^2.1.8",
"autoprefixer": "^10.4.20",
"babel-plugin-react-compiler": "0.0.0-experimental-592953e-20240517",
"cpy-cli": "^5.0.0",
Expand All @@ -97,8 +93,7 @@
"tailwindcss": "^3.4.17",
"turbo": "^2.3.3",
"typescript": "~5.5.4",
"vercel": "^37.14.0",
"vitest": "^2.1.8"
"vercel": "^37.14.0"
},
"engines": {
"node": ">=20"
Expand Down
2 changes: 1 addition & 1 deletion packages/actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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__",
Expand Down
10 changes: 10 additions & 0 deletions packages/actions/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -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"]
}
2 changes: 1 addition & 1 deletion packages/brokers/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
2 changes: 1 addition & 1 deletion packages/brokers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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__",
Expand Down
10 changes: 10 additions & 0 deletions packages/brokers/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -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"]
}
2 changes: 1 addition & 1 deletion packages/builders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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__",
Expand Down
2 changes: 1 addition & 1 deletion packages/builders/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
10 changes: 10 additions & 0 deletions packages/builders/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -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"]
}
2 changes: 1 addition & 1 deletion packages/collection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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__",
Expand Down
10 changes: 10 additions & 0 deletions packages/collection/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -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"]
}
160 changes: 160 additions & 0 deletions packages/core/__tests__/types.test-d.ts
Original file line number Diff line number Diff line change
@@ -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>
>());
});
Loading
Loading