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

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

Open
kerbe opened this issue Nov 23, 2022 · 4 comments
Open

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

kerbe opened this issue Nov 23, 2022 · 4 comments

Comments

@kerbe
Copy link

kerbe commented Nov 23, 2022

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
Copy link
Owner

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
Copy link
Author

kerbe commented Nov 24, 2022

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
Copy link
Author

kerbe commented Nov 30, 2022

Any update on this @TomFreudenberg?

@TomFreudenberg
Copy link
Owner

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

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

No branches or pull requests

2 participants