我现在正在处理一些代码,由于集成测试是在Windows计算机的EC2实例上运行测试作业,因此这些代码正在我们的集成测试中搞砸了。解决文件名过长的问题后,许多路径仍无法正确解析,因为其中许多路径是针对UNIX进行硬编码的。
我一直在研究nodejs的Path模块,但是我不确定要更改所有内容以使路径名在两个操作系统上都能正常工作(当然不是反斜杠)。我需要为Windows的这些路径名添加前缀吗?
这是一些失败的代码:
function getDirectories(srcpath) {
//srcPath looks like graph-validator/tests/data/graph-examples/
return fs.readdirSync(srcpath).filter(function(file) {
return (
file !== '.git' && fs.statSync(path.join(srcpath, file)).isDirectory()
)
})
}
const dataDirectory = 'graph-validator/tests/data/'
// Generate valid input for included minimal tests
function createDatasetFileList(path) {
const testDatasetPath = `${dataDirectory}${path}`
//path is often 'graph-examples/ds001/'
if (!isNode) {
return createFileList(testDatasetPath)
} else {
return testDatasetPath
// testDatasetPath = graph-validator/tests/data/graph-examples/ds001/
}
}
我尝试过path.join()
,但这似乎可以部分解决这个问题,至少是斜杠。如何使这些路径名在OS'之间完全不可知?
我认为您要寻找的是path.sep
? https://nodejs.org/api/path.html#path_path_sep