adamgruber / mochawesome

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

[BUG] Test code appears with changes in report #186

Closed APshenkin closed 7 years ago

APshenkin commented 7 years ago

Hi!

In my test there is test code like this:

function* (I, test) {
    let resp = yield* test.sendRequest();
    I.assertStatusCode(resp.statusCode, 200);
    let orderId = resp.body.orderId;
    I.waitSpecifiedOrderState(bearerToken, orderId, (order) => order.status == 'working')
    I.pauseOrder(bearerToken, {orderId: [orderId]})
    I.waitResponses()
    I.seeWsResponseHasValidJsonSchema('pausePassed.json');
    I.sendOrderRequest(bearerToken, orderId)
    I.waitSpecifiedOrderState(bearerToken, orderId, (order) => order.category == "paused" && order.operation != 'pausing', 10000)
}

but in HTML report it displays so:

function* (I, test) {
    let resp = yield* test.sendRequest;
    I.assertStatusCode(resp.statusCode, 200);
    let orderId = resp.body.orderId;
    I.waitSpecifiedOrderStateorder.status == 'working')
    I.pauseOrder(bearerToken, {orderId: [orderId]})
    I.waitResponses()
    I.seeWsResponseHasValidJsonSchema('pausePassed.json');
    I.sendOrderRequest(bearerToken, orderId)
    I.waitSpecifiedOrderState(bearerToken, orderId, (order) => order.category == "paused" && order.operation != 'pausing', 10000)

As you can see I.waitSpecifiedOrderState(bearerToken, orderId, (order) => order.status == 'working') Changes to I.waitSpecifiedOrderStateorder.status == 'working')

Looks like these changes appears after cleanCode function https://github.com/adamgruber/mochawesome/blob/master/src/utils.js#L67

APshenkin commented 7 years ago

This appears because of this replacement: .replace(/^function\s*\(.*\)\s*{|\(.*\)\s*=>\s*{?/, '')

APshenkin commented 7 years ago

Looks like this issue is only with generator function. I update this regex to ^function(\*?)\s*\(.*\)\s*{|\(.*\)\s*=>\s*{? and now it works

adamgruber commented 7 years ago

Fix included in v2.3.1