Grunt + Protractor - 找不到任务 "shell:xvfb"

Grunt + Protractor - Task "shell:xvfb" not found

我正在尝试使用 g运行t 来 运行 Xvfb 和我的量角器测试,但是当我执行我的任务量角器-xvfb 时,我得到了这个 return :

Running tasks: protractor-xvfb Warning: Task "protractor-xvfb" not found. Use --force to continue.

Aborted due to warnings.

我的Gruntfile.js:

module.exports = function(grunt) {


    grunt.initConfig({
        protractor: {
            options: {
                keepAlive: true,
                configFile: "protractor.conf.js"
            },
            run: {}
        },

        shell: {
            xvfb: {
                command: 'Xvfb :99 -ac -screen 0 1600x1200x24',
                options: {
                    async: true
                }
            }
        },
        env: {
            xvfb: {
                DISPLAY: ':99'
            }
        }

});


    grunt.registerTask('protractor-xvfb',[
        'shell:xvfb',
        'env:xvfb',
        'protractor:run',
        'shell:xvfb:kill'
        ]);

// assim funciona
    grunt.registerTask('test', 'Test task.', function() {
        grunt.log.writeln('Lorem ipsum dolor sit amet.');
    });

}

当我执行我的任务测试时,它是成功的,我得到了这个return:

Running tasks: test

Running "test" task Lorem ipsum dolor sit amet.

Done, without errors.

OBS:我在没有 g运行t 的情况下使用量角器进行的测试工作正常。 Return:

Finished in 24.753 seconds

9 tests, 5 assertions, 0 failures

OBS2:我正在关注这个例子:Running Xvfb from Grunt

我不确定这是否是核心问题,但您在代码中将 shell.xvfb.command 设置为包含字符串的数组,而您链接的示例只有一个字符串。

我解决了我的问题!

首先,我的 Gruntfile.js 不在我的项目根目录中,我需要将它放在靠近 package.json 的项目根目录中,以便将我的插件加载到 运行 这些测试中。当我添加这些插件以加载我的测试失败时,我的 Gruntfile.js 在错误的路径上:

 grunt.loadNpmTasks('grunt-shell-spawn');
 grunt.loadNpmTasks('grunt-env');
 grunt.loadNpmTasks('grunt-protractor-runner');

失败信息:

Registering "grunt-shell-spawn" local Npm module tasks.
>> Local Npm module "grunt-shell-spawn" not found. Is it installed?

Registering "grunt-env" local Npm module tasks.
>> Local Npm module "grunt-env" not found. Is it installed?

Registering "grunt-protractor-runner" local Npm module tasks.
>> Local Npm module "grunt-protractor-runner" not found. Is it installed?
Loading "Gruntfile.js" tasks...OK

我删除了所有已安装并重新安装的 g运行t 内容。

我的 G运行t 文件在正确的路径中,我可以加载我的插件和 运行 我用 G运行t + Xvfb + Protractor 的测试。