Skip to content
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

[Bug]: Jest cannot run tests in Sapling repos with invalid JSON backups #13673

Closed
vegerot opened this issue Dec 13, 2022 · 6 comments · Fixed by #13674
Closed

[Bug]: Jest cannot run tests in Sapling repos with invalid JSON backups #13673

vegerot opened this issue Dec 13, 2022 · 6 comments · Fixed by #13674

Comments

@vegerot
Copy link
Contributor

vegerot commented Dec 13, 2022

Version

41bf230 (main)

Steps to reproduce

sl clone git@github.com:facebook/jest.git # or git clone git@github.com:facebook/jest.git
cd jest
yarn
cd examples/getting-started
yarn
mkdir -pv .sl/origbackups/
echo "aoeu}{" > .sl/origbackups/package.json
node ../../packages/jest-cli/bin/jest.js

Expected behavior

expected: tests pass successfully

Actual behavior

actual:

❯ node ../../packages/jest-cli/bin/jest.js                                                                           ─╯
Error: Cannot parse /Users/m0c0j7y/workspace/github.com/facebook/jest/examples/getting-started/.sl/origbackups/package.json as JSON: Unexpected token 'a', "aoeu}{
" is not valid JSON
    at Object.worker (/Users/m0c0j7y/workspace/github.com/facebook/jest/packages/jest-haste-map/build/worker.js:128:13)
    at execFunction (/Users/m0c0j7y/workspace/github.com/facebook/jest/packages/jest-worker/build/workers/processChild.js:130:17)
    at execHelper (/Users/m0c0j7y/workspace/github.com/facebook/jest/packages/jest-worker/build/workers/processChild.js:
118:5)
    at execMethod (/Users/m0c0j7y/workspace/github.com/facebook/jest/packages/jest-worker/build/workers/processChild.js:121:5)
    at process.messageListener (/Users/m0c0j7y/workspace/github.com/facebook/jest/packages/jest-worker/build/workers/processChild.js:44:7)
    at process.emit (node:events:513:28)
    at emit (node:internal/child_process:944:14)
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21)

Additional context

I have tested this on multiple versions of jest

Environment

❯ npx envinfo --preset jest                                                                                          ─╯

  System:
    OS: macOS 12.6.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
  Binaries:
    Node: 19.2.0 - /usr/local/bin/node
    Yarn: 3.3.0 - /usr/local/bin/yarn
    npm: 9.2.0 - /usr/local/bin/npm
@vegerot
Copy link
Contributor Author

vegerot commented Dec 13, 2022

FYI this bug would probably also happen if you did

mkdir .aoeu
echo yourmom > .aoeu/package.json

but I encountered this with Sapling.

I should probably update the Issue title to be more general

@vegerot
Copy link
Contributor Author

vegerot commented Dec 13, 2022

workaround: deleting the corrupted package.json

vegerot added a commit to vegerot/jest that referenced this issue Dec 21, 2022
Summary: Ignore `.sl` directories in HasteMap.  This will allow Sapling to be
used with jest projects

Test Plan: `packages/jest-haste-map/src/__tests__/index.test.js` similar
testing plan to what's in jestjs#13673

Closes jestjs#13673
@vegerot
Copy link
Contributor Author

vegerot commented Jan 3, 2023

@SimenB Do you think it's a bug that an invalid JSON file name package.json anywhere in your project will cause any Jest test to fail?

If I'm working on a JSON validator and I have a few test files that are invalid I could not use Jest

It's worth thinking about better workarounds than deleting those files

@SimenB
Copy link
Member

SimenB commented Jan 6, 2023

adding the invalid files to an ignore pattern seems fine if you want them?

@SimenB
Copy link
Member

SimenB commented Jan 24, 2023

https://github.com/facebook/jest/releases/tag/v29.4.0

@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 Feb 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants