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, CamelCasedPropertiesDeep,
SnakeCasedPropertiesDeep, SnakeCasedPropertiesDeep,
} from "type-fest" } from "type-fest"
import { expect, test } from "vitest"
import { camelCaseDeep, snakeCaseDeep } from "./convert-object-property-case" import { camelCaseDeep, snakeCaseDeep } from "./convert-object-property-case"
test("camelCaseDeep", () => { test("camelCaseDeep", () => {
@@ -12,12 +13,14 @@ test("camelCaseDeep", () => {
someOtherProp: "someOtherValue", someOtherProp: "someOtherValue",
} }
expect(camelCaseDeep(input)).toEqual<CamelCasedPropertiesDeep<typeof input>>({ const expected: CamelCasedPropertiesDeep<typeof input> = {
someProp: { someProp: {
someDeepProp: "some_deep_value", someDeepProp: "some_deep_value",
}, },
someOtherProp: "someOtherValue", someOtherProp: "someOtherValue",
}) }
expect(camelCaseDeep(input)).toEqual(expected)
}) })
test("snakeCaseDeep", () => { test("snakeCaseDeep", () => {
@@ -28,10 +31,12 @@ test("snakeCaseDeep", () => {
some_other_prop: "someOtherValue", some_other_prop: "someOtherValue",
} }
expect(snakeCaseDeep(input)).toEqual<SnakeCasedPropertiesDeep<typeof input>>({ const expected: SnakeCasedPropertiesDeep<typeof input> = {
some_prop: { some_prop: {
some_deep_prop: "someDeepValue", some_deep_prop: "someDeepValue",
}, },
some_other_prop: "someOtherValue", 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 { nextTick } from "node:process"
import { promisify } from "node:util" import { promisify } from "node:util"
import type { ReactNode } from "react" import type { ReactNode } from "react"
import { expect } from "vitest"
import { logPretty } from "../../helpers/log-pretty" import { logPretty } from "../../helpers/log-pretty"
import { omit } from "../../helpers/omit" import { omit } from "../../helpers/omit"
import { raise } from "../../helpers/raise" import { raise } from "../../helpers/raise"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,4 +1,5 @@
import * as React from "react" import * as React from "react"
import { test } from "vitest"
import { import {
Button, Button,
Embed, 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, // test that the interaction update is _eventually_ deferred if there's no component update,
// and that update isn't called after the fact // and that update isn't called after the fact
// ...somehow // ...somehow
test.todo("defer update timeout") test.todo("defer update timeout")
export {}

View File

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

1496
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff