-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Switch to a new testing system #703
Comments
feature matrixes don't work for software, as apple so well demonstrates. what sucks about current tests? |
I'm skeptical of stuff like this because the ecosystem will be completely different in a few months. Though I won't stop anyone who wants to refactor things all day :D |
For one thing, you can't easily detect that there isn't a header (that's the lack of "Response Testing Covers Common Use Cases" column). Also in rare situations it would be useful to have a .then to assert something set elsewhere rather than a custom end method. Another thing is that as tests grow speed matters more, and with how split up tests are multiple processes for multiple files will be very important. Lastly, if we do switch our request library to something without builtin request testing, having async/await will be very nice (builtin babel will be required as that isn't in the near future for node). |
I'm not sure it will change that much, given that libraries take time to accumulate popularity. Also, if we find a toolset that works well for the job, there's little reason to change. |
I think that in the case of these libraries, they make sense. If you have anything to add that doesn't fit in the table, I can make a note. |
In mocha
should be written as
with the helper function shouldNotHaveHeader(header) {
return function (res) {
assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header)
}
} |
@dougwilson Makes sense, I've added a note about that. |
This change feels larger than it probably is, but I'd keep things as they are until v3 and to further analyse tools when ecosystem stabilises post native v8 async/await. |
For scale, IIRC it took me 1.5 hours to change supertest to assert-request. Changing the testing framework as well would be much larger. |
@fl0w 👍 i've been writing my latest tests w/ async functions using babel and it's been a lot easier it('should do something', async () => {
const response = await request('http://...')
assert.equal(200, response.status)
}) i think it's worth waiting until then |
another note: i HATE using |
@jonathanong +1 on stopping using should, I think that es6 array functions covers pretty much everything it's needed for. What request library are you using with async/await? Also, ava has builtin babel support but IDK if that would slow things down. It also can test files simultaneously, which might result in a speed up. |
Take a look at thenables/requisition :) |
@coderhaoxin Looks neat. I've added it to the table. Comments from skimming through it:
|
@jonathanong How do you choose to transpile your tests? Babel require hook inside each test? node -r? |
have an entry point like the following: // test/index.js
require('babel-register') // or whatever entry point it is now
require('./test1')
require('./test2') then run it like: mocha test/index.js |
the only issue i have with |
@jonathanong Slightly off-topic, but I wrote and use https://github.com/blakeembrey/popsicle with https://github.com/blakeembrey/popsicle-server to replicate the basic behaviour of |
Once Node v7 comes along with async/await support, will we still be testing Koa v2 on earlier versions? |
@jonathanong you can hack around with import Test from 'supertest/lib/test';
const {end} = Test.prototype;
Test.prototype.end = function(cb) {
const self = this;
if (isFunction(cb)) {
return end.call(self, cb);
}
return new Promise((res, rej) => {
end.call(self, (err) => {
if (err) return rej(err);
res();
});
});
}; then it('should run a basic route', async () => {
await agent.get('/')
.expect(200)
.end();
}); |
@dtothefp It still has the problem of |
yes,i write 64 tests in two days using ava+supertest-as-promised, port express-graphql to koa v2... |
Already landed in https://github.com/trekjs/engine/tree/master/test. Need a PR? |
I'm always surprised by how many forks Koa has inspired. I think we'll just rewrite our tests in async once it lands in all supported versions of Node. |
maybe consider jest. lol. looked better than ava to me at a glance. |
Jest looks like the best I've seen so far. |
@PlasmaPower alright, I'll hold off then. Let me know if you need/want to off load. README also updated to 7.6 only support so I would assume using async-await to be fine? |
@fl0w it says that only for using async/await though. |
Actually I guess I misread it. I thought it required a new node if you want async/await, but I think in reality it requires a new node so it has async/await. |
For the request library, I think we should use |
@PlasmaPower considering 0c2d881 I would assume it's ok! :) |
I've setup the basis for network tests this way: https://gist.github.com/PlasmaPower/57d361a6d0a90c7a5a6aac890cd2322d Look good? |
yes, we dropped babel from tests and only support node v7.6+ to make life easier! feel free to use async functions in tests |
there should be minimal changes in tests though. only moving around test files to make them jest-like and |
One problem I'm having is jest seems to break |
I fixed that with a custom |
I haven't really experienced jest breaking anything. Have you tried setting the environment to node? |
I'm assuming you meant setting the node environment to test, but jest does that automatically. The problem I'm currently encountering is that this assertion fails for this test. I have no idea why, the error is quite odd:
I'll do some more investigation into that error object. |
More information: process.stderr.write(err + '\n');
process.stderr.write((typeof err) + '\n');
process.stderr.write(err.constructor + '\n');
process.stderr.write(Error + '\n');
process.stderr.write((err instanceof Error) + '\n'); gives
Very odd. JS objects are confusing. I'm also not sure why Jest causes this, it doesn't seem to be messing with the |
@PlasmaPower I think jonathanong was referring to set jest to omit mocking a browser environment by having following in {
"jest": {
"testEnvironment": "node"
}
} |
@fl0w Oh, I didn't know jest did that. I'll try changing that and see if it does anything. |
The error type problem is still maintained, but I'll keep it in the config of course. |
I've pushed my work to this branch if anyone's interested: https://github.com/PlasmaPower/koa/tree/jest-tests |
I'm getting more and more wary of jest. Its breaking stuff knows no bounds. The basic problem is that Node's native libraries (
|
See also: node-fetch/node-fetch#220 |
Why are you switching from |
keep |
IDK, I'd prefer to do it all at once. There's little point in async/await without node-fetch. Switching to |
Frameworks
Request Libraries
Notes
(current)
indicates that Koa currently uses it.If anybody has any more columns or rows to add to either table, please leave a comment.
The text was updated successfully, but these errors were encountered: