codesandbox / codesandbox/codesandbox-client
fs.readFileSync() causes tests to hang
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 13.6k
- Forks
- 2.4k
- Avg merge
- 6d 19h
- Merged PRs (30d)
- 2
Description
🐛 bug report
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project
adheres to. - I have searched the issue tracker for an issue that matches the one I want
to file, without success.
Description of the problem
Cannot use fs.readFileSync() in tests
How has this issue affected you? What are you trying to accomplish?
I would like to write unit tests for a Vanilla Javascript project. To do that I need to read the index.html file into my test file.
To Reproduce
import fs from "fs";
const html = fs.readFileSync("index.html", "utf-8");
In src/index.tests.js causes the tests to hang. In src/index.js it works just fine.
Link to sandbox: link
Your Environment
| Software | Name/Version |
|---|---|
| Сodesandbox | Browser |
| Browser | Chrome Version 114.0.5735.198 (Official Build) (arm64) |
| Operating System | macOs Ventura 13.4.1 |
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the hang from src/index.tests.js using the linked CodeSandbox, then compare it with the working use in src/index.js. Trace how fs.readFileSync() is handled in the test environment and determine whether the test should complete while reading index.html; verify the result by rerunning the affected test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100