-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
node:test
should be able to detect a plan has not been met
#56758
Comments
If nobody beats me to it, I'll try to check it out ASAP |
@jsumners, would you be able to provide a minimum repro? I'd then add it directly to our tests |
@pmarchini go for it. I think the only tricky part is:
Tests do not have a default timeout (we received push back over having a default test timeout when originally creating the test runner), so unmet plans would hang indefinitely when they currently do not. The simplest way to implement it without breaking anyone might be by adding a Some other implementation notes (at least how I see it in my head):
|
'use strict'
const test = require('node:test')
const assert = require('node:assert')
const http = require('node:http')
const server = http.createServer((req, res) => {
res.writeHead(200, { 'content-type': 'application/json' })
res.end(JSON.stringify({ data: 'ok' }))
})
server.listen(0, '127.0.0.1', (listenError) => {
assert.ifError(listenError)
test.after(() => {
server.close()
})
test('with a plan', t => {
t.plan(2)
doRequest(payload => {
t.assert.deepStrictEqual(payload, { data: 'ok' })
})
doRequest(payload => {
t.assert.deepStrictEqual(payload, { data: 'ok' })
})
})
test('should pass', async t => {
t.plan(2)
await new Promise(resolve => {
doRequest(payload => {
t.assert.deepStrictEqual(payload, { data: 'ok' })
resolve()
})
})
await new Promise(resolve => {
doRequest(payload => {
t.assert.deepStrictEqual(payload, { data: 'ok' })
resolve()
})
})
})
})
function doRequest(cb) {
const req = http.request(
{
host: '127.0.0.1', // server.address().address,
port: server.address().port
},
res => {
let data = ''
res.on('data', d => { data += d.toString() })
res.on('end', () => cb(JSON.parse(data)))
}
)
req.end()
} |
I hope we can define a default value, say |
It doesn't seem like it's a very common option that needs to be on by default? My understanding is that Fastify has been using this feature for a while and this is the first time it has come up. My two cents is that even if it does get a default value of |
Most of Fastify's tests that rely on a plan are synchronous and thus do not encounter this issue. It was very surprising to find that the plan is synchronous only. |
This issue stems from the conversation at fastify/fastify#5957 (review)
Given a test like:
The test should wait until the defined timeout for both asserts to resolve. If only one resolves within the time limit, the test should fail due to the plan not being completed. From the linked conversation, this is not happening.
The text was updated successfully, but these errors were encountered: