Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

actual is being emptied after verifySteps(..) is called #1266

Closed
getify opened this issue Feb 22, 2018 · 1 comment · Fixed by #1267
Closed

actual is being emptied after verifySteps(..) is called #1266

getify opened this issue Feb 22, 2018 · 1 comment · Fixed by #1267
Labels
Component: Assert Type: Bug Something isn't working right.

Comments

@getify
Copy link

getify commented Feb 22, 2018

Tell us about your runtime:

  • QUnit version: 2.5.0
  • What environment are you running QUnit in? (e.g., browser, Node): Node
  • How are you running QUnit? (e.g., script, testem, Grunt): via qunit node package/API

Node 9.3.0

The bug I'm experiencing is that the actual array for a log(..) call from a verifySteps(..) is subsequently emptied out before the final testDone(..) is called. That means I can't correctly output the test results for expected vs actual whenever verifySteps(..) fails.

Here's some code to illustrate:

var all_logs = {};

QUnit.log(function(details){
   if (details.message == "check my steps") {
      all_logs[details.message] = details;
      console.log(JSON.stringify(details));
   }
});

QUnit.testDone(function(results){
   var details = all_logs[results.assertions[0].message];
   console.log(JSON.stringify(details));
});

// ***********

QUnit.test( "my test", function test(assert){
   assert.step("step one");
   assert.step("step two");

   assert.verifySteps(["step one","step two","step 3"],"check my steps");
});

QUnit.start();

The console output looks like:

{"module":"","name":"my test","result":false,"message":"check my steps","actual":["step one","step two"],"testId":"b31bbaea","negative":false,"runtime":2,"todo":false,"expected":["step one","step two","step 3"],"source":"    at Assert.verifySteps (/tmp/node_modules/qunit/qunit/qunit.js:2158:11)"}

{"module":"","name":"my test","result":false,"message":"check my steps","actual":[],"testId":"b31bbaea","negative":false,"runtime":2,"todo":false,"expected":["step one","step two","step 3"],"source":"    at Assert.verifySteps (/tmp/node_modules/qunit/qunit/qunit.js:2158:11)"}

Notice how the first output has the actual array filled in, but the second output, from the same shared object but accessed from within testDone(..), has actual as an empty array.

I strongly suspect that what's happening is that when verifySteps(..) calls log(..), it passes a reference to its own internal step(..) queue as actual, and then it empties that queue array at the end of verifySteps(..). Instead, shouldn't a copy of that array be sent, so that when your internal queue is emptied, it doesn't affect my storage of the log details.

I'm temporarily fixing this bug by doing JSON.parse(JSON.stringify(details)) to JSON-clone the log details object so that I can't be affected by your internal queue reset. But I'd expect to just be able to store the details object as-is and not have it later be modified at-a-distance unexpectedly by qunit.

@trentmwillis
Copy link
Member

Thanks for the report! Definitely a bug and definitely due to passing around the same reference. See these lines:

qunit/src/assert.js

Lines 39 to 40 in 7e7bb7e

this.deepEqual( this.test.steps, steps, message );
this.test.steps.length = 0;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Assert Type: Bug Something isn't working right.
Development

Successfully merging a pull request may close this issue.

2 participants