Skip to content

Commit

Permalink
test: replace jest by vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
janek26 committed Jun 29, 2022
1 parent 3309dc7 commit fef4c73
Show file tree
Hide file tree
Showing 25 changed files with 714 additions and 1,509 deletions.
2 changes: 1 addition & 1 deletion Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ yarn build

## Need help?

If you want to contribute but have any questions, concerns or doubts, feel free to ping maintainers. Ideally create a pull request with `WIP` (Work in progress) in its title and ask questions in the pull request description.
If you want to contribute but have any questions, concerns or doubts, feel free to ping maintainers. Ideally create a pull request with `WIP` (Work in progress) in its title and ask questions in the pull request description.
3 changes: 1 addition & 2 deletions Deployment.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Deployment
===
# Deployment

We automated some parts of the release process to make things easier. This file lists the nessisary steps to release the latest version of the application:

Expand Down
612 changes: 131 additions & 481 deletions License.md

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"packages": [
"packages/*"
],
"packages": ["packages/*"],
"version": "4.1.9",
"npmClient": "yarn",
"useWorkspaces": true
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"clean": "rm -rf packages/extension/dist packages/get-starket/dist",
"build": "lerna run build",
"build:sourcemaps": "GEN_SOURCE_MAPS=true lerna run build",
"build:sourcemaps": "GEN_SOURCE_MAPS=true lerna run build",
"test": "lerna run test",
"test:e2e": "lerna run test:e2e",
"prepare": "yarn --cwd packages/get-starknet build && husky install",
"storybook": "cd packages/storybook && yarn storybook"
},
Expand Down
9 changes: 0 additions & 9 deletions packages/extension/jest.config.js

This file was deleted.

9 changes: 4 additions & 5 deletions packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
"@playwright/test": "^1.23.0",
"@svgr/webpack": "^6.0.0",
"@testing-library/react": "^13.3.0",
"@types/jest": "^27.4.0",
"@types/jest-json-schema": "^6.1.0",
"@types/lodash-es": "^4.17.6",
"@types/numeral": "^2.0.2",
"@types/object-hash": "^2.2.1",
Expand All @@ -21,6 +19,7 @@
"@types/webextension-polyfill": "^0.9.0",
"@typescript-eslint/eslint-plugin": "^5.10.1",
"@typescript-eslint/parser": "^5.10.1",
"@vitejs/plugin-react": "^1.3.2",
"copy-webpack-plugin": "^11.0.0",
"cross-fetch": "^3.1.5",
"dotenv-webpack": "^7.1.0",
Expand All @@ -33,12 +32,12 @@
"file-loader": "^6.2.0",
"html-webpack-plugin": "^5.5.0",
"isomorphic-fetch": "^3.0.0",
"jest": "^27.5.1",
"jsdom": "^20.0.0",
"raw-loader": "^4.0.2",
"ts-jest": "^27.1.3",
"typescript": "^4.6.3",
"typescript-styled-plugin": "^0.18.2",
"url-loader": "^4.1.1",
"vitest": "^0.16.0",
"wait-for-expect": "^3.0.2",
"webpack": "^5.62.1",
"webpack-cli": "^4.9.1"
Expand All @@ -49,7 +48,7 @@
"build:sourcemaps": "NODE_ENV=production GEN_SOURCE_MAPS=true webpack",
"start": "webpack",
"dev": "webpack --color --watch",
"test": "jest",
"test": "vitest run",
"pretest:e2e": "[ -d dist ] || yarn build",
"test:e2e": "playwright test",
"version": "yarn run change-to-release-branch && yarn run sync-manifest-version && yarn run commit-version-changes && yarn run push-release-branch",
Expand Down
4 changes: 1 addition & 3 deletions packages/extension/src/background/swr/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ export function parseConfig(config: Config) {
const minTimeToStale = config.minTimeToStale || 0
const maxTimeToLive =
Math.min(config.maxTimeToLive ?? 0, Number.MAX_SAFE_INTEGER) || Infinity
const serialize = isFunction(config.serialize)
? config.serialize
: identity
const serialize = isFunction(config.serialize) ? config.serialize : identity
const deserialize = isFunction(config.deserialize)
? config.deserialize
: identity
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/ui/theme.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createTheme } from "@mui/material/styles"
import { createGlobalStyle } from "styled-components"
import { normalize } from "styled-normalize"
import { createTheme } from "@mui/material/styles"

/**
* Adds additional variables to the theme
Expand Down
20 changes: 10 additions & 10 deletions packages/extension/test/__snapshots__/transactions.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1

exports[`nameTransaction() should return right metadata for 1 transaction 1`] = `
Object {
exports[`nameTransaction() > should return right metadata for 1 transaction 1`] = `
{
"title": "Transfer from",
}
`;

exports[`nameTransaction() should return right metadata for 2 transactions 1`] = `
Object {
exports[`nameTransaction() > should return right metadata for 2 transactions 1`] = `
{
"title": "Approve and Transfer",
}
`;

exports[`transactions should get a transaction by hash 1`] = `
Object {
"account": Object {
exports[`transactions > should get a transaction by hash 1`] = `
{
"account": {
"address": "0x05e54edb59e1b1e398f9647e617276f6da0eb9ddfc0c02723269b9baa2489dce",
"network": Object {
"network": {
"accountClassHash": "0x3e327de1c40540b98d05cbcb13552008e36f0ec8d61d46956d2f9752c294328",
"baseUrl": "https://alpha4.starknet.io",
"chainId": "SN_GOERLI",
Expand All @@ -27,7 +27,7 @@ Object {
"readonly": true,
},
"networkId": "goerli-alpha",
"signer": Object {
"signer": {
"derivationPath": "0",
"type": "local_secret",
},
Expand Down
2 changes: 2 additions & 0 deletions packages/extension/test/addresses.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, test } from "vitest"

import { addressSchema } from "../src/ui/services/addresses"

describe("address input", () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/extension/test/analytics.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, test } from "vitest"

import { anonymizeUserAgent } from "../src/shared/analytics"

describe("anonymizeUseragent()", () => {
Expand Down
1 change: 1 addition & 0 deletions packages/extension/test/call.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Call } from "starknet"
import { describe, expect, test } from "vitest"

import {
Erc20TransferCall,
Expand Down
1 change: 1 addition & 0 deletions packages/extension/test/keyDerivation.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ec } from "starknet"
import { describe, expect, test } from "vitest"

import {
getNextPathIndex,
Expand Down
2 changes: 2 additions & 0 deletions packages/extension/test/schema.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from "vitest"

import backupSchema from "../src/background/schema/backup.schema"
import { Wallet } from "../src/background/wallet"
import legacyBackup from "./backup_legacy.mock.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { register } from "fetch-intercept"

global.fetch = fetch

jest.setTimeout(50 * 60 * 1000)

if (process.env.DEBUG === "true") {
register({
request(url, config) {
Expand Down
7 changes: 2 additions & 5 deletions packages/extension/test/swr.test.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
/**
* @jest-environment jsdom
*/

import { fireEvent, render, screen } from "@testing-library/react"
import { useState } from "react"
import { describe, expect, test, vi } from "vitest"

import { useConditionallyEnabledSWR } from "../src/ui/services/swr"

describe("swr", () => {
describe("useConditionallyEnabledSWR()", () => {
test("should use the fetcher and return data when enabled, set data to undefined when disabled", async () => {
const fetcher = jest.fn(() => "foo")
const fetcher = vi.fn(() => "foo")

function Component() {
const [enabled, setEnabled] = useState(true)
Expand Down
1 change: 1 addition & 0 deletions packages/extension/test/tokenPrice.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BigNumber } from "ethers"
import { number } from "starknet"
import { describe, expect, test } from "vitest"

import {
convertTokenAmountToCurrencyValue,
Expand Down
5 changes: 1 addition & 4 deletions packages/extension/test/tokenPriceHooks.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/**
* @jest-environment jsdom
*/

import { renderHook } from "@testing-library/react"
import { describe, expect, test } from "vitest"

import {
useSumTokenBalancesToCurrencyValue,
Expand Down
2 changes: 2 additions & 0 deletions packages/extension/test/tokens.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, test } from "vitest"

import { formatTokenBalance } from "../src/ui/features/accountTokens/tokens.service"

describe("format token balance", () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/extension/test/transactions.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "isomorphic-fetch"

import { Call } from "starknet"
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"
import waitForExpect from "wait-for-expect"

import { ArrayStorage } from "../src/background/storage/array"
Expand Down Expand Up @@ -43,7 +44,7 @@ const fetchMockTransactions: FetchTransactions = async (_, __) =>

describe("transactions", () => {
let txTracker: TransactionTracker
const fn = jest.fn()
const fn = vi.fn()
beforeEach(async () => {
txTracker = getTransactionsTracker(
getTransactionsStore,
Expand Down Expand Up @@ -191,7 +192,7 @@ describe("getTransactionsStatusUpdate()", () => {

describe("setAsyncInterval()", () => {
test("should run fn every n seconds", async () => {
const fn = jest.fn()
const fn = vi.fn()
const n = 100

const stop = setIntervalAsync(fn, n)
Expand Down
18 changes: 9 additions & 9 deletions packages/extension/test/wallet.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import fs from "fs"
import path from "path"

import { afterEach, expect, test, vi } from "vitest"

import { LoadContracts } from "../src/background/accounts"
import {
GetNetwork,
Expand Down Expand Up @@ -44,14 +46,12 @@ const getNetwork: GetNetwork = async (networkId) =>
name: "Test Network",
}) as Network

jest.setTimeout(999999)

afterEach(() => {
jest.useRealTimers()
vi.useRealTimers()
})

test("create a new wallet", async () => {
jest.useFakeTimers()
vi.useFakeTimers()

const storage = new MockStorage<WalletStorageProps>()
const wallet = new Wallet(storage, loadContracts, getNetwork)
Expand Down Expand Up @@ -82,12 +82,12 @@ test("create a new wallet", async () => {
const selectedAccount = await wallet.getSelectedAccount()
expect(selectedAccount).toBeDefined()

jest.advanceTimersByTime(SESSION_DURATION_PLUS_ONE_SEC)
vi.advanceTimersByTime(SESSION_DURATION_PLUS_ONE_SEC)
expect(wallet.isSessionOpen()).toBe(false)
})

test("open existing wallet", async () => {
jest.useFakeTimers()
vi.useFakeTimers()

const storage = new MockStorage<WalletStorageProps>()
storage.setItem("backup", backupString)
Expand Down Expand Up @@ -118,7 +118,7 @@ test("open existing wallet", async () => {
"0x06c67629cae87e7a1b284f1002747af681b39b8199f9263b9aed985e200d8f59",
)

jest.advanceTimersByTime(SESSION_DURATION_PLUS_ONE_SEC)
vi.advanceTimersByTime(SESSION_DURATION_PLUS_ONE_SEC)
expect(wallet.isSessionOpen()).toBe(false)
})

Expand All @@ -137,7 +137,7 @@ test("open existing wallet with wrong password", async () => {
})

test("import backup file", async () => {
jest.useFakeTimers()
vi.useFakeTimers()

const storage = new MockStorage<WalletStorageProps>()
storage.setItem("discoveredOnce", true)
Expand All @@ -154,7 +154,7 @@ test("import backup file", async () => {
expect(isValid).toBe(true)
expect(wallet.isSessionOpen()).toBe(true)

jest.advanceTimersByTime(SESSION_DURATION_PLUS_ONE_SEC)
vi.advanceTimersByTime(SESSION_DURATION_PLUS_ONE_SEC)
expect(wallet.isSessionOpen()).toBe(false)
})

Expand Down
18 changes: 18 additions & 0 deletions packages/extension/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import react from "@vitejs/plugin-react"
import { defineConfig } from "vitest/config"

export default defineConfig({
plugins: [react()],
test: {
globals: true,
setupFiles: "test/setup.ts",
environment: "jsdom",
testTimeout: 50 * 60 * 1000,
exclude: [
"**/node_modules/**",
"**/dist/**",
"**/e2e/**",
"**/.{idea,git,cache,output,temp}/**",
],
},
})
1 change: 1 addition & 0 deletions packages/get-starknet/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Getting Started

<!-- show deprication warning -->

> **Deprication Warning:** This package is deprecated. Please use the community [`get-starknet`](https://www.npmjs.com/package/get-starknet) package instead.
```javascript
Expand Down
Loading

0 comments on commit fef4c73

Please sign in to comment.