question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

allure-mocha - TypeError: Cannot read property 'epic' of undefined

See original GitHub issue

I’m trying to do this configuration, but allure is undefined. Do you have any example calling allure method from mocha tests using TypeScript?

    "allure-mocha": "2.0.0-beta.6",
// es-modules
import { allure } from 'allure-mocha/runtime';
// or commonjs
const { allure } = require('allure-mocha/runtime');

it('is a test', () => {
  allure.epic('Some info');
});
TypeError: Cannot read property 'epic' of undefined

Thank you

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:26
  • Comments:33 (11 by maintainers)

github_iconTop GitHub Comments

5reactions
sskorolcommented, May 3, 2020

Should work as soon as #138 is merged and a new version is released. I’ve added epic tests and tested it locally with decorators as well. So stay tuned.

4reactions
sskorolcommented, May 26, 2020

@fescobar @tims-j is there any reason you can’t use es6 import syntax?

The problem here is in a combination of Mocha specifics and plain-old JS require syntax.

First of all, we have to use default export for reporter itself to be able to include it via -R option. On the other hand, we can’t make allure default as well, as allure-runtime makes 3 exports.

So what’s wrong with require syntax then? Nothing special, except the fact that when you destructure allure via require, it detaches it from the reporter context.

The problem here is that this variable’s value is populated in runtime, when AllureReport is initialized by Mocha. So when you detached it via require you couldn’t track any changes anymore. That’s why you got epic of undefined error. However, it would fail the same way for any other property as well.

You may wonder how to fix that? Either use es6 import syntax, which correctly handles destructuring without detaching object from its parent context, or operate with a root runtime object. But in the latter case you can access allure only within test.

import { allure } from "allure-mocha/runtime";

it('is a test', () => {
    allure.epic('Some info');
});

// or
const runtime = require('allure-mocha/runtime')

it('is a test', () => {
    runtime.allure.epic('Some info');
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'Base' of undefined error using mocha ...
I was able to use mocha-allure-reporter by simply installing it (along with mocha), npm install mocha mocha-allure-reporter.
Read more >
allure-framework/allure-core - Gitter
TypeError : Cannot read property 'createAttachment' of undefined and allure methods like createStep, attachment and other (critical); run in parallel (not ...
Read more >
allure-decorators - npm
This project introduces TS decorators integration for Allure framework. Installation based on allure-mocha reporter. npm i allure-js-commons allure-decorators ...
Read more >
typeerror can not read property x of null - YouTube
Join this channel to get access to perks:https://www.youtube.com/channel/UCoSpmr2KNOxjwE_B9ynUmig/joinMy GearCamera ...
Read more >
ANGULAR 13 TypeError Cannot read property of undefined
In this tutorial, we will see a most common error faced by the Angular developers named as " TypeError Cannot read property of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found