I'm trying to setup plugin and I stumbled upon a problem with test framework mocha.
My goal is to get name of the test, in which library instance currently executes method run without passing this into each method call.
Library is instantiated at the top suite with passed suite instance this. Problem is that this in parent suite contains array of suites and tests, but no information about currently executed test.
const { SuperfaceTest } = require('@superfaceai/testing');
const chai = require('chai');
const { jestSnapshotPlugin } = require('mocha-chai-jest-snapshot');
chai.use(jestSnapshotPlugin());
const expect = chai.expect;
describe('usecases', function () {
const superfaceTest = new SuperfaceTest({ testInstance: this });
describe('starwars', function () {
it('character info luke', async function () {
const input = {
characterName: 'Luke Skywalker',
};
expect(
await superfaceTest.run({
profile: 'starwars/character-information',
provider: 'swapi',
useCase: 'RetrieveCharacterInformation',
input,
})
).toMatchSnapshot();
});
});
});
I'm trying to figure out a way to recognize current executing test just from instance of top suite.
Is there some property that I've missed, that could indicate currently executed test? Or is there some other way how to get current test in mocha from outside that test?