设置 Cypress IO 以在 Quasar 框架上使用 dotenv

Set up Cypress IO to work with dotenv on Quasar Framework

我正在使用 Quasar 框架,在我添加 quasar-dotenv 包之后,我意识到 e2e 测试不起作用。

Uncaught TypeError: fs.readFileSync is not a function

This error originated from your test code, not from Cypress.

When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.

Cypress could not associate this error to any specific test.

We dynamically generated a new test to display this failure.

Check your console for the stack trace or click this message to see where it originated from.
    at Object.config (http://localhost:8080/__cypress/tests?p=test/cypress/integration/home/init.spec.js-312:141291:34)
    at Object.746.eslint (http://localhost:8080/__cypress/tests?p=test/cypress/integration/home/init.spec.js-312:150393:36)
    at o (http://localhost:8080/__cypress/tests?p=test/cypress/integration/home/init.spec.js-312:1:265)
    at http://localhost:8080/__cypress/tests?p=test/cypress/integration/home/init.spec.js-312:1:316
    at Object.747.../../../../quasar.conf.js (http://localhost:8080/__cypress/tests?p=test/cypress/integration/home/init.spec.js-312:150535:35)
    at o (http://localhost:8080/__cypress/tests?p=test/cypress/integration/home/init.spec.js-312:1:265)
    at r (http://localhost:8080/__cypress/tests?p=test/cypress/integration/home/init.spec.js-312:1:431)
    at http://localhost:8080/__cypress/tests?p=test/cypress/integration/home/init.spec.js-312:1:460

我尝试通过添加带有一些数据的 test/cypress/plugins/cypress.env.json 文件以及更改同一文件夹中的 test/cypress/plugins/index.js 文件来设置 Cypress 环境,方法是遵循此 documentation as it was suggested here:

const env = require('quasar-dotenv').config()

module.exports = (on, config) => {

  // config.env.API_URL = 'http://example.com' // not working
  config.env = env

  // Chrome:: Hack for shaking AUT. Cypress Issue: https://github.com/cypress-io/cypress/issues/1620
  on('before:browser:launch', (browser = {}, args) => {
    if (browser.name === 'chrome') {
      args.push('--disable-blink-features=RootLayerScrolling');
      return args;
    }
    return true;
  });

  return config
};

我不知道答案,因为我不熟悉quasar-dotenv。您是否尝试过官方类星体 dotenv 应用程序扩展? https://github.com/quasarframework/app-extension-dotenv or, alternatively, another official app extension, but less opinionated than dotenv wrappers: https://github.com/quasarframework/app-extension-qenv