Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Data(function*() {
}).Scenario() // ...
```

*HINT: If you don't use DataTable. add `toString()` method to each object added to data set, so the data could be pretty printed in a test name*
Objects in a data set are serialized as JSON in the test name.


## Debug
Expand Down
10 changes: 4 additions & 6 deletions lib/data/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,11 @@ function replaceTitle(title, dataRow) {
return `${title} | ${dataRow.data.getMasked()}`
}

// if `dataRow` is object and has own `toString()` method,
// it should be printed
if (Object.prototype.toString.call(dataRow.data) === Object().toString() && dataRow.data.toString() !== Object().toString()) {
return `${title} | ${dataRow.data}`
}
return `${title} | ${JSON.stringify(dataRow.data, maskSecret)}`
}

return `${title} | ${JSON.stringify(dataRow.data)}`
function maskSecret(key, value) {
return typeof value?.getMasked === 'function' ? value.getMasked() : value
}

function isTableDataRow(row) {
Expand Down
12 changes: 9 additions & 3 deletions test/unit/data/ui_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ describe('ui', () => {
dataScenarioConfig.scenarios.forEach(scenario => expect(helper).to.equal(scenario.test.config[helperName]))
})

it("should shows object's toString() method in each scenario's name if the toString() method is overridden", () => {
const data = [{ toString: () => 'test case title' }]
it("should use JSON in each scenario's name if the object overrides toString()", () => {
const data = [{ name: 'John Do', toString: () => 'test case title' }]
const dataScenarioConfig = context.Data(data).Scenario('scenario', () => {})
expect('scenario | test case title').to.equal(dataScenarioConfig.scenarios[0].test.title)
expect('scenario | {"name":"John Do"}').to.equal(dataScenarioConfig.scenarios[0].test.title)
})

it("should shows JSON.stringify() in each scenario's name if the toString() method isn't overridden", () => {
Expand Down Expand Up @@ -128,5 +128,11 @@ describe('ui', () => {
const dataScenarioConfig = context.Data([new Secret('theSecretPassword')]).Scenario('scenario', () => {})
expect(dataScenarioConfig.scenarios[0].test.title).to.equal('scenario | *****')
})

it("should not leak a skipped secret object's value into the title", () => {
const data = Secret.secret({ username: 'jon', password: 'theSecretPassword' }, 'password')
context.xData([data]).Scenario('scenario')
expect(suite.tests.at(-1).title).to.equal('scenario | {"username":"jon","password":"*****"}')
})
})
})
Loading