Search code examples
javascriptnode.jsmacoscypressmacos-sonoma

Is there a way to avoid the `Secure coding is not enabled for restorable state...` warning for Node scripts?


I'm writing some automated tests using node.js and Cypress, and since I have a lot of them I want to group them split them off onto their own files. I have started doing this, eg:

//myscripts/prodPageTests.js

const { exec } = require('child_process');

let command = "npx cypress run --headless --browser chrome --spec './cypress/e2e/LoremProdPage.feature'";
// Other tests to come.
// Probably in some kind of loop with args.

exec(command, (error, stdout, stderr) => {
    if (error) {
        console.error(`Error executing command: ${error}`);
        return;
    }
    console.log(`Output:\n${stdout}`);
    if (stderr) {
        console.error(`Error Output:\n${stderr}`);
    }
});

This works, but after it runs I also get the warning:

Error Output:

DevTools listening on ws://127.ip.address/devtools/browser/<some hash>
2025-02-19 10:18:07.287 Cypress[18578:4259699] WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSup

Which I understand to be something to do with the Mac Sonoma OS.

I'm just curious: is there a work around for this with node.js?


Solution

  • I would do it using the Module API

    You can require Cypress as a node module from your application under test and run Cypress via Node.js.

    This means you don't need the execa() layer to execute Cypress.

    All of your CLI options are available as options in this mode, for example

    //myscripts/prodPageTests.js
    
    const cypress = require('cypress')
    
    cypress.run({
      browser: 'chrome',
      headless: true,
      spec: './cypress/e2e/LoremProdPage.feature'
    })
    .then((results) => {
      console.log(`Results:\n${results}`);
    })
    .catch((err) => {
      console.error(`Error executing command: ${error}`);
    })