Skip to content

Commit

Permalink
feat: use vitest instead of jest for more speed
Browse files Browse the repository at this point in the history
  • Loading branch information
iCrawl committed Jun 4, 2022
1 parent dfadcbc commit 8d8e6c0
Show file tree
Hide file tree
Showing 42 changed files with 616 additions and 855 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dist/
.DS_Store
.turbo
tsconfig.tsbuildinfo
coverage/

# yarn
.pnp.*
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"private": true,
"scripts": {
"build": "turbo run build",
"test": "turbo run test",
"test": "turbo run test && vitest run",
"lint": "turbo run lint",
"format": "turbo run format",
"fmt": "turbo run format",
Expand Down Expand Up @@ -41,10 +41,13 @@
"@commitlint/cli": "^17.0.2",
"@commitlint/config-angular": "^17.0.0",
"@favware/npm-deprecate": "^1.0.4",
"c8": "^7.11.3",
"conventional-changelog-cli": "^2.2.2",
"husky": "^8.0.1",
"is-ci": "^3.0.1",
"prettier": "^2.6.2",
"turbo": "^1.2.16"
"turbo": "^1.2.16",
"vitest": "^0.13.1"
},
"engines": {
"node": ">=16.9.0"
Expand Down
1 change: 1 addition & 0 deletions packages/actions/__tests__/formatTag.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, test, expect } from 'vitest';
import { formatTag } from '../src';

