Title: test_runner: support mock file system · Issue #55902 · nodejs/node · GitHub
Open Graph Title: test_runner: support mock file system · Issue #55902 · nodejs/node
X Title: test_runner: support mock file system · Issue #55902 · nodejs/node
Description: What is the problem this feature will solve? The current test requires writing files to a real disk when reading and writing files related to the file system, which is very unsafe. After all, the file may remain due to test case failure ...
Open Graph Description: What is the problem this feature will solve? The current test requires writing files to a real disk when reading and writing files related to the file system, which is very unsafe. After all, the f...
X Description: What is the problem this feature will solve? The current test requires writing files to a real disk when reading and writing files related to the file system, which is very unsafe. After all, the f...
Opengraph URL: https://github.com/nodejs/node/issues/55902
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"test_runner: support mock file system","articleBody":"### What is the problem this feature will solve?\n\nThe current test requires writing files to a real disk when reading and writing files related to the file system, which is very unsafe.\r\n\r\nAfter all, the file may remain due to test case failure and other reasons.\n\n### What is the feature you are proposing to solve the problem?\n\nUnder the mock namespace, APIs are exposed to provide a mock file system.\r\n\r\n```js\r\nmock.fileSystem.enable({ });\r\n```\r\n\r\nAnd provide some options\r\n\r\ne.g.\r\n\r\nOverride the file that defined by defaults\r\n\r\n```js\r\nmock.fileSystem.enable({\r\n files: {\r\n '/path/to/file': new Uint8Array([0])\r\n }\r\n});\r\n\r\n// it will read the virtual file system first if it does exist\r\n// if not found, then read the read the real file system\r\nfs.readFileSync('/path/to/file')\r\n```\r\n\r\nOverride the whole file system\r\n\r\n```js\r\nmock.fileSystem.enable({\r\n files: {\r\n '/path/to/file': new Uint8Array([0])\r\n },\r\n override: true // override the whole file system\r\n});\r\n\r\n// This file is exists in the real file system\r\n// But not define in the vitual file system, so it should throw an error\r\nfs.readFileSync('/etc/proc')\r\n```\r\n\n\n### What alternatives have you considered?\n\n[mock-fs](https://www.npmjs.com/package/mock-fs)","author":{"url":"https://github.com/axetroy","@type":"Person","name":"axetroy"},"datePublished":"2024-11-18T06:05:08.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/55902/node/issues/55902"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4541bf8f-f257-b206-a522-f1dd27621c10 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 87CC:348CFA:869F8D:C10D66:6A4CB22F |
| html-safe-nonce | a508cfac029e117d1c566b4c673ce49161a37072b8d0dc5f7b025030ee6e258e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4N0NDOjM0OENGQTo4NjlGOEQ6QzEwRDY2OjZBNENCMjJGIiwidmlzaXRvcl9pZCI6IjM2OTAzNDI3MzU1MjMxMzE5NTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 786d06c37129915ff8af8e80499ce3b6cfe9c8c9ccacf599a24e77ce81e7ccbc |
| hovercard-subject-tag | issue:2667275360 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/55902/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1ad8c2cad8492f88f35465645af404ac90723e86da3cc8d793a35cf917ba3227/nodejs/node/issues/55902 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1ad8c2cad8492f88f35465645af404ac90723e86da3cc8d793a35cf917ba3227/nodejs/node/issues/55902 |
| og:image:alt | What is the problem this feature will solve? The current test requires writing files to a real disk when reading and writing files related to the file system, which is very unsafe. After all, the f... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | axetroy |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3d11bb817438277de2a940854450e83a7d32b6aeb5014e9e6b00a6423900251c |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ae90d426644ca15e89bacceb72e51f4e9dbf85f7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width