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

TypeError: fs.existsSync is not a function even when using Tasks #8098

Closed
kzaiwo opened this issue Jul 28, 2020 · 1 comment
Closed

TypeError: fs.existsSync is not a function even when using Tasks #8098

kzaiwo opened this issue Jul 28, 2020 · 1 comment

Comments

@kzaiwo
Copy link

kzaiwo commented Jul 28, 2020

I am using Cypress to test my Electron application.
Since Cypress uses the browser mode, FS is not supported.

So I am getting this error:

Error in mounted hook: "TypeError: fs.existsSync is not a function"

I know Electron is not yet fully supported, but specifically for my need to use fs, I found this on the documentation:

https://docs.cypress.io/api/commands/task.html#Event

So I added this on my test:

it('Sample test', () => {
  cy.task('readSettingsJson', settingsFolder).then((content) => { 
    // This can print the JSON file contents correctly
    console.log('content = ' + content) 
  })
})

And on my plugins/index.js:

 on('task', {
    readSettingsJson(foldername) {
      if (!fs.existsSync(foldername)) {
        fs.mkdirSync(foldername, { recursive: true })
        // some command to copy the file
      } else {
        // This is what I am testing at this moment
        return fs.readFileSync(path.join(filename, '/settings.json'), 'utf8')
      }

      return null
    }
 })

However, it doesnt seem to work. I still get the error:

Error in mounted hook: "TypeError: fs.existsSync is not a function"

And despite the test printing (console.log in the test) the json file correctly, my app still can't load the JSON file.

Am I missing anything? Help please! Thank you!

Cypress Version: 4.3.0
Browser: Electron

@jennifer-shehane
Copy link
Member

This seems isolated to your running and testing within Electron app (or some other variable in your project) - as this is not reproducible with the code provided. Some comments in Electron mention changing the require statements maybe helping. electron/electron#7300 (comment)

Closing as we don't support testing Electron apps out of the box.

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