nodejs / nodejs/node

test_runner: support mock file system

未关闭
#55,902 12 条评论 4 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

feature request fs test_runner
主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 3 小时
30 天内合并 PR
272

描述

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 and other reasons.

What is the feature you are proposing to solve the problem?

Under the mock namespace, APIs are exposed to provide a mock file system.

mock.fileSystem.enable({ });

And provide some options

e.g.

Override the file that defined by defaults

mock.fileSystem.enable({
  files: {
    '/path/to/file': new Uint8Array([0])
  }
});

// it will read the virtual file system first if it does exist
// if not found, then read the read the real file system
fs.readFileSync('/path/to/file')

Override the whole file system

mock.fileSystem.enable({
  files: {
    '/path/to/file': new Uint8Array([0])
  },
  override: true // override the whole file system
});

// This file is exists in the real file system
// But not define in the vitual file system, so it should throw an error
fs.readFileSync('/etc/proc')
What alternatives have you considered?

mock-fs

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先检查 test_runner 的 mock 命名空间以及 issue 中描述的文件系统 API。明确 mock.fileSystem.enable 如何处理已配置的文件、回退到真实文件系统以及处理覆盖模式;当这些行为已对外提供并由测试覆盖时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, node.js
领域
operating-systems, testing-qa
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
冷清
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。