describe('Format Tag', () => {
Expand Down
18 changes: 0 additions & 18 deletions packages/actions/babel.config.js

This file was deleted.

19 changes: 0 additions & 19 deletions packages/actions/jest.config.js

This file was deleted.

8 changes: 0 additions & 8 deletions packages/actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"private": true,
"scripts": {
"build": "tsup",
"test": "jest --pass-with-no-tests",
"lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts",
"format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix"
},
Expand Down Expand Up @@ -48,20 +47,13 @@
"tslib": "^2.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",
"@types/jest": "^28.1.0",
"@types/node": "^16.11.38",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.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",
"typescript": "^4.7.3"
Expand Down
5 changes: 4 additions & 1 deletion packages/builders/__tests__/components/actionRow.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { APIActionRowComponent, APIMessageActionRowComponent, ButtonStyle, ComponentType } from 'discord-api-types/v10';
import { describe, test, expect } from 'vitest';
import {
ActionRowBuilder,
ButtonBuilder,
Expand Down Expand Up @@ -82,6 +83,7 @@ describe('Action Row Components', () => {
expect(new ActionRowBuilder().toJSON()).toEqual({ type: ComponentType.ActionRow, components: [] });
expect(() => createComponentBuilder({ type: ComponentType.ActionRow, components: [] })).not.toThrowError();
});

test('GIVEN valid builder options THEN valid JSON output is given', () => {
const rowWithButtonData: APIActionRowComponent<APIMessageActionRowComponent> = {
type: ComponentType.ActionRow,
Expand Down Expand Up @@ -122,7 +124,8 @@ describe('Action Row Components', () => {
expect(new ActionRowBuilder().toJSON()).toEqual({ type: ComponentType.ActionRow, components: [] });
expect(() => createComponentBuilder({ type: ComponentType.ActionRow, components: [] })).not.toThrowError();
});
test('GIVEN valid builder options THEN valid JSON output is given', () => {

test('GIVEN valid builder options THEN valid JSON output is given 2', () => {
const button = new ButtonBuilder().setLabel('test').setStyle(ButtonStyle.Primary).setCustomId('123');
const selectMenu = new SelectMenuBuilder()
.setCustomId('1234')
Expand Down
5 changes: 3 additions & 2 deletions packages/builders/__tests__/components/button.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ButtonStyle,
ComponentType,
} from 'discord-api-types/v10';
import { describe, test, expect } from 'vitest';
import { buttonLabelValidator, buttonStyleValidator } from '../../src/components/Assertions';
import { ButtonBuilder } from '../../src/components/button/Button';

Expand Down Expand Up @@ -124,7 +125,7 @@ describe('Button Components', () => {
expect(
buttonComponent()
.setCustomId(interactionData.custom_id)
.setLabel(interactionData.label)
.setLabel(interactionData.label!)
.setStyle(interactionData.style)
.setDisabled(interactionData.disabled)
.toJSON(),
Expand All @@ -140,7 +141,7 @@ describe('Button Components', () => {

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

expect(buttonComponent().setLabel(linkData.label).setDisabled(true).setURL(linkData.url));
expect(buttonComponent().setLabel(linkData.label!).setDisabled(true).setURL(linkData.url));
});
});
});
1 change: 1 addition & 0 deletions packages/builders/__tests__/components/selectMenu.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { APISelectMenuComponent, APISelectMenuOption, ComponentType } from 'discord-api-types/v10';
import { describe, test, expect } from 'vitest';
import { SelectMenuBuilder, SelectMenuOptionBuilder } from '../../src/index';

const selectMenu = () => new SelectMenuBuilder();
Expand Down
13 changes: 7 additions & 6 deletions packages/builders/__tests__/components/textInput.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { APITextInputComponent, ComponentType, TextInputStyle } from 'discord-api-types/v10';
import { describe, test, expect } from 'vitest';
import {
labelValidator,
maxLengthValidator,
Expand Down Expand Up @@ -45,7 +46,7 @@ describe('Text Input Components', () => {
expect(() => maxLengthValidator.parse(10)).not.toThrowError();
});

test('GIVEN invalid min length THEN validator does throw', () => {
test('GIVEN invalid min length THEN validator does throw 2', () => {
expect(() => maxLengthValidator.parse(4001)).toThrowError();
});

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

test('GIVEN invalid value THEN validator does throw', () => {
test('GIVEN invalid value THEN validator does throw 2', () => {
expect(() => placeholderValidator.parse(superLongStr)).toThrowError();
});

Expand Down Expand Up @@ -114,10 +115,10 @@ describe('Text Input Components', () => {
textInputComponent()
.setCustomId(textInputData.custom_id)
.setLabel(textInputData.label)
.setPlaceholder(textInputData.placeholder)
.setMaxLength(textInputData.max_length)
.setMinLength(textInputData.min_length)
.setValue(textInputData.value)
.setPlaceholder(textInputData.placeholder!)
.setMaxLength(textInputData.max_length!)
.setMinLength(textInputData.min_length!)
.setValue(textInputData.value!)
.setRequired(textInputData.required)
.setStyle(textInputData.style)
.toJSON(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PermissionFlagsBits } from 'discord-api-types/v10';
import { describe, test, expect } from 'vitest';
import { ContextMenuCommandAssertions, ContextMenuCommandBuilder } from '../../src/index';

const getBuilder = () => new ContextMenuCommandBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ApplicationCommandOptionType,
ChannelType,
} from 'discord-api-types/v10';
import { describe, test, expect } from 'vitest';
import {
SlashCommandBooleanOption,
SlashCommandChannelOption,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { APIApplicationCommandOptionChoice, ChannelType, PermissionFlagsBits } from 'discord-api-types/v10';
import { describe, test, expect } from 'vitest';
import {
SlashCommandAssertions,
SlashCommandBooleanOption,
Expand Down Expand Up @@ -313,8 +314,10 @@ describe('Slash Commands', () => {
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
expect(() => getBuilder().addBooleanOption(true)).toThrowError();

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

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

// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
Expand Down
1 change: 1 addition & 0 deletions packages/builders/__tests__/interactions/modal.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { APIModalInteractionResponseCallbackData, ComponentType, TextInputStyle } from 'discord-api-types/v10';
import { describe, test, expect } from 'vitest';
import {
ActionRowBuilder,
ButtonBuilder,
Expand Down
11 changes: 6 additions & 5 deletions packages/builders/__tests__/messages/embed.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, test, expect } from 'vitest';
import { EmbedBuilder, embedLength } from '../../src';

const alpha = 'abcdefghijklmnopqrstuvwxyz';
Expand Down Expand Up @@ -341,7 +342,7 @@ describe('Embed', () => {
});
});

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

Expand Down Expand Up @@ -374,31 +375,31 @@ describe('Embed', () => {
});

describe('GIVEN invalid field amount THEN throws error', () => {
test('', () => {
test('1', () => {
const embed = new EmbedBuilder();

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

describe('GIVEN invalid field name THEN throws error', () => {
test('', () => {
test('2', () => {
const embed = new EmbedBuilder();

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

describe('GIVEN invalid field name length THEN throws error', () => {
test('', () => {
test('3', () => {
const embed = new EmbedBuilder();

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

describe('GIVEN invalid field value length THEN throws error', () => {
test('', () => {
test('4', () => {
const embed = new EmbedBuilder();

expect(() => embed.addFields([{ name: '', value: 'a'.repeat(1025) }])).toThrowError();
Expand Down
7 changes: 4 additions & 3 deletions packages/builders/__tests__/messages/formatters.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, test, expect, vitest } from 'vitest';
import {
blockQuote,
bold,
Expand Down Expand Up @@ -150,12 +151,12 @@ describe('Message formatters', () => {

describe('time', () => {
test('GIVEN no arguments THEN returns "<t:${bigint}>"', () => {
jest.useFakeTimers('modern');
jest.setSystemTime(1566424897579);
vitest.useFakeTimers();
vitest.setSystemTime(1566424897579);

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

jest.useRealTimers();
vitest.useRealTimers();
});

test('GIVEN a date THEN returns "<t:${bigint}>"', () => {
Expand Down
18 changes: 0 additions & 18 deletions packages/builders/babel.config.js

This file was deleted.

19 changes: 0 additions & 19 deletions packages/builders/jest.config.js

This file was deleted.

8 changes: 0 additions & 8 deletions packages/builders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"description": "A set of builders that you can use when creating your bot",
"scripts": {
"build": "tsup",
"test": "jest --pass-with-no-tests",
"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",
Expand Down Expand Up @@ -60,21 +59,14 @@
"tslib": "^2.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",
"@types/node": "^16.11.38",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.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",
Expand Down
5 changes: 3 additions & 2 deletions packages/collection/__tests__/collection.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, test, expect } from 'vitest';
import Collection from '../src';

type TestCollection = Collection<string, number>;
Expand Down Expand Up @@ -247,7 +248,7 @@ test('random select from a collection', () => {
const chars = 'abcdefghijklmnopqrstuvwxyz';
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];

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

const random = coll.random(5);
expect(random.length === 5).toBeTruthy();
Expand Down Expand Up @@ -357,7 +358,7 @@ describe('hasAny() tests', () => {
});
});

describe('reverse() tests', () => {
test('reverse() tests', () => {
const coll = new Collection();
coll.set('a', 1);
coll.set('b', 2);
Expand Down
Loading

0 comments on commit 8d8e6c0

Please sign in to comment.