-
Notifications
You must be signed in to change notification settings - Fork 1.8k
test(crud): resync crud tests and update test runner #2005
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me! the description was very helpful :)
just 1 question about a ticket
expect(result).to.not.be.an('error'); | ||
} | ||
|
||
// TODO: when we fix our bulk write errors, get rid of this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a ticket for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just made the same comment above at the point of function definition 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought there was, b/c it's been a known issue for a while, but I can't seem to find one, so I made https://jira.mongodb.org/browse/NODE-1989
expect(result).to.not.be.an('error'); | ||
} | ||
|
||
// TODO: when we fix our bulk write errors, get rid of this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just made the same comment above at the point of function definition 😄
@@ -162,7 +206,7 @@ describe('CRUD spec', function() { | |||
.find({}) | |||
.toArray() | |||
.then(collectionResults => { | |||
expect(collectionResults).to.containSubset(outcome.result); | |||
expect(collectionResults).to.containSubset(outcome.collection.data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we still need to check this in v1, see this for example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are already asserting outcome.results
here. This line is not asserting the result of the function call, but rather the state of the collection after the operation has been performed. If we were to use the example you provided above, we would be asserting that the entire collection would equal 3
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh wow, yeah that's a bug. Do we need a more rigorous validator than containsSubset
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
containsSubset seems to default to equals
for non-objects, so I think we're fine.
test/functional/crud_spec_tests.js
Outdated
); | ||
const asserter = assertWriteExpectations(collection, scenarioTest.outcome); | ||
|
||
return collection[scenarioTest.operation.name](documents, options).then(asserter, asserter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This used to return a Promise with only a then
attached to it, allowing errors to propagate back up if something went wrong before the expectations were checked. Now you pass in the "asserter" to both resolve and reject, but don't pass in a method that checks for an error.
To me it seems like it would be easier to read this flow if we did something more like:
const promise = collection[scenarioTest.operation.name](documents, options);
if (scenario.hasError) {
promise.catch(doErrorChecks);
}
return promise.then(asserter);
Files to look at:
lib/bulk/common.js
: minor change to exposeBulkWriteError
for aninstanceof
check intest/functional/crud_spec_tests.js
test/functional/crud_spec_tests.js
: Updated it to run with some of the new features that were added intov1
beforev2
was created. Specifically:scenario.data
can be an empty array, which will result in an empty insert attempt / erroroutcome.collection.data
instead ofoutcome.results
bulkWrite
andinsertMany
), and added a transform function to massage ourBulkWriteError
into the shape it should be.Files to ignore: Any yml/json/rst files