【发布时间】:2020-03-14 18:20:52
【问题描述】:
使用 jest 和节点,我想检查我的一个文件是否有错误解决的 GIT 冲突。我做了一个可以在我的机器上运行的代码:
const cmd = `find . -not \\( -path ./node_modules -prune \\) -not \\( -path ./.next -prune \\) -not \\( -path ./.git -prune \\) -type f -print0 | xargs -0 grep -li "<<<< HEAD"`
describe('Git conflicts', () => {
test('All conflicts should be resolved', () => {
const result = require('child_process')
.execSync(cmd)
.toString('utf8')
expect(result).toBe('./server/__tests__/check-git-conflicts.test.js\n')
})
})
但是,正如我所说,它可以在我的机器上运行......但它在不同的环境中不起作用,因为我正在直接执行 UNIX 命令。
为了让它更健壮。我想更改该命令:
find . -not \\( -path ./node_modules -prune \\) -not \\( -path ./.next -prune \\) -not \\( -path ./.git -prune \\) -type f -print0 | xargs -0 grep -li "<<<< HEAD
仅用node.js 代码编写它,以便与环境更加兼容。我尝试使用fs.readFile,但尝试失败...
有人知道在 Node.js 中搜索多个文件中的文本的有效方法吗?
【问题讨论】:
标签: javascript node.js unix testing jestjs