mirror of
https://github.com/nodejs/node.git
synced 2025-12-28 07:50:41 +00:00
Tests should be explicit regarding whether a promise is expected to settle, and the test should fail when the behavior does not meet expectations. PR-URL: https://github.com/nodejs/node/pull/60976 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Erick Wendel <erick.workspace@gmail.com>
40 lines
702 B
JavaScript
40 lines
702 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
const {
|
|
PerformanceObserver,
|
|
performance: {
|
|
timerify,
|
|
},
|
|
} = require('perf_hooks');
|
|
|
|
const assert = require('assert');
|
|
|
|
const {
|
|
setTimeout: sleep
|
|
} = require('timers/promises');
|
|
|
|
let check = false;
|
|
|
|
async function doIt() {
|
|
await sleep(100);
|
|
check = true;
|
|
return check;
|
|
}
|
|
|
|
const obs = new PerformanceObserver(common.mustCall((list) => {
|
|
const entry = list.getEntries()[0];
|
|
assert.strictEqual(entry.name, 'doIt');
|
|
assert(check);
|
|
obs.disconnect();
|
|
}));
|
|
|
|
obs.observe({ type: 'function' });
|
|
|
|
const timerified = timerify(doIt);
|
|
|
|
const res = timerified();
|
|
assert(res instanceof Promise);
|
|
res.then(assert).then(common.mustCall());
|