diff --git a/scripts/create-icons/index.test.ts b/scripts/create-icons/index.test.ts
index 926ee4d3..b030b0f0 100644
--- a/scripts/create-icons/index.test.ts
+++ b/scripts/create-icons/index.test.ts
@@ -1,14 +1,10 @@
-import { afterAll, test } from 'vitest'
+import { test } from 'vitest'
import fs from 'fs/promises'
import path from 'path'
import { generateIcons } from './index'
const distDir = path.resolve(__dirname, 'tmp')
-afterAll(() => {
- fs.rm(path.resolve(__dirname, 'tmp'), { recursive: true })
-})
-
test('should generate Astro & React components from SVG files', async () => {
// Act
await generateIcons(distDir)
@@ -45,4 +41,7 @@ test('should generate Astro & React components from SVG files', async () => {
`Example React component does not exist: ${exampleComponentPathReact}`
)
}
+
+ // cleanup
+ await fs.rm(distDir, { recursive: true, force: true })
})
diff --git a/scripts/move-downloads.ts b/scripts/move-downloads.ts
index 87128ff0..c0355c74 100644
--- a/scripts/move-downloads.ts
+++ b/scripts/move-downloads.ts
@@ -22,7 +22,7 @@ function removeFolderContents(folderPath: string) {
const filePath = path.join(folderPath, file)
if (fs.lstatSync(filePath).isDirectory()) {
removeFolderContents(filePath)
- fs.rmdirSync(filePath)
+ fs.rmSync(filePath)
} else {
fs.unlinkSync(filePath)
}
diff --git a/scripts/new/index.test.ts b/scripts/new/index.test.ts
index e9fb1e92..e67d4041 100644
--- a/scripts/new/index.test.ts
+++ b/scripts/new/index.test.ts
@@ -9,7 +9,7 @@ const destFolder = path.join('.', 'test/__fixtures__/tmp')
describe('npm run new', () => {
afterEach(async () => {
- await fs.rmdir(destFolder, { recursive: true })
+ await fs.rm(destFolder, { recursive: true })
})
// Mock spinner
diff --git a/src/components/Exif/ExifMap.test.tsx b/src/components/Exif/ExifMap.test.tsx
index 06dbd726..7a06be1a 100644
--- a/src/components/Exif/ExifMap.test.tsx
+++ b/src/components/Exif/ExifMap.test.tsx
@@ -1,20 +1,23 @@
import { describe, it } from 'vitest'
-import { render, screen } from '@testing-library/react'
+import { render, screen, fireEvent } from '@testing-library/react'
import ExifMap from './ExifMap'
describe('ExifMap', () => {
it('renders without crashing', async () => {
render(
-
-
-
-
-
-
+ <>
+
+
+ >
)
await screen.findByText(/wheel to zoom/)
+
+ // Simulate a change event on the checkbox
+ fireEvent.change(screen.getByTestId('toggle'), {
+ target: { checked: true }
+ })
})
})
diff --git a/src/components/Location/index.test.tsx b/src/components/Location/index.test.tsx
index 26e7ee4c..28d27601 100644
--- a/src/components/Location/index.test.tsx
+++ b/src/components/Location/index.test.tsx
@@ -77,7 +77,9 @@ describe('Location component', () => {
})
it('renders nothing and logs error when error is encountered', () => {
- const consoleErrorSpy = vi.spyOn(console, 'error')
+ const consoleErrorSpy = vi
+ .spyOn(console, 'error')
+ .mockImplementation(() => {})
useStoreSpy.mockImplementationOnce(() => ({
data: null,
loading: false,
@@ -90,5 +92,8 @@ describe('Location component', () => {
expect(consoleErrorSpy).toHaveBeenCalledWith(
'Failed to fetch location: Error'
)
+
+ // Restore the original console.error function after the test
+ consoleErrorSpy.mockRestore()
})
})
diff --git a/src/features/Web3/components/Preview/Preview.tsx b/src/features/Web3/components/Preview/Preview.tsx
index bad330dd..b75f1c75 100644
--- a/src/features/Web3/components/Preview/Preview.tsx
+++ b/src/features/Web3/components/Preview/Preview.tsx
@@ -39,8 +39,6 @@ export function Preview() {
isDisabled={isLoading}
/>
- {console.log(txConfig)}
-
{error || prepareError ? (
{error || prepareError}
) : null}
diff --git a/src/features/Web3/hooks/useFetchTokens/useFetchTokens.tsx b/src/features/Web3/hooks/useFetchTokens/useFetchTokens.tsx
index 27a888f8..6dae3a52 100644
--- a/src/features/Web3/hooks/useFetchTokens/useFetchTokens.tsx
+++ b/src/features/Web3/hooks/useFetchTokens/useFetchTokens.tsx
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react'
-import useSWR from 'swr'
+import useSWR, { type SWRResponse } from 'swr'
import { useNetwork, useAccount } from 'wagmi'
import type { GetToken } from './types'
@@ -9,7 +9,7 @@ const apiUrl = import.meta.env.PUBLIC_WEB3_API_URL
//
// Wrapper for fetching user tokens with swr.
//
-export function useFetchTokens() {
+export function useFetchTokens(): SWRResponse {
const { chain } = useNetwork()
const { address } = useAccount()
diff --git a/src/lib/astro/loadAndFormatCollection.test.ts b/src/lib/astro/loadAndFormatCollection.test.ts
index c282a8b4..15c56e67 100644
--- a/src/lib/astro/loadAndFormatCollection.test.ts
+++ b/src/lib/astro/loadAndFormatCollection.test.ts
@@ -8,6 +8,7 @@ import getCollectionPhotos from '@test/__fixtures__/getCollectionPhotos.json'
let getCollectionSpy: any
let readOutExifSpy: any
+let consoleErrorSpy: any
beforeEach(() => {
getCollectionSpy = vi.spyOn(astroContent, 'getCollection')
@@ -17,11 +18,14 @@ beforeEach(() => {
exif: 'mocked exif',
iptc: 'mocked iptc'
}))
+
+ // Silence console.error
+ consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
})
afterEach(() => {
getCollectionSpy.mockRestore()
- readOutExifSpy.mockRestore()
+ consoleErrorSpy.mockRestore()
})
describe('loadAndFormatCollection', () => {
diff --git a/src/lib/github/github.test.ts b/src/lib/github/github.test.ts
index 732712e4..0f6cb998 100644
--- a/src/lib/github/github.test.ts
+++ b/src/lib/github/github.test.ts
@@ -23,23 +23,36 @@ describe('getRepo Function', () => {
}
}
- const mockFetch = async () => ({ json: async () => mockResponseData })
-
it('should fetch repo data', async () => {
+ const mockFetch = async () => ({ json: async () => mockResponseData })
const originalFetch = window.fetch
+
+ // Silence console.log, console.info, and console.error
+ const originalConsoleLog = console.log
+ const originalConsoleInfo = console.info
+ const originalConsoleError = console.error
+ console.log = () => {}
+ console.info = () => {}
+ console.error = () => {}
+
window.fetch = mockFetch as any
const repoInfo = await getRepo('mockuser/mockrepo')
- window.fetch = originalFetch
-
expect(repoInfo).toEqual(mockResponseData.data.user.repository)
+
+ // Restore the original fetch and console functions
+ window.fetch = originalFetch
+ console.log = originalConsoleLog
+ console.info = originalConsoleInfo
+ console.error = originalConsoleError
})
it('should handle errors', async () => {
- const consoleMock = vi
+ const consoleErrorMock = vi
.spyOn(console, 'error')
.mockImplementation(() => undefined)
+
const originalFetch = window.fetch
;(window as any).fetch = async () => ({
@@ -51,9 +64,9 @@ describe('getRepo Function', () => {
window.fetch = originalFetch
expect(repoInfo).toBeUndefined()
- expect(consoleMock).toHaveBeenCalled()
- expect(consoleMock).toHaveBeenLastCalledWith(['Mock error message'])
+ expect(consoleErrorMock).toHaveBeenCalled()
+ expect(consoleErrorMock).toHaveBeenLastCalledWith(['Mock error message'])
- consoleMock.mockReset()
+ consoleErrorMock.mockReset()
})
})
diff --git a/test/vitest.config.ts b/test/vitest.config.ts
index 4bd85454..45e4a73f 100644
--- a/test/vitest.config.ts
+++ b/test/vitest.config.ts
@@ -19,6 +19,7 @@ export default getViteConfig({
all: true,
exclude: [
'**/*.d.ts',
+ '**/types.ts',
'**/*.test.ts',
'**/*.spec.ts',
'**/test/**/*',
diff --git a/tsconfig.json b/tsconfig.json
index f7a5bccd..f773b30e 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -17,11 +17,7 @@
},
"typeRoots": ["./src/@types", "./node_modules/@types"]
},
- "exclude": [
- "src/images/components/**/*",
- "src/content",
- "scripts/create-icons/tmp/"
- ],
+ "exclude": ["src/images/components/**/*", "src/content"],
"include": [
"src/**/*",
"content/**/*",