Skip to content

Commit

Permalink
Merge pull request #96 from Nosto/vitest-conversion
Browse files Browse the repository at this point in the history
Convert to vitest
  • Loading branch information
timowestnosto authored Aug 14, 2024
2 parents e5891f7 + 89e6258 commit 79e2d09
Show file tree
Hide file tree
Showing 15 changed files with 1,087 additions and 3,446 deletions.
4,474 changes: 1,058 additions & 3,416 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 6 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,37 @@
"clean": "rimraf dist",
"prettier": "prettier '{src,spec}/**' --list-different",
"prettier:fix": "prettier '{src,spec}/**' --write",
"test": "jest spec",
"test": "vitest run --silent",
"typedoc": "typedoc src/index.ts"
},
"files": [
"dist",
"src"
],
"devDependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@testing-library/jest-dom": "^6.4.8",
"@testing-library/react": "^16.0.0",
"@testing-library/user-event": "^14.4.3",
"@types/jest": "^29.5.0",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@types/user-event": "^4.1.1",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"@vitejs/plugin-react": "^1.3.0",
"@vitejs/plugin-react": "^4.3.1",
"eslint": "^8.53.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-react": "^7.33.2",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"prettier": "^2.0.5",
"react": "*",
"react-dom": "*",
"react-router": "^6.25.1",
"react-router-dom": "^6.25.1",
"rimraf": "^3.0.2",
"ts-jest": "^29.1.0",
"typedoc": "^0.24.1",
"typescript": "^4.6.3",
"vite": "^5.2.10",
"vite-plugin-dts": "^3.9.1"
"vite-plugin-dts": "^3.9.1",
"vitest": "^2.0.5"
},
"main": "./dist/index.umd.js",
"module": "./dist/index.es.js",
Expand All @@ -69,12 +66,5 @@
},
"bugs": {
"url": "https://github.com/Nosto/nosto-react/issues"
},
"homepage": "https://github.com/Nosto/nosto-react#readme",
"jest": {
"preset": "ts-jest",
"setupFiles": [
"./spec/setup.js"
]
}
}
2 changes: 1 addition & 1 deletion spec/category.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react"
import { test, expect } from "vitest"
import { render, screen, waitFor } from "@testing-library/react"
import { NostoProvider, NostoCategory, NostoPlacement } from "../src/index"
import RecommendationComponent from "./renderer"
import "@testing-library/jest-dom"
import { WAIT_FOR_TIMEOUT } from "./utils"

test("Category page render", async () => {
Expand Down
2 changes: 1 addition & 1 deletion spec/checkout.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react"
import { test, expect } from "vitest"
import { render, screen, waitFor } from "@testing-library/react"
import { NostoProvider, NostoCheckout, NostoPlacement } from "../src/index"
import RecommendationComponent from "./renderer"
import "@testing-library/jest-dom"
import { WAIT_FOR_TIMEOUT } from "./utils"

test("Checkout page render", async () => {
Expand Down
2 changes: 1 addition & 1 deletion spec/fohofo.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react"
import { test, expect } from "vitest"
import { render, screen, waitFor } from "@testing-library/react"
import { NostoProvider, Nosto404, NostoPlacement } from "../src/index"
import RecommendationComponent from "./renderer"
import "@testing-library/jest-dom"
import { WAIT_FOR_TIMEOUT } from "./utils"

test("404 page render", async () => {
Expand Down
2 changes: 1 addition & 1 deletion spec/home.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react"
import { test, expect } from "vitest"
import { render, screen, waitFor } from "@testing-library/react"
import { NostoProvider, NostoHome, NostoPlacement } from "../src/index"
import RecommendationComponent from "./renderer"
import "@testing-library/jest-dom"
import { WAIT_FOR_TIMEOUT } from "./utils"

test("Home page render", async () => {
Expand Down
9 changes: 5 additions & 4 deletions spec/module.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { test, expect } from "vitest"
import * as imports from "../src/index"

test("module structure is stable", () => {
expect(Object.keys(imports)).toEqual([
"NostoContext",
"useNostoContext",
expect(Object.keys(imports)).toEqual([
"Nosto404",
"NostoOther",
"NostoCheckout",
Expand All @@ -14,6 +13,8 @@ test("module structure is stable", () => {
"NostoHome",
"NostoPlacement",
"NostoProvider",
"NostoSession"
"NostoSession",
"NostoContext",
"useNostoContext"
])
})
1 change: 1 addition & 0 deletions spec/navigation.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from "react"
import { test, expect } from "vitest"
import { NostoCategory, NostoHome, NostoPlacement, NostoProduct, NostoProvider } from "../src"
import RecommendationComponent from "./renderer"
import { Link, BrowserRouter, Route, Routes, useParams } from "react-router-dom"
Expand Down
2 changes: 1 addition & 1 deletion spec/nosto.reload.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react"
import { test, expect } from "vitest"
import { render } from "@testing-library/react"
import { NostoProvider, NostoHome } from "../src/index"
import "@testing-library/jest-dom"

test("verify Nosto is not loaded twice", async () => {
// @ts-expect-error dummy placeholder for Nosto iframe window scope
Expand Down
2 changes: 1 addition & 1 deletion spec/other.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react"
import { test, expect } from "vitest"
import { render, screen, waitFor } from "@testing-library/react"
import { NostoProvider, NostoOther, NostoPlacement } from "../src/index"
import RecommendationComponent from "./renderer"
import "@testing-library/jest-dom"
import { WAIT_FOR_TIMEOUT } from "./utils"

test("Other page render", async () => {
Expand Down
2 changes: 1 addition & 1 deletion spec/product.sku.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useState } from "react"
import { test, expect } from "vitest"
import { fireEvent, render, screen, waitFor } from "@testing-library/react"
import { NostoProvider, NostoPlacement, NostoProduct } from "../src/index"
import RecommendationComponent from "./renderer"
import "@testing-library/jest-dom"
import { listenTo, WAIT_FOR_TIMEOUT } from "./utils"

function ProductPage() {
Expand Down
2 changes: 1 addition & 1 deletion spec/product.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react"
import { test, expect } from "vitest"
import { render, screen, waitFor } from "@testing-library/react"
import { NostoProvider, NostoPlacement, NostoProduct } from "../src/index"
import RecommendationComponent from "./renderer"
import "@testing-library/jest-dom"
import { WAIT_FOR_TIMEOUT } from "./utils"

test("Product page render", async () => {
Expand Down
2 changes: 1 addition & 1 deletion spec/search.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react"
import { test, expect } from "vitest"
import { render, screen, waitFor } from "@testing-library/react"
import { NostoProvider, NostoSearch, NostoPlacement } from "../src/index"
import RecommendationComponent from "./renderer"
import "@testing-library/jest-dom"
import { WAIT_FOR_TIMEOUT } from "./utils"

test("Search page render", async () => {
Expand Down
3 changes: 2 additions & 1 deletion spec/setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { JSDOM } = require("jsdom")
import "@testing-library/jest-dom/vitest"
import { JSDOM } from "jsdom"

const { window } = new JSDOM("<html></html>", {
url: "http://localhost",
Expand Down
6 changes: 6 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ export default defineConfig({
},
},
},
test: {
include: ["*.spec.*"],
dir: "spec",
setupFiles: ['./spec/setup.js'],
silent: true
},
})

0 comments on commit 79e2d09

Please sign in to comment.