adamgruber / mochawesome

A Gorgeous HTML/CSS Reporter for Mocha.js
https://gitter.im/mochawesome/general
MIT License
1.06k stars 160 forks source link

addContext is not working #264

Closed KSinichkina closed 5 years ago

KSinichkina commented 5 years ago

Describe the bug So in any way I'm using addContext there is no any result

Screenshots screen shot 2019-01-11 at 1 27 52 pm

Environment (please complete the following information):

Additional context Running cypress run:

cypress.json

{
  "reporter": "mochawesome",
  "reporterOptions": {
    "reportDir": "mochawesome-reports",
    "overwrite": true
  },
  "viewportWidth": 1050,
  "viewportHeight": 938,
  "defaultCommandTimeout": 7000,
  "requestTimeout": 7000,
  "waitForAnimations": true
}
adamgruber commented 5 years ago

Thanks for the info. Can you show me how your test is defined? Make sure you are not using an arrow function as the test callback. See the note about adding context.

KSinichkina commented 5 years ago

@adamgruber so my code in a test is s sample from the link you shared: ` const addContext = require('mochawesome/addContext'); describe('test suite', function () { it('should add context', function () { // context can be a simple string addContext(this, 'simple string');

    // context can be a url and the report will create a link
    addContext(this, 'http://www.url.com/pathname');

    // context can be an image url and the report will show it inline
    addContext(this, 'http://www.url.com/screenshot-maybe.jpg');

    // context can be an object with title and value properties
    addContext(this, {
        title: 'expected output',
        value: {
            a: 1,
            b: '2',
            c: 'd'
        }
    });
})

}); `

adamgruber commented 5 years ago

From what I can tell, the addContext function is working but there's something with Cypress that is modifying the test object so the context property is not there. You might want to open an issue with Cypress.

KSinichkina commented 5 years ago

thank you @adamgruber think need to talk to cypress guys))

HamzaQA commented 4 years ago

Hi there,

I am adding addContext in my testfile but getting following error:

Could not find a declaration file for module 'mochawesome/addContext'. 'd:/Cypress/CypressProject/node_modules/mochawesome/addContext.js' implicitly has an 'any' type. Try npm install @types/mochawesome if it exists or add a new declaration (.d.ts) file containing `declare module 'mochawesome/addContext';

I wrote this line of code where I am getting above error const addContext = require('mochawesome/addContext')

Somebody can help please?

michael-siek commented 4 years ago

Hi there,

I am adding addContext in my testfile but getting following error:

Could not find a declaration file for module 'mochawesome/addContext'. 'd:/Cypress/CypressProject/node_modules/mochawesome/addContext.js' implicitly has an 'any' type. Try npm install @types/mochawesome if it exists or add a new declaration (.d.ts) file containing `declare module 'mochawesome/addContext';

I wrote this line of code where I am getting above error const addContext = require('mochawesome/addContext')

Somebody can help please?

If you are writing typescript you can make noImplicitAny: false in your tsconfig.json file or you can create a declaration file (make sure to include this in your tsconfig file)

// src/@types/mochawesome.d.ts
declare module 'mochawesome/addContext';
Serg-develop commented 3 years ago

Hi guys. I have no possibility to add some context through parallel mode. So, i have the function like:

_`afterEach: async function() { if (this.currentTest.state === "failed") { FAILED_TESTS[this.currentTest.file] = true;

  const title = new Buffer.from(this.currentTest.title).toString("base64");

  try {
    await makeScreenshot(title);
  } catch (e) {
    console.error(e);
  }

  addContext(this, `./${title}.png`);
}

}`_

It works in single mode, but in parallel - no. Report generates without any context. Maybe someone knows any solution?