[求助]请教一个问题, travis 上跑测试的时候报错: spawn EACCES

2021-09-23 13:48:38 +08:00
 jzlivioo

学习 node 中,写了个跑本地 html 的工具,类似于 live-server

然后在 travis 上跑测试的时候报错了

这两个测试用例是用来验证命令行功能的,使用起来大概是server --version这样子

给这个工具的命令行参数加测试的时候,是读取编译后的 js 文件,然后用 child_process.execFile 来跑这个文件并添加参数,代码如下

...
var cmd = path.join(__dirname, "../lib", "serve.js");
var exec = require("child_process").execFile;
...

function exec_test(args, callback) {
  if (process.platform === "win32")
    exec(process.execPath, [cmd].concat(args), opts, callback);
  else exec(cmd, args, opts, callback);
}

describe("command line usage", function () {
  it("--version", function (done) {
    exec_test(["--version"], function (error, stdout, stdin) {
      assert(!error, error);
      assert(stdout.indexOf("server") !== -1, "version not found");
      done();
    });
  });
  ...

本地跑测试的话是会通过的

请问这是文件访问权限的问题吗?如何解决呢?

5113 次点击
所在节点    Node.js
1 条回复
xingguang
2021-09-23 13:54:25 +08:00
权限问题,要么用 sudo 去运行(不推荐),要么给 node 监听的文件夹读写权限 sudo chmod -R a+rwx

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/803624

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX