Files
pybricks-code/test/env.js
dependabot[bot]GitHubdependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>David Lechner
09c07affa3 build(deps): bump jest and @types/jest (#835)
* build(deps): bump jest and @types/jest

Bumps [jest](https://github.com/facebook/jest/tree/HEAD/packages/jest) and [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest). These dependencies needed to be updated together.

Updates `jest` from 27.5.1 to 28.1.0
- [Release notes](https://github.com/facebook/jest/releases)
- [Changelog](https://github.com/facebook/jest/blob/main/CHANGELOG.md)
- [Commits](https://github.com/facebook/jest/commits/v28.1.0/packages/jest)

Updates `@types/jest` from 27.4.1 to 28.1.0
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest)

---
updated-dependencies:
- dependency-name: jest
  dependency-type: direct:production
  update-type: version-update:semver-major
- dependency-name: "@types/jest"
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix breaking changes in jest 28

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: David Lechner <david@pybricks.com>
2022-06-02 18:53:21 +00:00

29 lines
937 B
JavaScript

const JSDomEnvironment = require('jest-environment-jsdom').default;
const { TextEncoder, TextDecoder } = require('util')
/**
* A custom environment to set TextEncoder/TextDecoder
* Thanks https://stackoverflow.com/a/57713960/1976323
*/
module.exports = class CustomTestEnvironment extends JSDomEnvironment {
async setup() {
await super.setup();
if (this.global.TextEncoder === undefined) {
this.global.TextEncoder = TextEncoder;
}
if (this.global.TextDecoder === undefined) {
this.global.TextDecoder = TextDecoder;
}
// work around https://github.com/facebook/jest/issues/7780
this.global.Uint8Array = Uint8Array;
this.global.ArrayBuffer = ArrayBuffer;
}
exportConditions() {
// JSDomEnvironment returns ['browser'] but tests run in node which
// has issues with some ESM modules.
return ['node'];
}
};