mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
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:
160
packages/core/__tests__/types.test-d.ts
Normal file
160
packages/core/__tests__/types.test-d.ts
Normal 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>
|
||||
>());
|
||||
});
|
||||
@@ -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 }),
|
||||
));
|
||||
});
|
||||
@@ -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",
|
||||
|
||||
@@ -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"]
|
||||
}
|
||||
|
||||
10
packages/core/tsconfig.test.json
Normal file
10
packages/core/tsconfig.test.json
Normal 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"]
|
||||
}
|
||||
Reference in New Issue
Block a user