在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):gruntjs/grunt-contrib-jasmine开源软件地址(OpenSource Url):https://github.com/gruntjs/grunt-contrib-jasmine开源编程语言(OpenSource Language):JavaScript 97.4%开源软件介绍(OpenSource Introduction):grunt-contrib-jasmine v2.2.0
Getting StartedIf you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command: npm install grunt-contrib-jasmine --save-dev Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: grunt.loadNpmTasks('grunt-contrib-jasmine'); Jasmine taskRun this task with the Automatically builds and maintains your spec runner and runs your tests headlessly through Headless Chrome. Run specs locally or on a remote serverRun your tests on your local filesystem or via a server task like grunt-contrib-connect. Customize your SpecRunner with templatesUse your own SpecRunner templates to customize how AMD SupportSupports AMD tests via the grunt-template-jasmine-requirejs module Third party templatesOptionssrcType: Your source files. These are the files that you are testing. If you are using RequireJS your source files will be loaded as dependencies into your spec modules and will not need to be placed here. options.specsType: Your Jasmine specs. options.vendorType: Third party libraries like jQuery & generally anything loaded before source, specs, and helpers. options.helpersType: Non-source, non-spec helper files. In the default runner these are loaded after options.stylesType: CSS files that get loaded after the jasmine.css options.versionType: This is the version of Jasmine which will be used. Available versions are published to npm. options.tempDirType: The temporary directory that runners use to load jasmine files. Automatically deleted upon normal runs. options.outfileType: The auto-generated specfile that Headless Chrome will use to run your tests.
Automatically deleted upon normal runs. Use the options.keepRunnerType: Prevents the auto-generated specfile used to run your tests from being automatically deleted. options.junit.pathType: Path to output JUnit xml options.junit.consolidateType: Consolidate the JUnit XML so that there is one file per top level suite. options.junit.templateType: Specify a custom JUnit template instead of using the default options.hostType: The host you want Headless Chrome to connect against to run your tests. e.g. if using an ad hoc server from within grunt host : 'http://127.0.0.1:8000/' Without a options.templateType: Custom template used to generate your Spec Runner. Parsed as underscore templates and provided the expanded list of files needed to build a specrunner. You can specify an object with a options.templateOptionsType: Options that will be passed to your template. Used to pass settings to the template. options.polyfillsType: Third party polyfill libraries like json2 that are loaded at the very top before anything else. options.displayType:
options.allowFileAccessType: Launches puppeteer with --allow-file-access-from-files (Fix Issue #298) options.timeoutType: Change the puppeteer default timeout value in milliseconds (reference: https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#pagesetdefaulttimeouttimeout) options.sandboxArgsType: Pass arugments to puppeteer launcher. For the list of available options, please look at puppeteer launch options. Example {
args: {
'=-allow-file-access-from-files'
},
executablePath: '/some/other/path/to/chrome'
} options.summaryType: Display a list of all failed tests and their failure messages FlagsName: Turn on this flag in order to build a SpecRunner html file. This is useful when troubleshooting templates, running in a browser, or as part of a watch chain e.g. watch: {
pivotal : {
files: ['src/**/*.js', 'specs/**/*.js'],
tasks: 'jasmine:pivotal:build'
}
} Filtering specsfilename
folder
wildcard
comma separated filters
flags with space
Example application usageBasic UseSample configuration to run Pivotal Labs' example Jasmine application. // Example configuration
grunt.initConfig({
jasmine: {
pivotal: {
src: 'src/**/*.js',
options: {
specs: 'spec/*Spec.js',
helpers: 'spec/*Helper.js'
}
}
}
}); Supplying a custom templateSupplying a custom template to the above example // Example configuration
grunt.initConfig({
jasmine: {
customTemplate: {
src: 'src/**/*.js',
options: {
specs: 'spec/*Spec.js',
helpers: 'spec/*Helper.js',
template: 'custom.tmpl'
}
}
}
}); Supplying template modules and vendorsA complex version for the above example // Example configuration
grunt.initConfig({
jasmine: {
customTemplate: {
src: 'src/**/*.js',
options: {
specs: 'spec/*Spec.js',
helpers: 'spec/*Helper.js',
template: require('exports-process.js'),
vendor: [
'vendor/*.js',
'http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js'
]
}
}
}
}); Passing options to sandbox (puppeteer)See puppeteer launch options for a complete list of arguments. // Example configuration
grunt.initConfig({
jasmine: {
customTemplate: {
src: 'src/**/*.js',
options: {
specs: 'spec/*Spec.js',
helpers: 'spec/*Helper.js',
template: 'custom.tmpl',
sandboxArgs: {
args: ['--no-sandbox'],
timeout: 3000,
defaultViewport: {
isMobile: true
}
}
}
}
}
}); Sample RequireJS/NPM Template usage// Example configuration
grunt.initConfig({
jasmine: {
yourTask: {
src: 'src/**/*.js',
options: {
specs: 'spec/*Spec.js',
template: require('grunt-template-jasmine-requirejs')
}
}
}
}); NPM Templates are just node modules, so you can write and treat them as such. Please see the grunt-template-jasmine-requirejs documentation for more information on the RequireJS template. Keeping temp files in an existing directorySupplying a custom temp directory // Example configuration
grunt.initConfig({
jasmine: {
pivotal: {
src: 'src/**/*.js',
options: {
keepRunner: true,
tempDir: 'bin/jasmine/',
specs: 'spec/*Spec.js',
helpers: 'spec/*Helper.js'
}
}
}
}); Release History
Task submitted by Jarrod Overson This file was generated on Thu May 13 2021 10:47:51. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论