TomFreudenberg / next-auth-mock

NextAuth.js mockup provider for jest, storybook and others.
MIT License
28 stars 1 forks source link

When using with Jest, EISDIR: illegal operation on a directory #3

Open kerbe opened 1 year ago

kerbe commented 1 year ago

I have tried starting to use this package, but running problems on very beginning.

I have test file like this:

// __tests__/index.test.jsx

import { render, screen } from '@testing-library/react'
import { withMockAuth } from '@tomfreudenberg/next-auth-mock/jest'
import Home from '../pages/index'
import '@testing-library/jest-dom'

describe('Home', () => {
  it('renders a heading', () => {
    render(<Home />)

    const heading = screen.getByRole('heading', {
      name: /welcome to next\.js!/i,
    })

    expect(heading).toBeInTheDocument()
  })
})

And when I run jest to test that, I get following error:

 FAIL  __tests__/index.test.jsx
  ● Test suite failed to run

    EISDIR: illegal operation on a directory, read

       6 | import '@testing-library/jest-dom'
       7 |
    >  8 | describe('Home', () => {
         |               ^
       9 |   it('renders a heading', () => {
      10 |     render(<Home />)
      11 |

      at Runtime.readFile (node_modules/jest-runtime/build/index.js:2574:21)
      at Object.<anonymous> (__tests__/index.test.jsx:8:15)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.421 s
Ran all test suites related to changed files.

This problem appears whenever I have import for withMockAuth present, ie this line:

import { withMockAuth } from '@tomfreudenberg/next-auth-mock/jest'

If I remove that line, all works as expected (I get error that useSession needs to be wrapped within SessionProvder). Adding that withMockAuth inside render() call doesn't change output in any way from EISDIR error.

I've wiped my node_modules and installed things again, but hasn't changed outcome. Any ideas for further fixing this issue?

TomFreudenberg commented 1 year ago

Hi @kerbe - thanks for using this component and posting an issue.

I will check that and give you feedback.

Any chance that I may access your sources or at least package.json to check with same conditions?

kerbe commented 1 year ago

I stripped code to bare minimum, and pushed to public repo so you can see: https://github.com/kerbe/next-auth-mock-eisdir-error

That has same package.json as my project. Biggest notepoint might be that it is using NextJS 12.2.2, and not 13.

Actual code is same structure as my project, but stripped down. That index.test.jsx still gives error when withMockAuth is imported, and doesn't when that line isn't present. Actual test in that file would fail, as it is old placeholder I started to update for real Home component structure.

When I was reducing code for that repo, I thought that maybe ChakraUI and it's ChakraProvider might cause problems, but doesn't seem to be the case. Even when I took Chakra out, and had even when removing MainLayout, problem still remained. So left those for clarity, if there are something rising during this bug hunt, that those cause.

kerbe commented 1 year ago

Any update on this @TomFreudenberg?

TomFreudenberg commented 1 year ago

Hi @kerbe

sorry for late reply, I was on a project-trip for the last time. I will follow up starting new year.

Cheers Tom