Skip to content

Commit 8d8e6c0

Browse files
committed
feat: use vitest instead of jest for more speed
1 parent dfadcbc commit 8d8e6c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+616
-855
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dist/
2626
.DS_Store
2727
.turbo
2828
tsconfig.tsbuildinfo
29+
coverage/
2930

3031
# yarn
3132
.pnp.*

Diff for: package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"private": true,
66
"scripts": {
77
"build": "turbo run build",
8-
"test": "turbo run test",
8+
"test": "turbo run test && vitest run",
99
"lint": "turbo run lint",
1010
"format": "turbo run format",
1111
"fmt": "turbo run format",
@@ -41,10 +41,13 @@
4141
"@commitlint/cli": "^17.0.2",
4242
"@commitlint/config-angular": "^17.0.0",
4343
"@favware/npm-deprecate": "^1.0.4",
44+
"c8": "^7.11.3",
4445
"conventional-changelog-cli": "^2.2.2",
4546
"husky": "^8.0.1",
47+
"is-ci": "^3.0.1",
4648
"prettier": "^2.6.2",
47-
"turbo": "^1.2.16"
49+
"turbo": "^1.2.16",
50+
"vitest": "^0.13.1"
4851
},
4952
"engines": {
5053
"node": ">=16.9.0"

Diff for: packages/actions/__tests__/formatTag.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, test, expect } from 'vitest';
12
import { formatTag } from '../src';
23

