Skip to content

[Bug]: Jest child process breaks Buffer instanceof Uint8Array #13349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
noCharger opened this issue Sep 30, 2022 · 5 comments
Closed

[Bug]: Jest child process breaks Buffer instanceof Uint8Array #13349

noCharger opened this issue Sep 30, 2022 · 5 comments

Comments

@noCharger
Copy link

noCharger commented Sep 30, 2022

Version

27.5.1

Steps to reproduce

  1. Clone my repo and bootstrap
git clone https://github.com/opensearch-project/OpenSearch-Dashboards.git
yarn osd bootstrap
  1. Create test file jest_debug.test.ts with simple test case
vi src/plugins/data_source/server/cryptography/jest_debug.test.ts

test('Debugging jest buffer behavior', () => {
    expect(Buffer.from("test")).toBeInstanceOf(Uint8Array);
});
  1. Execute test file jest_debug.test.ts together with others
% yarn test:jest src/plugins/data_source/server/cryptography
yarn run v1.22.19
$ node scripts/jest src/plugins/data_source/server/cryptography
 FAIL  src/plugins/data_source/server/cryptography/jest_debug.test.ts
  ● Debugging jest buffer behavior

    expect(received).toBeInstanceOf(expected)

    Expected constructor: Uint8Array
    Received constructor: Buffer

      1 | test('Debugging jest buffer behavior', () => {
    > 2 |     expect(Buffer.from("test")).toBeInstanceOf(Uint8Array);
        |                                 ^
      3 | });
      4 |

      at Object.<anonymous> (src/plugins/data_source/server/cryptography/jest_debug.test.ts:2:33)```
  1. Execute test file jest_debug.test.ts only
 % yarn test:jest src/plugins/data_source/server/cryptography/jest_debug.test.ts 
yarn run v1.22.19
$ node scripts/jest src/plugins/data_source/server/cryptography/jest_debug.test.ts
 PASS  src/plugins/data_source/server/cryptography/jest_debug.test.ts
  ✓ Debugging jest buffer behavior (3 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.727 s, estimated 2 s
Ran all test suites matching /src\/plugins\/data_source\/server\/cryptography\/jest_debug.test.ts/i.
✨  Done in 5.56s.

Expected behavior

#4422 (comment) This solution should work both single test suite on single node process, but multiple test suites with child processes.

Actual behavior

The global config mentioned #4422 (comment) doesn't apply to child processes when there are multiple test suites. Very appreciated anyone helps me out.

Additional context

  1. Closed Jest repo issue Jest breaks Buffer instanceof Uint8Array #4422
  2. Created issue from OSD repo [Test] local unit tests failed  opensearch-project/OpenSearch-Dashboards#2459
  3. Known issue from AWS Encryption SDK JavaScript instanceOf and different versions of the underlying Encryption SDK modules. aws/aws-encryption-sdk-javascript#126
  4. Jest config from OSD repo in src/dev/jest/config.js
  globals: {
    Uint8Array: Uint8Array,
  },

Environment

System:
    OS: macOS 12.6
    CPU: 2.6 GHz 6-Core Intel Core i7
  Binaries:
    Node: 14.20.0 - ~/.nvm/versions/node/v14.20.0/bin/node
    Yarn: 1.21.1 - ~/.yarn/bin/yarn
    npm: 6.14.17 - ~/.nvm/versions/node/v14.20.0/bin/npm
  npmPackages:
    jest: ^27.5.1
    "@types/jest": "^27.4.0",
    "babel-jest": "^27.5.1",
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Oct 30, 2022
@sergekh2
Copy link

sergekh2 commented Nov 1, 2022

There is one more repro with jest 29.2.2/node 18:

https://github.com/sergekh2/jest-buffer-test-fail/

It passes in node env, but fails in jsdom.

Judging by open/closed bugs, it seems like this issue is present in one form or another since jest 26.

@github-actions github-actions bot removed the Stale label Nov 1, 2022
@github-actions
Copy link

github-actions bot commented Dec 1, 2022

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Dec 1, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 31, 2022
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants