Skip to content

Commit

Permalink
[encoderpatch] Patch TextEncoder/TextDecoder for tests (#2307)
Browse files Browse the repository at this point in the history
## Summary:
React 18 requires these things but JSDOM doesn't include them, so we shim them

Issue: XXX-XXXX

## Test plan:
`yarn test` before React 18 update and after.

Author: somewhatabstract

Reviewers: jeresig

Required Reviewers:

Approved By: jeresig

Checks: ✅ Chromatic - Get results on regular PRs (ubuntu-latest, 20.x), ✅ Test (ubuntu-latest, 20.x, 2/2), ✅ Test (ubuntu-latest, 20.x, 1/2), ✅ Lint (ubuntu-latest, 20.x), ✅ Check build sizes (ubuntu-latest, 20.x), ✅ Chromatic - Build on regular PRs / chromatic (ubuntu-latest, 20.x), ⏭️  Chromatic - Skip on Release PR (changesets), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ gerald, ⏭️  dependabot

Pull Request URL: #2307
  • Loading branch information
somewhatabstract authored Aug 29, 2024
1 parent 40493ba commit d8bb74e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions config/jest/test-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,26 @@ const {StyleSheetTestUtils} = require("aphrodite");
const {
mockRequestAnimationFrame,
} = require("../../utils/testing/mock-request-animation-frame");
const {TextEncoder, TextDecoder} = require("util");

StyleSheetTestUtils.suppressStyleInjection();


const attachShims = (targetWindow) => {
if (!targetWindow.TextEncoder) {
targetWindow.TextEncoder = TextEncoder;
}
if (!targetWindow.TextDecoder) {
targetWindow.TextDecoder = TextDecoder;
}
}

const resetWindow = () => {
attachShims(globalThis);
};
resetWindow();

beforeEach(() => {
resetWindow();
mockRequestAnimationFrame();
});

0 comments on commit d8bb74e

Please sign in to comment.