mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 03:23:29 +01:00
feat: use vitest instead of jest for more speed
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { test, expect } from 'vitest';
|
||||
import { CDN } from '../src';
|
||||
|
||||
const base = 'https://discord.com';
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { test, expect } from 'vitest';
|
||||
import { DiscordAPIError } from '../src';
|
||||
|
||||
test('Unauthorized', () => {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { DiscordSnowflake } from '@sapphire/snowflake';
|
||||
import { Routes, Snowflake } from 'discord-api-types/v10';
|
||||
import { File, FormData, MockAgent, setGlobalDispatcher } from 'undici';
|
||||
import type { Interceptable, MockInterceptor } from 'undici/types/mock-interceptor';
|
||||
import { beforeEach, afterEach, test, expect } from 'vitest';
|
||||
import { genPath } from './util';
|
||||
import { REST } from '../src';
|
||||
|
||||
@@ -107,7 +108,7 @@ test('simple POST', async () => {
|
||||
expect(await api.post('/simplePost')).toStrictEqual({ test: true });
|
||||
});
|
||||
|
||||
test('simple PUT', async () => {
|
||||
test('simple PUT 2', async () => {
|
||||
mockPool
|
||||
.intercept({
|
||||
path: genPath('/simplePut'),
|
||||
@@ -285,7 +286,7 @@ test('Old Message Delete Edge-Case: Old message', async () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('Old Message Delete Edge-Case: Old message', async () => {
|
||||
test('Old Message Delete Edge-Case: Old message 2', async () => {
|
||||
mockPool
|
||||
.intercept({
|
||||
path: genPath(`/channels/339942739275677727/messages/${newSnowflake}`),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { performance } from 'node:perf_hooks';
|
||||
import { MockAgent, setGlobalDispatcher } from 'undici';
|
||||
import type { Interceptable, MockInterceptor } from 'undici/types/mock-interceptor';
|
||||
import { beforeEach, afterEach, test, expect, vitest } from 'vitest';
|
||||
import { genPath } from './util';
|
||||
import { DiscordAPIError, HTTPError, RateLimitError, REST, RESTEvents } from '../src';
|
||||
|
||||
@@ -82,8 +83,8 @@ test('Significant Invalid Requests', async () => {
|
||||
.reply(403, { message: 'Missing Permissions', code: 50013 }, responseOptions)
|
||||
.times(10);
|
||||
|
||||
const invalidListener = jest.fn();
|
||||
const invalidListener2 = jest.fn();
|
||||
const invalidListener = vitest.fn();
|
||||
const invalidListener2 = vitest.fn();
|
||||
api.on(RESTEvents.InvalidRequestWarning, invalidListener);
|
||||
// Ensure listeners on REST do not get double added
|
||||
api.on(RESTEvents.InvalidRequestWarning, invalidListener2);
|
||||
@@ -364,6 +365,7 @@ test('Handle unexpected 429', async () => {
|
||||
expect(await unexepectedSublimit).toStrictEqual({ test: true });
|
||||
expect(await queuedSublimit).toStrictEqual({ test: true });
|
||||
expect(performance.now()).toBeGreaterThanOrEqual(previous + 1000);
|
||||
// @ts-expect-error
|
||||
expect(secondResolvedTime).toBeGreaterThan(firstResolvedTime);
|
||||
});
|
||||
|
||||
@@ -495,7 +497,7 @@ test('Unauthorized', async () => {
|
||||
.reply(401, { message: '401: Unauthorized', code: 0 }, responseOptions)
|
||||
.times(2);
|
||||
|
||||
const setTokenSpy = jest.spyOn(invalidAuthApi.requestManager, 'setToken');
|
||||
const setTokenSpy = vitest.spyOn(invalidAuthApi.requestManager, 'setToken');
|
||||
|
||||
// Ensure authless requests don't reset the token
|
||||
const promiseWithoutTokenClear = invalidAuthApi.get('/unauthorized', { auth: false });
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { MockAgent, setGlobalDispatcher } from 'undici';
|
||||
import { Interceptable } from 'undici/types/mock-interceptor';
|
||||
import type { Interceptable } from 'undici/types/mock-interceptor';
|
||||
import { beforeEach, afterEach, test, expect } from 'vitest';
|
||||
import { genPath } from './util';
|
||||
import { REST } from '../src';
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Blob } from 'node:buffer';
|
||||
import { test, expect } from 'vitest';
|
||||
import { resolveBody, parseHeader } from '../src/lib/utils/utils';
|
||||
|
||||
test('GIVEN string parseHeader returns string', () => {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { makeURLSearchParams } from '../src';
|
||||
|
||||
describe('makeURLSearchParams', () => {
|
||||
|
||||
Reference in New Issue
Block a user