Skip to content

Commit

Permalink
Merge pull request #27 from mukilan/fix-NaN-scores-due-to-subtest-name
Browse files Browse the repository at this point in the history
Use `Object.hasOwn` to handle subtests with names like `toString`
  • Loading branch information
mukilan authored Jul 31, 2024
2 parents 5093f00 + 7fbfa98 commit d7a48a5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion process-wpt-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export function score_run (run, against_run, focus_areas_map) {
} else {
let test_score = 0
for (const subtest of subtest_names) {
if (run_test.subtests[subtest]) {
if (Object.hasOwn(run_test.subtests, subtest)) {
test_score += run_test.subtests[subtest].score
}
}
Expand Down
33 changes: 33 additions & 0 deletions test/process-wpt-results.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,39 @@ describe('Scoring', () => {
const score = score_run(run, run, { test1: ['all'] })
assert.equal(score.all, 333)
})
it('calculates scores correctly even subtest name collides with JS builtins', () => {
const run = {
test_scores: {
test1: {
score: 0,
subtests: {
}
},
test2: {
score: 1,
subtests: { }
}
}
}

const against_run = {
test_scores: {
test1: {
score: 1,
subtests: {
toString: { score: 1 }
}
},
test2: {
score: 1,
subtests: { }
}
}
}

const score = score_run(run, against_run, { test1: ['all'], test2: ['all'] })
assert.equal(score.all, 500)
})
it('calculates scores based only on tests in new runs', () => {
const old_run = {
test_scores: {
Expand Down

0 comments on commit d7a48a5

Please sign in to comment.