Skip to content

Commit

Permalink
Test: Tolerate additional properties on Assertion event data
Browse files Browse the repository at this point in the history
This was already in the spec, but the test was extra strict,
which would have caused other compliant implementations to
fail our test.

Also add a test for the names of tests and suites before we compare
arbitrary offsets in the result arrays. This makes off-by-one
failures less confusing to debug.

Ref #105.
  • Loading branch information
Krinkle committed Sep 24, 2020
1 parent 7aa817d commit 32a9e85
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
46 changes: 34 additions & 12 deletions test/integration/adapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,16 @@ function normalizeTestEnd (test) {
// Throw away the rest of the actual assertion objects as being framework-specific.
if (test.assertions) {
test.assertions.forEach(assertion => {
assertion.actual = undefined;
assertion.expected = undefined;
assertion.message = undefined;
assertion.stack = undefined;
Object.keys(assertion).forEach(key => {
if (key !== 'passed') delete assertion[key];
});
});
}
if (test.errors) {
test.errors.forEach(assertion => {
assertion.actual = undefined;
assertion.expected = undefined;
assertion.message = undefined;
assertion.stack = undefined;
Object.keys(assertion).forEach(key => {
if (key !== 'passed') delete assertion[key];
});
});
}
}
Expand Down Expand Up @@ -129,7 +127,13 @@ QUnit.module('Adapters integration', function () {

test('Event "testStart" data', assert => {
const actuals = collectedData.filter(pair => pair[0] === 'testStart');
expectedData.filter(pair => pair[0] === 'testStart').forEach((expected, i) => {
const expecteds = expectedData.filter(pair => pair[0] === 'testStart');
assert.propEqual(
actuals.map(expected => expected[1].name),
expecteds.map(pair => pair[1].name),
'Test names'
);
expecteds.forEach((expected, i) => {
assert.propEqual(
actuals[i][1],
expected[1],
Expand All @@ -140,7 +144,13 @@ QUnit.module('Adapters integration', function () {

test('Event "testEnd" data', assert => {
const actuals = collectedData.filter(pair => pair[0] === 'testEnd');
expectedData.filter(pair => pair[0] === 'testEnd').forEach((expected, i) => {
const expecteds = expectedData.filter(pair => pair[0] === 'testEnd');
assert.propEqual(
actuals.map(expected => expected[1].name),
expecteds.map(pair => pair[1].name),
'Test names'
);
expecteds.forEach((expected, i) => {
assert.propEqual(
actuals[i][1],
expected[1],
Expand All @@ -151,7 +161,13 @@ QUnit.module('Adapters integration', function () {

test('Event "suiteStart" data', assert => {
const actuals = collectedData.filter(pair => pair[0] === 'suiteStart');
expectedData.filter(pair => pair[0] === 'suiteStart').forEach((expected, i) => {
const expecteds = expectedData.filter(pair => pair[0] === 'suiteStart');
assert.propEqual(
actuals.map(expected => expected[1].name),
expecteds.map(pair => pair[1].name),
'Suite names'
);
expecteds.forEach((expected, i) => {
assert.propEqual(
actuals[i][1],
expected[1],
Expand All @@ -162,7 +178,13 @@ QUnit.module('Adapters integration', function () {

test('Event "suiteEnd" data', assert => {
const actuals = collectedData.filter(pair => pair[0] === 'suiteEnd');
expectedData.filter(pair => pair[0] === 'suiteEnd').forEach((expected, i) => {
const expecteds = expectedData.filter(pair => pair[0] === 'suiteEnd');
assert.propEqual(
actuals.map(expected => expected[1].name),
expecteds.map(pair => pair[1].name),
'Suite names'
);
expecteds.filter(pair => pair[0] === 'suiteEnd').forEach((expected, i) => {
assert.propEqual(
actuals[i][1],
expected[1],
Expand Down
14 changes: 2 additions & 12 deletions test/integration/reference-data.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
const failedAssertion = {
passed: false,
actual: undefined,
expected: undefined,
message: undefined,
stack: undefined,
todo: undefined
passed: false
};

const passedAssertion = {
passed: true,
actual: undefined,
expected: undefined,
message: undefined,
stack: undefined,
todo: undefined
passed: true
};

const globalTestStart = {
Expand Down

0 comments on commit 32a9e85

Please sign in to comment.