Skip to content

Commit

Permalink
Merge pull request #10 from xmtp/migrate-to-vitest
Browse files Browse the repository at this point in the history
Migrate to vitest
  • Loading branch information
neekolas authored Sep 8, 2023
2 parents 191eea0 + 53c3326 commit 3c8e72f
Show file tree
Hide file tree
Showing 15 changed files with 690 additions and 296 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = {
ecmaVersion: 2020,
},
env: {
"jest/globals": true,
es6: true,
node: true,
},
Expand All @@ -27,7 +26,7 @@ module.exports = {
plugins: [
"@typescript-eslint",
"prettier",
"jest",
"vitest",
"promise",
"simple-import-sort",
],
Expand Down
2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
enableTransparentWorkspaces: true
enableTransparentWorkspaces: false

nodeLinker: node-modules
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-vitest": "^0.3.1",
"jest": "^29.5.0",
"prettier": "^3.0.2",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
"typescript": "^5.1.6",
"vitest": "^0.34.3"
},
"packageManager": "[email protected]"
}
19 changes: 0 additions & 19 deletions packages/bot-kit-pro/jest.config.ts

This file was deleted.

6 changes: 3 additions & 3 deletions packages/bot-kit-pro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
"migration:run": "",
"up": "./dev/up",
"prepublishOnly": "yarn build",
"test": "jest ./src"
"test": "vitest run ./src"
},
"dependencies": {
"@xmtp/grpc-api-client": "workspace:*",
"@xmtp/proto": "^3.27.0",
"@xmtp/xmtp-js": "^11.0.0-beta.8",
"drizzle-orm": "^0.28.6",
"ethers": "^6.7.1",
"jest": "^29.6.4",
"long": "^5.2.3",
"pino": "^8.15.0",
"pino-pretty": "^10.2.0",
Expand Down Expand Up @@ -51,6 +50,7 @@
"homepage": "https://github.com/xmtp/bot-tools-js#readme",
"packageManager": "[email protected]",
"devDependencies": {
"drizzle-kit": "^0.19.13"
"drizzle-kit": "^0.19.13",
"vitest": "^0.34.3"
}
}
10 changes: 4 additions & 6 deletions packages/bot-kit-pro/src/bot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Client } from "@xmtp/xmtp-js"
import { randomBytes } from "crypto"
import { eq } from "drizzle-orm"
import { Wallet } from "ethers"
import postgres from "postgres"
import { beforeAll, beforeEach, describe, expect, it } from "vitest"

import Bot, { BotHandler, getOrCreateXmtpKeys } from "./bot.js"
import { newAppConfig, newBotConfig } from "./config.js"
Expand All @@ -16,18 +16,16 @@ import { PostgresPersistence } from "./persistence.js"
describe("Bot", () => {
let keys: Uint8Array
let dataSource: DB
let dbConnection: postgres.Sql

beforeAll(async () => {
const appConfig = newAppConfig({})
await doMigrations(appConfig.db)
const { db, connection } = await buildDrizzle(appConfig.db)
dataSource = db
dbConnection = connection
})

afterAll(async () => {
await dbConnection.end()
return async () => {
await connection.end()
}
})

beforeEach(async () => {
Expand Down
10 changes: 4 additions & 6 deletions packages/bot-kit-pro/src/persistence.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { randomBytes } from "crypto"
import postgres from "postgres"
import { beforeAll, beforeEach, describe, expect, it } from "vitest"

import { newAppConfig } from "./config"
import { buildDrizzle, doMigrations } from "./db/database"
Expand All @@ -8,17 +8,15 @@ import { randomKeys } from "./utils"

describe("persistence", () => {
let persistence: PostgresPersistence
let dbConnection: postgres.Sql
beforeAll(async () => {
const appConfig = newAppConfig({})
await doMigrations(appConfig.db)
const { db, connection } = await buildDrizzle(appConfig.db)
dbConnection = connection
persistence = new PostgresPersistence(db)
})

afterAll(async () => {
await dbConnection.end()
return async () => {
await connection.end()
}
})

it("allows setting and retrieving values", async () => {
Expand Down
19 changes: 0 additions & 19 deletions packages/grpc-api-client/jest.config.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/grpc-api-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"build": "tsc",
"prepublishOnly": "yarn build",
"gen:proto": "buf generate buf.build/xmtp/proto --path message_api/v1",
"test": "jest ."
"test": "vitest run ./src"
},
"author": "XMTP Labs <[email protected]>",
"license": "MIT",
Expand Down
1 change: 1 addition & 0 deletions packages/grpc-api-client/src/GrpcApiClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from "@xmtp/xmtp-js"
import { randomBytes } from "crypto"
import { Wallet } from "ethers"
import { beforeEach, describe, expect, it } from "vitest"

import GrpcApiClient from "./GrpcApiClient"

Expand Down
19 changes: 0 additions & 19 deletions packages/redis-persistence/jest.config.ts

This file was deleted.

5 changes: 2 additions & 3 deletions packages/redis-persistence/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"start-redis": "docker-compose up -d",
"build": "tsc",
"test": "jest .",
"test": "vitest run .",
"pretest": "yarn start-redis"
},
"dependencies": {
Expand Down Expand Up @@ -36,7 +36,6 @@
"homepage": "https://github.com/xmtp/bot-kit-pro#readme",
"packageManager": "[email protected]",
"devDependencies": {
"@xmtp/xmtp-js": "11.0.0-beta.8",
"jest": "^29.6.4"
"@xmtp/xmtp-js": "11.0.0-beta.8"
}
}
9 changes: 5 additions & 4 deletions packages/redis-persistence/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createClient, RedisClientType } from "@redis/client"
import { randomBytes } from "crypto"
import { beforeAll, beforeEach, describe, expect, it } from "vitest"

import { RedisPersistence } from "."

Expand All @@ -12,17 +13,17 @@ describe("RedisPersistence", () => {
url: "redis://localhost:6379",
})
await redis.connect()

return async () => {
await redis.disconnect()
}
})

beforeEach(() => {
keyPrefix = randomKey()
persistence = new RedisPersistence(redis, keyPrefix)
})

afterAll(async () => {
await redis.disconnect()
})

it("can write to a key", async () => {
const value = Uint8Array.from([1, 2, 3])
const key = randomKey()
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/* Projects */
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
"composite": true /* Enable constraints that allow a TypeScript project to be used with project references. */,
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
Expand Down Expand Up @@ -36,7 +36,6 @@
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
"types": [
"@types/jest",
"@types/node"
] /* Specify type package names to be included without being referenced in a source file. */,
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
Expand Down
Loading

0 comments on commit 3c8e72f

Please sign in to comment.