34
describe('Format Tag', () => {

Diff for: packages/actions/babel.config.js

-18
This file was deleted.

Diff for: packages/actions/jest.config.js

-19
This file was deleted.

Diff for: packages/actions/package.json

-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"private": true,
66
"scripts": {
77
"build": "tsup",
8-
"test": "jest --pass-with-no-tests",
98
"lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts",
109
"format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix"
1110
},
@@ -48,20 +47,13 @@
4847
"tslib": "^2.4.0"
4948
},
5049
"devDependencies": {
51-
"@babel/core": "^7.18.2",
52-
"@babel/plugin-proposal-decorators": "^7.18.2",
53-
"@babel/preset-env": "^7.18.2",
54-
"@babel/preset-typescript": "^7.17.12",
55-
"@types/jest": "^28.1.0",
5650
"@types/node": "^16.11.38",
5751
"@typescript-eslint/eslint-plugin": "^5.27.0",
5852
"@typescript-eslint/parser": "^5.27.0",
59-
"babel-plugin-transform-typescript-metadata": "^0.3.2",
6053
"eslint": "^8.17.0",
6154
"eslint-config-marine": "^9.4.1",
6255
"eslint-config-prettier": "^8.5.0",
6356
"eslint-plugin-import": "^2.26.0",
64-
"jest": "^28.1.0",
6557
"prettier": "^2.6.2",
6658
"tsup": "^6.0.1",
6759
"typescript": "^4.7.3"

Diff for: packages/builders/__tests__/components/actionRow.test.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { APIActionRowComponent, APIMessageActionRowComponent, ButtonStyle, ComponentType } from 'discord-api-types/v10';
2+
import { describe, test, expect } from 'vitest';
23
import {
34
ActionRowBuilder,
45
ButtonBuilder,
@@ -82,6 +83,7 @@ describe('Action Row Components', () => {
8283
expect(new ActionRowBuilder().toJSON()).toEqual({ type: ComponentType.ActionRow, components: [] });
8384
expect(() => createComponentBuilder({ type: ComponentType.ActionRow, components: [] })).not.toThrowError();
8485
});
86+
8587
test('GIVEN valid builder options THEN valid JSON output is given', () => {
8688
const rowWithButtonData: APIActionRowComponent<APIMessageActionRowComponent> = {
8789
type: ComponentType.ActionRow,
@@ -122,7 +124,8 @@ describe('Action Row Components', () => {
122124
expect(new ActionRowBuilder().toJSON()).toEqual({ type: ComponentType.ActionRow, components: [] });
123125
expect(() => createComponentBuilder({ type: ComponentType.ActionRow, components: [] })).not.toThrowError();
124126
});
125-
test('GIVEN valid builder options THEN valid JSON output is given', () => {
127+
128+
test('GIVEN valid builder options THEN valid JSON output is given 2', () => {
126129
const button = new ButtonBuilder().setLabel('test').setStyle(ButtonStyle.Primary).setCustomId('123');
127130
const selectMenu = new SelectMenuBuilder()
128131
.setCustomId('1234')

Diff for: packages/builders/__tests__/components/button.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ButtonStyle,
55
ComponentType,
66
} from 'discord-api-types/v10';
7+
import { describe, test, expect } from 'vitest';
78
import { buttonLabelValidator, buttonStyleValidator } from '../../src/components/Assertions';
89
import { ButtonBuilder } from '../../src/components/button/Button';
910

@@ -124,7 +125,7 @@ describe('Button Components', () => {
124125
expect(
125126
buttonComponent()
126127
.setCustomId(interactionData.custom_id)
127-
.setLabel(interactionData.label)
128+
.setLabel(interactionData.label!)
128129
.setStyle(interactionData.style)
129130
.setDisabled(interactionData.disabled)
130131
.toJSON(),
@@ -140,7 +141,7 @@ describe('Button Components', () => {
140141

141142
expect(new ButtonBuilder(linkData).toJSON()).toEqual(linkData);
142143

143-
expect(buttonComponent().setLabel(linkData.label).setDisabled(true).setURL(linkData.url));
144+
expect(buttonComponent().setLabel(linkData.label!).setDisabled(true).setURL(linkData.url));
144145
});
145146
});
146147
});

Diff for: packages/builders/__tests__/components/selectMenu.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { APISelectMenuComponent, APISelectMenuOption, ComponentType } from 'discord-api-types/v10';
2+
import { describe, test, expect } from 'vitest';
23
import { SelectMenuBuilder, SelectMenuOptionBuilder } from '../../src/index';
34

45
const selectMenu = () => new SelectMenuBuilder();

Diff for: packages/builders/__tests__/components/textInput.test.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { APITextInputComponent, ComponentType, TextInputStyle } from 'discord-api-types/v10';
2+
import { describe, test, expect } from 'vitest';
23
import {
34
labelValidator,
45
maxLengthValidator,
@@ -45,7 +46,7 @@ describe('Text Input Components', () => {
4546
expect(() => maxLengthValidator.parse(10)).not.toThrowError();
4647
});
4748

48-
test('GIVEN invalid min length THEN validator does throw', () => {
49+
test('GIVEN invalid min length THEN validator does throw 2', () => {
4950
expect(() => maxLengthValidator.parse(4001)).toThrowError();
5051
});
5152

@@ -61,7 +62,7 @@ describe('Text Input Components', () => {
6162
expect(() => placeholderValidator.parse('foobar')).not.toThrowError();
6263
});
6364

64-
test('GIVEN invalid value THEN validator does throw', () => {
65+
test('GIVEN invalid value THEN validator does throw 2', () => {
6566
expect(() => placeholderValidator.parse(superLongStr)).toThrowError();
6667
});
6768

@@ -114,10 +115,10 @@ describe('Text Input Components', () => {
114115
textInputComponent()
115116
.setCustomId(textInputData.custom_id)
116117
.setLabel(textInputData.label)
117-
.setPlaceholder(textInputData.placeholder)
118-
.setMaxLength(textInputData.max_length)
119-
.setMinLength(textInputData.min_length)
120-
.setValue(textInputData.value)
118+
.setPlaceholder(textInputData.placeholder!)
119+
.setMaxLength(textInputData.max_length!)
120+
.setMinLength(textInputData.min_length!)
121+
.setValue(textInputData.value!)
121122
.setRequired(textInputData.required)
122123
.setStyle(textInputData.style)
123124
.toJSON(),

Diff for: packages/builders/__tests__/interactions/ContextMenuCommands.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { PermissionFlagsBits } from 'discord-api-types/v10';
2+
import { describe, test, expect } from 'vitest';
23
import { ContextMenuCommandAssertions, ContextMenuCommandBuilder } from '../../src/index';
34

45
const getBuilder = () => new ContextMenuCommandBuilder();

Diff for: packages/builders/__tests__/interactions/SlashCommands/Options.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
ApplicationCommandOptionType,
1111
ChannelType,
1212
} from 'discord-api-types/v10';
13+
import { describe, test, expect } from 'vitest';
1314
import {
1415
SlashCommandBooleanOption,
1516
SlashCommandChannelOption,

Diff for: packages/builders/__tests__/interactions/SlashCommands/SlashCommands.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { APIApplicationCommandOptionChoice, ChannelType, PermissionFlagsBits } from 'discord-api-types/v10';
2+
import { describe, test, expect } from 'vitest';
23
import {
34
SlashCommandAssertions,
45
SlashCommandBooleanOption,
@@ -313,8 +314,10 @@ describe('Slash Commands', () => {
313314
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
314315
expect(() => getBuilder().addBooleanOption(true)).toThrowError();
315316

317+
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
316318
expect(() => getBuilder().addBooleanOption(null)).toThrowError();
317319

320+
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
318321
expect(() => getBuilder().addBooleanOption(undefined)).toThrowError();
319322

320323
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error

Diff for: packages/builders/__tests__/interactions/modal.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { APIModalInteractionResponseCallbackData, ComponentType, TextInputStyle } from 'discord-api-types/v10';
2+
import { describe, test, expect } from 'vitest';
23
import {
34
ActionRowBuilder,
45
ButtonBuilder,

Diff for: packages/builders/__tests__/messages/embed.test.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, test, expect } from 'vitest';
12
import { EmbedBuilder, embedLength } from '../../src';
23

34
const alpha = 'abcdefghijklmnopqrstuvwxyz';
@@ -341,7 +342,7 @@ describe('Embed', () => {
341342
});
342343
});
343344

344-
test('GIVEN an embed using Embed#spliceFields THEN returns valid toJSON data', () => {
345+
test('GIVEN an embed using Embed#spliceFields THEN returns valid toJSON data 2', () => {
345346
const embed = new EmbedBuilder();
346347
embed.addFields(Array.from({ length: 23 }, () => ({ name: 'foo', value: 'bar' })));
347348

@@ -374,31 +375,31 @@ describe('Embed', () => {
374375
});
375376

376377
describe('GIVEN invalid field amount THEN throws error', () => {
377-
test('', () => {
378+
test('1', () => {
378379
const embed = new EmbedBuilder();
379380

380381
expect(() => embed.addFields(Array.from({ length: 26 }, () => ({ name: 'foo', value: 'bar' })))).toThrowError();
381382
});
382383
});
383384

384385
describe('GIVEN invalid field name THEN throws error', () => {
385-
test('', () => {
386+
test('2', () => {
386387
const embed = new EmbedBuilder();
387388

388389
expect(() => embed.addFields([{ name: '', value: 'bar' }])).toThrowError();
389390
});
390391
});
391392

392393
describe('GIVEN invalid field name length THEN throws error', () => {
393-
test('', () => {
394+
test('3', () => {
394395
const embed = new EmbedBuilder();
395396

396397
expect(() => embed.addFields([{ name: 'a'.repeat(257), value: 'bar' }])).toThrowError();
397398
});
398399
});
399400

400401
describe('GIVEN invalid field value length THEN throws error', () => {
401-
test('', () => {
402+
test('4', () => {
402403
const embed = new EmbedBuilder();
403404

404405
expect(() => embed.addFields([{ name: '', value: 'a'.repeat(1025) }])).toThrowError();

Diff for: packages/builders/__tests__/messages/formatters.test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, test, expect, vitest } from 'vitest';
12
import {
23
blockQuote,
34
bold,
@@ -150,12 +151,12 @@ describe('Message formatters', () => {
150151

151152
describe('time', () => {
152153
test('GIVEN no arguments THEN returns "<t:${bigint}>"', () => {
153-
jest.useFakeTimers('modern');
154-
jest.setSystemTime(1566424897579);
154+
vitest.useFakeTimers();
155+
vitest.setSystemTime(1566424897579);
155156

156157
expect<`<t:${bigint}>`>(time()).toEqual('<t:1566424897>');
157158

158-
jest.useRealTimers();
159+
vitest.useRealTimers();
159160
});
160161

161162
test('GIVEN a date THEN returns "<t:${bigint}>"', () => {

Diff for: packages/builders/babel.config.js

-18
This file was deleted.

Diff for: packages/builders/jest.config.js

-19
This file was deleted.

Diff for: packages/builders/package.json

-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"description": "A set of builders that you can use when creating your bot",
55
"scripts": {
66
"build": "tsup",
7-
"test": "jest --pass-with-no-tests",
87
"lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts",
98
"format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix",
109
"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",
@@ -60,21 +59,14 @@
6059
"tslib": "^2.4.0"
6160
},
6261
"devDependencies": {
63-
"@babel/core": "^7.18.2",
64-
"@babel/plugin-proposal-decorators": "^7.18.2",
65-
"@babel/preset-env": "^7.18.2",
66-
"@babel/preset-typescript": "^7.17.12",
6762
"@discordjs/scripts": "workspace:^",
68-
"@types/jest": "^28.1.0",
6963
"@types/node": "^16.11.38",
7064
"@typescript-eslint/eslint-plugin": "^5.27.0",
7165
"@typescript-eslint/parser": "^5.27.0",
72-
"babel-plugin-transform-typescript-metadata": "^0.3.2",
7366
"eslint": "^8.17.0",
7467
"eslint-config-marine": "^9.4.1",
7568
"eslint-config-prettier": "^8.5.0",
7669
"eslint-plugin-import": "^2.26.0",
77-
"jest": "^28.1.0",
7870
"prettier": "^2.6.2",
7971
"tsup": "^6.0.1",
8072
"typedoc": "^0.22.17",

Diff for: packages/collection/__tests__/collection.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, test, expect } from 'vitest';
12
import Collection from '../src';
23

34
type TestCollection = Collection<string, number>;
@@ -247,7 +248,7 @@ test('random select from a collection', () => {
247248
const chars = 'abcdefghijklmnopqrstuvwxyz';
248249
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26];
249250

250-
for (let i = 0; i < chars.length; i++) coll.set(chars[i], numbers[i]);
251+
for (let i = 0; i < chars.length; i++) coll.set(chars[i]!, numbers[i]!);
251252

252253
const random = coll.random(5);
253254
expect(random.length === 5).toBeTruthy();
@@ -357,7 +358,7 @@ describe('hasAny() tests', () => {
357358
});
358359
});
359360

360-
describe('reverse() tests', () => {
361+
test('reverse() tests', () => {
361362
const coll = new Collection();
362363
coll.set('a', 1);
363364
coll.set('b', 2);

0 commit comments

Comments
 (0)