mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 02:53:31 +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', () => {
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
/**
|
||||
* @type {import('@babel/core').TransformOptions}
|
||||
*/
|
||||
module.exports = {
|
||||
parserOpts: { strictMode: true },
|
||||
sourceMaps: 'inline',
|
||||
presets: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
targets: { node: 'current' },
|
||||
modules: 'commonjs',
|
||||
},
|
||||
],
|
||||
'@babel/preset-typescript',
|
||||
],
|
||||
plugins: [
|
||||
['const-enum', { transform: 'constObject' }],
|
||||
'babel-plugin-transform-typescript-metadata',
|
||||
['@babel/plugin-proposal-decorators', { legacy: true }],
|
||||
],
|
||||
};
|
||||
@@ -1,19 +0,0 @@
|
||||
/**
|
||||
* @type {import('@jest/types').Config.InitialOptions}
|
||||
*/
|
||||
module.exports = {
|
||||
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
|
||||
testEnvironment: 'node',
|
||||
collectCoverage: true,
|
||||
coverageProvider: 'v8',
|
||||
coverageDirectory: 'coverage',
|
||||
coverageReporters: ['html', 'text', 'clover'],
|
||||
coverageThreshold: {
|
||||
global: {
|
||||
branches: 70,
|
||||
lines: 70,
|
||||
statements: 70,
|
||||
},
|
||||
},
|
||||
coveragePathIgnorePatterns: ['/node_modules/', '/__tests__/'],
|
||||
};
|
||||
@@ -4,7 +4,6 @@
|
||||
"description": "The REST API for discord.js",
|
||||
"scripts": {
|
||||
"build": "tsup && tsc --emitDeclarationOnly --incremental",
|
||||
"test": "jest --pass-with-no-tests --collect-coverage",
|
||||
"lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts",
|
||||
"format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix",
|
||||
"docs": "typedoc --json docs/typedoc-out.json src/index.ts && ts-docgen -i docs/typedoc-out.json -c docs/index.yml -o docs/docs.json",
|
||||
@@ -58,21 +57,13 @@
|
||||
"undici": "^5.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.18.2",
|
||||
"@babel/plugin-proposal-decorators": "^7.18.2",
|
||||
"@babel/preset-env": "^7.18.2",
|
||||
"@babel/preset-typescript": "^7.17.12",
|
||||
"@discordjs/scripts": "workspace:^",
|
||||
"@types/jest": "^28.1.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.27.0",
|
||||
"@typescript-eslint/parser": "^5.27.0",
|
||||
"babel-plugin-const-enum": "^1.2.0",
|
||||
"babel-plugin-transform-typescript-metadata": "^0.3.2",
|
||||
"eslint": "^8.17.0",
|
||||
"eslint-config-marine": "^9.4.1",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"jest": "^28.1.0",
|
||||
"prettier": "^2.6.2",
|
||||
"tsup": "^6.0.1",
|
||||
"typedoc": "^0.22.17",
|
||||
|
||||
Reference in New Issue
Block a user