Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add testing environment #73

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Conversation

ErikSin
Copy link
Contributor

@ErikSin ErikSin commented Dec 19, 2024

  1. Adds React Testing Library and jest dom. configure setup file to import jest dom.
  2. Creates a mock client api to allow for testing of @comapeo-core/react
  3. Writes test for / route and _Map route

@awana-lockfile-bot
Copy link

awana-lockfile-bot bot commented Dec 19, 2024

package-lock.json changes

Click to toggle table visibility
Name Status Previous Current
@adobe/css-tools ADDED - 4.4.1
@comapeo/core-react UPDATED 0.1.2 1.1.0
@testing-library/jest-dom ADDED - 6.6.3
css.escape ADDED - 1.5.1
min-indent ADDED - 1.0.1
random-access-memory ADDED - 6.2.1
redent ADDED - 3.0.0
strip-indent ADDED - 3.0.0

Copy link
Member

@achou11 achou11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial feeling is that the actual tests introduced here feel better-suited for being done in the actual app as opposed to the emulated environment. think it's fine for now given that we don't have that set up

Also, I'd prefer the tests directory to be located at the renderer root instead of within its src directory. see #76 for reasoning, but basically it better follows conventions around node-based projects.

import { render, screen } from '@testing-library/react'
import { expect, test } from 'vitest'

import { IntlProvider } from '../../contexts/IntlContext'
import { MapLayout } from './_Map'
import { router } from '../../App'
Copy link
Member

@achou11 achou11 Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to how we should be working with zustand stores in tests, I think the tests should avoid using this singleton instance and instead create their own instance within the test to avoid potential issues related to shared instances across tests i.e.

import { routeTree } from '../../routeTree.gen'

describe('tabs navigate to correct routes', () => {
	const router = createRouter({ routeTree })

	render(<RouterProvider router={router} />, { wrapper: Wrapper })

        // rest of tests...

expect(title).toBeVisible()
})

test('Clicking "Settings" propogates "/Tab 2" to the navigator', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
test('Clicking "Settings" propogates "/Tab 2" to the navigator', () => {
test('Clicking "Settings" propagates "/Tab 2" to the navigator', () => {

import { render, waitFor } from '@testing-library/react'
import { describe, expect, test } from 'vitest'

import { router } from '../App'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment about creating these router instances within the tests instead of using the singleton instance

Comment on lines +41 to +52
export const ReuseableProviderWrapper = ({
children,
}: {
children: ReactNode
}) => {
return (
<ThemeProvider theme={theme}>
<CssBaseline />
<IntlProvider>{children}</IntlProvider>
</ThemeProvider>
)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think abstracting this is necessary for the time being. would suggest just doing duplicate work of setting up the providers in the relevant test helper for now

import { createMapeoServer } from '@comapeo/ipc/dist/server.js'
import { KeyManager } from '@mapeo/crypto'
import Fastify from 'fastify'
// @ts-expect-error - no types
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you add the following to the compilerOptions in the project root tsconfig.json, it should fix this issue:

"baseUrl": "./",
"paths": {
    "*": ["node_modules/@digidem/types/vendor/*/index.d.ts"]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants