Javascript gruntjs和phantomjs测试中的问题
我想创建一个Gruntfile.js来运行一组phantomjs测试,当我从命令行执行>grunt run test时,它会运行一组测试。我创建了一个Gruntfile.js和package.json,它可以正常工作,并且可以从目录中读取大量测试。现在我的问题是,当我编写phantomjs测试并运行“grunt”时,它会给我以下错误: 错误:找不到模块“系统” 错误:找不到模块“幻影” 但是,以前通过使用Javascript gruntjs和phantomjs测试中的问题,javascript,node.js,gruntjs,phantomjs,Javascript,Node.js,Gruntjs,Phantomjs,我想创建一个Gruntfile.js来运行一组phantomjs测试,当我从命令行执行>grunt run test时,它会运行一组测试。我创建了一个Gruntfile.js和package.json,它可以正常工作,并且可以从目录中读取大量测试。现在我的问题是,当我编写phantomjs测试并运行“grunt”时,它会给我以下错误: 错误:找不到模块“系统” 错误:找不到模块“幻影” 但是,以前通过使用npm安装phantomjs安装phantomjs phantomtest的示例给出了上述错
npm安装phantomjs安装phantomjs
phantomtest的示例给出了上述错误:
var system = require('system');
if (system.args.length === 1) {
console.log('Try to pass some args when invoking this script!');
} else {
system.args.forEach(function (arg, i) {
console.log(i + ': ' + arg);
});
}
phantom.exit();
当我运行phantomjstest1(测试文件的名称)时,它会运行测试,所以我想也许我应该在Gruntfile中的某个地方附加“phantomjs”。有什么想法吗
Grunfile.js
'use strict';
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
jshint: {
all: [
'Gruntfile.js',
'tests/*.js',
'<%= nodeunit.tests %>',
],
options: {
jshintrc: '.jshintrc',
},
},
// Before generating any new files, remove any previously-created files.
clean: {
tests: ['tmp'],
},
// Configuration to be run (and then tested).
testArgs: {
configFile:"test/testConf.js",
options: {
args: {
params: {
number: 1,
bool: true,
str: "string",
nil: null, // Null is not supported.
obj: {
array: [1, 2, 3],
undef: undefined
}
},
capabilities: {
'browserName': 'chrome'
},
rootElement:"body",
specs:["test/argsTest.js"],
verbose:true
}
}
},
testDebug: {
configFile:"test/testConf.js",
options: {
debug:true,
args: {
specs:["test/debugTest.js"],
}
}
},
// Unit tests.
nodeunit: {
tests: ['tests/*_test.js'],
},
});
// Actually load this plugin's task(s).
grunt.loadTasks('tests');
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-nodeunit');
// Whenever the "test" task is run, first clean the "tmp" dir, then run this
// plugin's task(s), then test the result.
grunt.registerTask('test', ['clean']);
// By default, lint and run all tests.
grunt.registerTask('default', ['jshint', 'test']);
};
“严格使用”;
module.exports=函数(grunt){
//项目配置。
grunt.initConfig({
jshint:{
全部:[
“Gruntfile.js”,
“tests/*.js”,
'',
],
选项:{
jshintrc:“.jshintrc”,
},
},
//在生成任何新文件之前,请删除所有以前创建的文件。
清洁:{
测试:['tmp'],
},
//要运行(然后测试)的配置。
测试RGS:{
配置文件:“test/testConf.js”,
选项:{
args:{
参数:{
编号:1,
布尔:是的,
str:“字符串”,
nil:null,//不支持null。
obj:{
数组:[1,2,3],
未定义:未定义
}
},
能力:{
'browserName':'chrome'
},
根元素:“身体”,
规范:[“test/argsTest.js”],
详细:正确
}
}
},
测试调试:{
配置文件:“test/testConf.js”,
选项:{
是的,
args:{
规范:[“test/debugTest.js”],
}
}
},
//单元测试。
nodeunit:{
测试:['tests/*_test.js'],
},
});
//实际加载此插件的任务。
grunt.loadTasks(“测试”);
//这些插件提供了必要的任务。
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks(“grunt-contrib-clean”);
grunt.loadNpmTasks(“grunt-contrib-nodeunit”);
//每当运行“test”任务时,首先清除“tmp”目录,然后运行此
//插件的任务,然后测试结果。
grunt.registerTask('test',['clean']);
//默认情况下,lint并运行所有测试。
registerTask('default',['jshint','test']);
};
testConf.js中有什么?好问题!:)我使用上面的插件代码。那么你认为我应该更改这个文件吗?我似乎找不到任何关于你正在使用的PhantomJS插件的引用。但是可能有一些模块没有加载(正确)。好吧,我已经单独安装了phantomjs,我想如果我编写一个GrunFile,可以从一个目录中读取和运行多个文件,并将phantomjs测试放在这个目录中,测试就可以运行了。所以我需要从这个文件中运行幻影?你能看一看吗