node/test/async-hooks/test-async-local-storage-promises.js
Antoine du Hamel e50cbc1abd
test: enforce better never-settling-promise detection
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>
2025-12-10 23:55:36 +00:00

24 lines
705 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const { AsyncLocalStorage } = require('async_hooks');
async function main() {
const asyncLocalStorage = new AsyncLocalStorage();
const err = new Error();
const next = () => Promise.resolve()
.then(() => {
assert.strictEqual(asyncLocalStorage.getStore().get('a'), 1);
throw err;
});
await assert.rejects(new Promise((resolve) => {
asyncLocalStorage.run(new Map(), () => {
const store = asyncLocalStorage.getStore();
store.set('a', 1);
resolve(next());
});
}), err);
assert.strictEqual(asyncLocalStorage.getStore(), undefined);
}
main().then(common.mustCall());