2

Gruntfile.js 内容:

grunt.initConfig({
        connect: {
            server: {
                options: {
                    port: 5005,
                    base: '.'
                }
            }
        },
        qunit: {
            all: ['test/*.html']
        }
    });

grunt.loadNpmTasks('grunt-contrib-connect');
    grunt.loadNpmTasks('grunt-contrib-qunit');

grunt.registerTask('test', ['connect', 'qunit']);

测试/index.html 文件内容:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>
            Sitejson - QUnit Test Runner
        </title>
        <link rel="stylesheet" href="libs/qunit/qunit.css" type="text/css">
    </head>
    <body>
        <div id="qunit"></div>
        <div id="qunit-fixture"></div>

        <script src="libs/qunit/qunit.js" type="text/javascript"></script>
        <script src="testcases/tests.js" type="text/javascript"></script>
    </body>
</html>

tests.js 内容:

QUnit.test("hello test", function(assert) {
    assert.ok(1 == "1", "Passed!");
});

我正在开发 Ubuntu / Linux 环境。我还安装了 Phantomjs 并且工作正常。每当我尝试运行 grunt test 时,我都会收到一个致命错误:spawn ENOENT 错误。

虽然我尝试在浏览器上运行它,但它的 qunit 工作正常......

我无法确定是什么问题。我是否在这里缺少更多配置。

grunt test --debug 告诉我:

Running "connect:server" (connect) task
[D] Task source: /media/hegdeashwin/Storage-TB/qunittesting/node_modules/grunt-contrib-connect/tasks/connect.js
Started connect web server on http://0.0.0.0:5005

Running "qunit:all" (qunit) task
[D] Task source: /media/hegdeashwin/Storage-TB/qunittesting/node_modules/grunt-contrib-qunit/tasks/qunit.js
Testing test/index.html [D] ["/media/hegdeashwin/Storage-TB/qunittesting/node_modules/grunt-contrib-qunit/node_modules/grunt-lib-phantomjs/phantomjs/main.js","/tmp/1405775714604.2773","test/index.html","{\"timeout\":5000,\"inject\":\"/media/hegdeashwin/Storage-TB/qunittesting/node_modules/grunt-contrib-qunit/phantomjs/bridge.js\",\"urls\":[],\"force\":false,\"console\":true,\"httpBase\":false}"]
Fatal error: spawn EACCES
4

1 回答 1

1

使用以下过程:

  • 设置tmpdir环境变量:

    setenv TMPDIR=~/tmp
    
  • 重新运行grunt任务

  • 如果可行,请通过将以下内容添加到您的.bashrcor来永久设置它.profile

    export TMPDIR=~/tmp
    

参考

于 2015-04-19T05:37:05.433 回答