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

ReferenceError: Cypress is not defined #2

Closed
onikiforov opened this issue Apr 17, 2020 · 4 comments
Closed

ReferenceError: Cypress is not defined #2

onikiforov opened this issue Apr 17, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@onikiforov
Copy link

Describe the bug
After upgrading to version 1.4.1 instead of displaying a failure message I see ReferenceError: Cypress is not defined:

  1) Organization STO-1: UI - Settings - Organization:
     ReferenceError: Cypress is not defined
      at Object.handler (/tests/node_modules/@shelex/cypress-allure-plugin/writer.js:60:9)
      at invoke (/Library/Caches/Cypress/4.3.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_plugins.js:21:16)
      at /Library/Caches/Cypress/4.3.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:48:16
      at tryCatcher (/Library/Caches/Cypress/4.3.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
      at Function.Promise.attempt.Promise.try (/Library/Caches/Cypress/4.3.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/method.js:39:29)
      at Object.wrapChildPromise (/Library/Caches/Cypress/4.3.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:47:28)
      at execute (/Library/Caches/Cypress/4.3.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_plugins.js:92:12)
      at EventEmitter.<anonymous> (/Library/Caches/Cypress/4.3.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_plugins.js:200:5)
      at EventEmitter.emit (events.js:210:5)
      at process.<anonymous> (/Library/Caches/Cypress/4.3.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:25:29)
      at process.emit (events.js:210:5)
      at emit (internal/child_process.js:876:12)
      at processTicksAndRejections (internal/process/task_queues.js:81:21)

This works normally in version 1.4.0 and seems to be related to if (Cypress.env('allure') === true) part from 7ff767a

I have plugin is connected in index.js file:

// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

const fs = require("fs-extra");
const path = require("path");
const clipboardy = require("clipboardy");
const allureWriter = require("@shelex/cypress-allure-plugin/writer");

module.exports = (on, config) => {
    // `on` is used to hook into various events Cypress emits
    // `config` is the resolved Cypress config
    // accept a configFile value or use development by default

    // https://docs.cypress.io/api/commands/task.html#Read-a-file-that-might-not-exist
    on("task", {
        readFileMaybe(filename) {
            if (fs.existsSync(filename)) {
                return fs.readFileSync(filename, "utf8");
            }

            return null;
        },
    });

    on("task", {
        getClipboard() {
            return clipboardy.readSync();
        },
    });

    const file = config.env.configFile || "development";

    allureWriter(on);

    return getConfigurationByFile(file);
};

function getConfigurationByFile(file) {
    const pathToConfigFile = path.resolve("cypress/config", `${file}.json`);

    return fs.readJson(pathToConfigFile);
}

Did I miss any changes in configuration?

Environment (please complete the following information):

  • Cypress version: 4.3.0
  • OS: Mac 10.14.6

Also reproduces in CircleCI

Unfortunately, I don't have a sample project to share, but may be able to create one if you need it.

@onikiforov onikiforov added the bug Something isn't working label Apr 17, 2020
@Shelex
Copy link
Owner

Shelex commented Apr 17, 2020

Hello, @onikiforov
Thank you for opening issue on github!

I am aware of it, will provide fix soon.

@onikiforov
Copy link
Author

@Shelex nice, thank you!

@Shelex
Copy link
Owner

Shelex commented Apr 17, 2020

@onikiforov Published v1.5.4 where it should not throw error.
Now it will save screenshot to allure-results in case Cypress is not defined anyway.
It is connected to fact that sometimes Cypress after:screenshot event is emmited after test. Will do better investigation of that stuff if it could be handled in more elegant way.

@onikiforov
Copy link
Author

@Shelex checked both locally and in CI, works as expected, for now. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants