add vitest in project

This commit is contained in:
MapleLeaf
2022-01-09 22:15:47 -06:00
parent 661a253d8c
commit 017a417773
16 changed files with 165 additions and 1409 deletions

View File

@@ -2,6 +2,7 @@ import type {
CamelCasedPropertiesDeep,
SnakeCasedPropertiesDeep,
} from "type-fest"
import { expect, test } from "vitest"
import { camelCaseDeep, snakeCaseDeep } from "./convert-object-property-case"
test("camelCaseDeep", () => {
@@ -12,12 +13,14 @@ test("camelCaseDeep", () => {
someOtherProp: "someOtherValue",
}
expect(camelCaseDeep(input)).toEqual<CamelCasedPropertiesDeep<typeof input>>({
const expected: CamelCasedPropertiesDeep<typeof input> = {
someProp: {
someDeepProp: "some_deep_value",
},
someOtherProp: "someOtherValue",
})
}
expect(camelCaseDeep(input)).toEqual(expected)
})
test("snakeCaseDeep", () => {
@@ -28,10 +31,12 @@ test("snakeCaseDeep", () => {
some_other_prop: "someOtherValue",
}
expect(snakeCaseDeep(input)).toEqual<SnakeCasedPropertiesDeep<typeof input>>({
const expected: SnakeCasedPropertiesDeep<typeof input> = {
some_prop: {
some_deep_prop: "someDeepValue",
},
some_other_prop: "someOtherValue",
})
}
expect(snakeCaseDeep(input)).toEqual(expected)
})

View File

@@ -1,15 +0,0 @@
/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
transform: {
"^.+\\.[jt]sx?$": ["esbuild-jest", { format: "esm", sourcemap: true }],
},
extensionsToTreatAsEsm: [".ts", ".tsx"],
moduleNameMapper: {
"^(\\.\\.?/.+)\\.jsx?$": "$1",
},
verbose: true,
cache: false,
coverageReporters: ["text", "text-summary", "html"],
coveragePathIgnorePatterns: ["discord-js-adapter", "test/setup-testing"],
}
export default config

View File

@@ -4,6 +4,7 @@ import { nanoid } from "nanoid"
import { nextTick } from "node:process"
import { promisify } from "node:util"
import type { ReactNode } from "react"
import { expect } from "vitest"
import { logPretty } from "../../helpers/log-pretty"
import { omit } from "../../helpers/omit"
import { raise } from "../../helpers/raise"

View File

@@ -20,9 +20,8 @@
"scripts": {
"build": "tsup-node library/main.ts --target node16 --format cjs,esm --dts --sourcemap",
"build-watch": "pnpm build -- --watch",
"test": "node --experimental-vm-modules --no-warnings ./node_modules/jest/bin/jest.js --colors",
"test-watch": "pnpm test -- --watch",
"coverage": "pnpm test -- --coverage",
"test": "vitest",
"coverage": "vitest --coverage",
"typecheck": "tsc --noEmit",
"playground": "nodemon --exec esmo --ext ts,tsx ./playground/main.tsx",
"release": "release-it"
@@ -45,8 +44,6 @@
}
},
"devDependencies": {
"@jest/globals": "^27.4.6",
"@types/jest": "^27.4.0",
"@types/lodash-es": "^4.17.5",
"c8": "^7.11.0",
"discord.js": "^13.5.1",
@@ -54,7 +51,6 @@
"esbuild": "latest",
"esbuild-jest": "^0.5.0",
"esmo": "^0.13.0",
"jest": "^27.4.7",
"lodash-es": "^4.17.21",
"nodemon": "^2.0.15",
"prettier": "^2.5.1",
@@ -63,7 +59,9 @@
"release-it": "^14.12.1",
"tsup": "^5.11.11",
"type-fest": "^2.9.0",
"typescript": "^4.5.4"
"typescript": "^4.5.4",
"vite": "^2.7.10",
"vitest": "^0.0.139"
},
"resolutions": {
"esbuild": "latest"

View File

@@ -1,4 +1,5 @@
import React from "react"
import { test } from "vitest"
import { ReacordTester } from "../library/core/reacord-tester"
import { ActionRow, Button, Select } from "../library/main"

View File

@@ -1,2 +1,3 @@
import { test } from "vitest"
test.todo("channel message renderer")
export {}

View File

@@ -1,2 +1,3 @@
import { test } from "vitest"
test.todo("discord js integration")
export {}

View File

@@ -1,4 +1,5 @@
import React from "react"
import { test } from "vitest"
import { ReacordTester } from "../library/core/reacord-tester"
import {
Embed,

View File

@@ -1,2 +1,2 @@
import { test } from "vitest"
test.todo("ephemeral reply")
export {}

View File

@@ -1,3 +1,4 @@
import { test } from "vitest"
test.todo("button onClick")
test.todo("select onChange")
export {}

View File

@@ -1,4 +1,5 @@
import React from "react"
import { test } from "vitest"
import { ReacordTester } from "../library/core/reacord-tester"
import { Link } from "../library/main"

View File

@@ -1,4 +1,5 @@
import * as React from "react"
import { test } from "vitest"
import {
Button,
Embed,

View File

@@ -1,6 +1,6 @@
import { test } from "vitest"
// test that the interaction update is _eventually_ deferred if there's no component update,
// and that update isn't called after the fact
// ...somehow
test.todo("defer update timeout")
export {}

View File

@@ -1,10 +1,10 @@
import { jest } from "@jest/globals"
import React, { useState } from "react"
import { expect, fn, test } from "vitest"
import { Button, Option, ReacordTester, Select } from "../library/main"
test("single select", async () => {
const tester = new ReacordTester()
const onSelect = jest.fn()
const onSelect = fn()
function TestSelect() {
const [value, setValue] = useState<string>()
@@ -74,7 +74,7 @@ test("single select", async () => {
test("multiple select", async () => {
const tester = new ReacordTester()
const onSelect = jest.fn()
const onSelect = fn()
function TestSelect() {
const [values, setValues] = useState<string[]>([])
@@ -125,13 +125,13 @@ test("multiple select", async () => {
expect(onSelect).toHaveBeenCalledTimes(0)
tester.findSelectByPlaceholder("select").select("1", "3")
await assertSelect(expect.arrayContaining(["1", "3"]))
await assertSelect(expect.arrayContaining(["1", "3"]) as unknown as string[])
expect(onSelect).toHaveBeenCalledWith(
expect.objectContaining({ values: expect.arrayContaining(["1", "3"]) }),
)
tester.findSelectByPlaceholder("select").select("2")
await assertSelect(expect.arrayContaining(["2"]))
await assertSelect(expect.arrayContaining(["2"]) as unknown as string[])
expect(onSelect).toHaveBeenCalledWith(
expect.objectContaining({ values: expect.arrayContaining(["2"]) }),
)

View File

@@ -0,0 +1,8 @@
/// <reference types="vitest" />
import { defineConfig } from "vite"
export default defineConfig({
build: {
sourcemap: true,
},
})