Skip to content

await-using tests: add microtask-boundary ordering assertions for null/undefined skipped resources #294

@coderabbitai

Description

@coderabbitai

Summary

Add microtask-boundary ordering assertions to the await using null and await using undefined test cases in tests/language/explicit-resource-management/await-using.js to verify that the runtime still introduces an async yield point at block exit even when the disposable resource is skipped.

Why

The current tests only verify that skipped null/undefined values do not throw and that surrounding code continues to run. They do not catch a regression where the compiler/evaluator drops the block-exit await point for skipped disposables, since no ordering assertion against the microtask queue is made.

Current behavior

test("await using null is silently skipped", async () => {
  let reached = false;
  {
    await using resource = null;
    reached = true;
  }
  expect(reached).toBe(true);
});

The test passes but does not verify the presence of the async boundary.

Expected behavior

The tests should use a microtask-ordering pattern to assert the block-exit await point is present even for skipped (null/undefined) resources:

test("await using null is silently skipped", async () => {
  const order = [];
  const task = (async () => {
    {
      await using resource = null;
    }
    order.push("after");
  })();

  expect(order).toEqual([]);
  await Promise.resolve();
  await task;
  expect(order).toEqual(["after"]);
});

Mirror the same pattern for the undefined case.

Scope notes

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions