Issue 243 Text Encoder Dependency Removal Design

Goal: Remove the deprecated @sinonjs/text-encoding dependency from fake XHR response handling without changing observable behavior for supported runtimes.

Context

Issue #243 was opened when the project still depended on an older jsdom version and a deprecated text-encoding polyfill. The current branch already uses jsdom@28, so the remaining work is narrower than the original issue title suggests: lib/fake-xhr/index.js still imports @sinonjs/text-encoding only to turn response strings into UTF-8 bytes for arraybuffer and blob responses.

The issue comments also point out that the current usage is conceptually wrong: TextEncoder is UTF-8 only, but the code passes an encoding argument as if alternate encodings were supported. In practice, the implementation already behaves as UTF-8-only, so the correct fix is to make that explicit and remove the dead abstraction.

Chosen Approach

Use the smallest dependency-free fix:

  • replace the GlobalTextEncoder fallback with a small local helper that converts a JavaScript string to a UTF-8 ArrayBuffer;
  • keep convertToArrayBuffer as the single production call site for this conversion;
  • preserve existing behavior for string, ArrayBuffer, and Blob response handling;
  • update tests so expected byte sequences no longer depend on the deprecated polyfill;
  • remove @sinonjs/text-encoding from package metadata and generated artifacts.

This keeps the production change local, removes an unmaintained dependency, and avoids adding @exodus/bytes for a single UTF-8 conversion path.

Architecture

The response conversion flow should remain centered in lib/fake-xhr/index.js:

  • convertToArrayBuffer(body) should return body unchanged when it is already an ArrayBuffer;
  • string input should flow through a new helper that encodes to UTF-8 bytes and returns a detached ArrayBuffer;
  • blob response creation should continue to build from the same UTF-8 bytes, so arraybuffer and blob stay behaviorally aligned.

The helper should be intentionally narrow. It should not claim to support arbitrary encodings, and it should not introduce a general-purpose text codec abstraction.

Testing

Update lib/fake-xhr/index.test.js to pin the intended UTF-8 behavior:

  • responseType = "arraybuffer" returns UTF-8 bytes for ASCII strings;
  • responseType = "arraybuffer" returns UTF-8 bytes for non-ASCII strings such as "\xFF";
  • existing binary ArrayBuffer responses still pass through unchanged;
  • expected buffers are created without @sinonjs/text-encoding, using explicit byte arrays or a local test helper.

Package-level verification should also confirm that:

Out of Scope

  • adding TextDecoder support;
  • implementing non-UTF-8 encodings;
  • broader fake XHR compatibility changes unrelated to the deprecated text-encoding dependency;
  • unrelated dependency upgrades or lockfile churn.