我使用Grunt来运行我的响应式网站的测试。Grunt-contrib-jasmine使用PhantomJS来运行网页。我注意到默认的视口宽度是400px。不过,我也想测试一下我在大屏幕上的表现。我如何改变viewport的宽度PhantomJS?
许多谢谢。我Gruntfile.jsmodule.exports = function (grunt) {
grunt.initConfig({
cssmin: {
css: {
src: 'css/common/page.css',
dest: 'css/common/page.min.css'
}
},
jshint: {
options: {
browser: true,
curly: true,
eqeqeq: true,
eqnull: true,
funcscope: true,
globals: {
jQuery: true
},
loopfunc: true,
reporter: require('jshint-stylish'),
smarttabs: true,
shadow: true
},
all: ['Gruntfile.js', 'js/default.j s', 'js/utils.js', 'tests/jasmine-standalone-2.0.0/spec/*.js']
},
jasmine: {
obpjs: {
src: 'tests/jasmine-standalone-2.0.0/src/*.js',
options: {
specs: 'tests/jasmine-standalone-2.0.0/spec/CommonSpec.js',
vendor: ['js/extlib.min.js', 'tests/jasmine-jquery/jasmine-jquery.js'],
helpers: ['js/utils.js', 'js/default.js'],
styles: 'css/common/page.min.css',
summary: true,
keepRunner: true
}
}
},
watch: {
script: {
files: ['js/default.js', 'js/utils.js'],
tasks: ['jshint']
},
styles: {
files: ['css/common/page.css'],
tasks: ['cssmin']
},
tests: {
files: ['js/default.js', 'js/utils.js', 'tests/jasmine-standalone-2.0.0/spec/*.js'],
tasks: ['jshint', 'jasmine']
}
}
});
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['jshint', 'jasmine']);
grunt.registerTask('build', ['cssmin', 'jshint', 'jasmine']);
};
试试这个:
jasmine: {
obpjs: {
src: 'tests/jasmine-standalone-2.0.0/src/*.js',
options: {
specs: 'tests/jasmine-standalone-2.0.0/spec/CommonSpec.js',
vendor: ['js/extlib.min.js', 'tests/jasmine-jquery/jasmine-jquery.js'],
helpers: ['js/utils.js', 'js/default.js'],
styles: 'css/common/page.min.css',
summary: true,
keepRunner: true,
page: {
viewportSize: {
width: 480,
height: 800
}
}
}
}
}
http://phantomjs.org/api/webpage/property/viewport-size.html