• Stars
    star
    354
  • Rank 120,042 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 12 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Run jasmine specs headlessly through Headless Chrome

grunt-contrib-jasmine v4.0.0 Build Status

Run jasmine specs headlessly through Headless Chrome

Getting Started

If 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 task

Run this task with the grunt jasmine command.

Automatically builds and maintains your spec runner and runs your tests headlessly through Headless Chrome.

Run specs locally or on a remote server

Run your tests on your local filesystem or via a server task like grunt-contrib-connect.

Customize your SpecRunner with templates

Use your own SpecRunner templates to customize how grunt-contrib-jasmine builds the SpecRunner. See the wiki for details and third party templates for examples.

AMD Support

Supports AMD tests via the grunt-template-jasmine-requirejs module

Third party templates

Options

src

Type: String|Array

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.specs

Type: String|Array

Your Jasmine specs.

options.vendor

Type: String|Array

Third party libraries like jQuery & generally anything loaded before source, specs, and helpers.

options.helpers

Type: String|Array

Non-source, non-spec helper files. In the default runner these are loaded after vendor files

options.styles

Type: String|Array

CSS files that get loaded after the jasmine.css

options.version

Type: String Default: 'latest'

This is the version of Jasmine which will be used. Available versions are published to npm.

options.tempDir

Type: String Default: .grunt/grunt-contrib-jasmine

The temporary directory that runners use to load jasmine files. Automatically deleted upon normal runs.

options.outfile

Type: String
Default: _SpecRunner.html

The auto-generated specfile that Headless Chrome will use to run your tests. Automatically deleted upon normal runs. Use the :build flag to generate a SpecRunner manually e.g. grunt jasmine:myTask:build

options.keepRunner

Type: Boolean
Default: false

Prevents the auto-generated specfile used to run your tests from being automatically deleted.

options.junit.path

Type: String
Default: undefined

Path to output JUnit xml

options.junit.consolidate

Type: Boolean
Default: false

Consolidate the JUnit XML so that there is one file per top level suite.

options.junit.template

Type: String
Default: undefined

Specify a custom JUnit template instead of using the default junitTemplate.

options.host

Type: String
Default: ''

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 host, your specs will be run from the local filesystem.

options.template

Type: String Object
Default: undefined

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 process method that will be called as a template function. See the Template API Documentation for more details.

options.templateOptions

Type: Object
Default: {}

Options that will be passed to your template. Used to pass settings to the template.

options.polyfills

Type: String|Array

Third party polyfill libraries like json2 that are loaded at the very top before anything else.

options.display

Type: String
Default: 'full'

  • full displays the full specs tree
  • short only displays a success or failure character for each test (useful with large suites)
  • none displays nothing

options.allowFileAccess

Type: Boolean Default: false

Launches puppeteer with --allow-file-access-from-files (Fix Issue #298)

options.timeout

Type: Number Default: 30000

Change the puppeteer default timeout value in milliseconds (reference: https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#pagesetdefaulttimeouttimeout)

options.sandboxArgs

Type: Object Default: { args: [] }

Pass arugments to puppeteer launcher. For the list of available options, please look at puppeteer launch options.

Example sandboxArgs object:

{
  args: {
    '=-allow-file-access-from-files'
  },
  executeablePath: '/some/other/path/to/chrome'
}

options.summary

Type: Boolean
Default: false

Display a list of all failed tests and their failure messages

Flags

Name: build

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 specs

filename grunt jasmine --filter=foo will run spec files that have foo in their file name.

folder grunt jasmine --filter=/foo will run spec files within folders that have foo* in their name.

wildcard grunt jasmine --filter=/*-bar will run anything that is located in a folder *-bar

comma separated filters grunt jasmine --filter=foo,bar will run spec files that have foo or bar in their file name.

flags with space grunt jasmine --filter="foo bar" will run spec files that have foo bar in their file name. grunt jasmine --filter="/foo bar" will run spec files within folders that have foo bar* in their name.

Example application usage

Basic Use

Sample 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 template

Supplying 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 vendors

A 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 directory

Supplying 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

  • 2023-01-12โ€ƒโ€ƒโ€ƒv4.0.0โ€ƒโ€ƒโ€ƒDependency Updates requires node 14+ requires jasmine 3.9.0+ bump puppeteer to version 19
  • 2021-05-13โ€ƒโ€ƒโ€ƒv3.0.0โ€ƒโ€ƒโ€ƒDependency Updates drop node 8 support bump puppeteer to 8.0.0
  • 2020-05-04โ€ƒโ€ƒโ€ƒv2.2.0โ€ƒโ€ƒโ€ƒDependency updates set the default option timeout value to 30 secs to sync with puppeteer's default timeout value. options.sandboxArgs; passing options to puppeteer
  • 2019-07-31โ€ƒโ€ƒโ€ƒv2.1.3โ€ƒโ€ƒโ€ƒFix security deps Update Puppeteer
  • 2018-11-14โ€ƒโ€ƒโ€ƒv2.0.3โ€ƒโ€ƒโ€ƒ[object Object] Build only should pass if the buildSpecrunner runs without error
  • 2018-08-13โ€ƒโ€ƒโ€ƒv2.0.2โ€ƒโ€ƒโ€ƒFix noSandbox option. Fix startTime, and timing issues.
  • 2018-05-31โ€ƒโ€ƒโ€ƒv2.0.1โ€ƒโ€ƒโ€ƒUse the grunt current working directory to find the jasmine core. Implement options.version. Dependency updates.
  • 2018-05-19โ€ƒโ€ƒโ€ƒv2.0.0โ€ƒโ€ƒโ€ƒSwitch from PhantomJS to Chrome Headless via Puppeteer
  • 2017-01-12โ€ƒโ€ƒโ€ƒv1.1.0โ€ƒโ€ƒโ€ƒadds tempDir option. locks jasmine version
  • 2016-04-07โ€ƒโ€ƒโ€ƒv1.0.3โ€ƒโ€ƒโ€ƒMove to a non-deprecated sprintf.
  • 2016-04-07โ€ƒโ€ƒโ€ƒv1.0.2โ€ƒโ€ƒโ€ƒFix sprintf issues in error calls.
  • 2016-04-07โ€ƒโ€ƒโ€ƒv1.0.1โ€ƒโ€ƒโ€ƒAllow to use custom bootfile. Doc updates. Fix and use lodash directly.
  • 2016-01-26โ€ƒโ€ƒโ€ƒv1.0.0โ€ƒโ€ƒโ€ƒBump grunt-lib-phantomjs to 1.0.0. Bump jasmine to 2.2.0.
  • 2015-09-24โ€ƒโ€ƒโ€ƒv0.9.2โ€ƒโ€ƒโ€ƒFixes npm@3 issues.
  • 2015-09-04โ€ƒโ€ƒโ€ƒv0.9.1โ€ƒโ€ƒโ€ƒFix summary logging.
  • 2015-07-10โ€ƒโ€ƒโ€ƒv0.9.0โ€ƒโ€ƒโ€ƒFix deprecated package.json licenses. Fix Phantomjs dependency to include correct phantom kill.
  • 2015-01-08โ€ƒโ€ƒโ€ƒv0.8.2โ€ƒโ€ƒโ€ƒFixes to test summary reporting.
  • 2014-10-20โ€ƒโ€ƒโ€ƒv0.8.1โ€ƒโ€ƒโ€ƒNow removes listeners when using the build flag. Adds handler for fail.load.
  • 2014-07-26โ€ƒโ€ƒโ€ƒv0.8.0โ€ƒโ€ƒโ€ƒPlugin now uses Jasmine 2.0.4 from npm. Updates other dependencies. Added options.polyfills.
  • 2014-07-26โ€ƒโ€ƒโ€ƒv0.7.0โ€ƒโ€ƒโ€ƒMerged #153 to add stack trace to summary. Updated for Jasmine 2.0.1. Merged #133 for minimal output. Merged #139 changing file exclusion logic.
  • 2014-05-31โ€ƒโ€ƒโ€ƒv0.6.5โ€ƒโ€ƒโ€ƒOption to allow specifying a junitTemplate.
  • 2014-04-28โ€ƒโ€ƒโ€ƒv0.6.4โ€ƒโ€ƒโ€ƒIndent level fix. Moved scripts inside the body tag.
  • 2014-01-29โ€ƒโ€ƒโ€ƒv0.6.0โ€ƒโ€ƒโ€ƒJasmine 2.0.0 support. Improved logging support. Various merges/bugfixes.
  • 2013-08-02โ€ƒโ€ƒโ€ƒv0.5.2โ€ƒโ€ƒโ€ƒFixed breakage with iframes / #44. Added filter flag / #70. Fixed junit failure output / #77.
  • 2013-06-18โ€ƒโ€ƒโ€ƒv0.5.1โ€ƒโ€ƒโ€ƒMerged #69: grunt async not called when tests fail or keepRunner is true.
  • 2013-06-15โ€ƒโ€ƒโ€ƒv0.5.0โ€ƒโ€ƒโ€ƒUpdated rimraf. Made teardown async. Added Function.prototype.bind polyfill. Breaking (templates) changed input options for getRelativeFileList. Breaking (usage) failing task on phantom error (SyntaxError, TypeError, et al).
  • 2013-04-03โ€ƒโ€ƒโ€ƒv0.4.2โ€ƒโ€ƒโ€ƒUpdated grunt-lib-phantomjs to 0.3.0/1.9 (closes #45). Merged #38, #51. Addressed #40, #43, #48, #45.
  • 2013-03-08โ€ƒโ€ƒโ€ƒv0.4.0โ€ƒโ€ƒโ€ƒUpdated grunt-lib-phantomjs to 0.2.0/1.8. Allowed spec/vendor/helper list to return non-matching files (e.g. for remote, http). Merged #30, #34.
  • 2013-02-24โ€ƒโ€ƒโ€ƒv0.3.3โ€ƒโ€ƒโ€ƒAdded better console output (via Gabor Kiss @Neverl).
  • 2013-02-17โ€ƒโ€ƒโ€ƒv0.3.2โ€ƒโ€ƒโ€ƒEnsure Gruntfile.js is included on npm.
  • 2013-02-15โ€ƒโ€ƒโ€ƒv0.3.1โ€ƒโ€ƒโ€ƒFirst official release for Grunt 0.4.0.
  • 2013-01-22โ€ƒโ€ƒโ€ƒv0.3.1rc7โ€ƒโ€ƒโ€ƒExposed phantom and sendMessage to templates
  • 2013-01-22โ€ƒโ€ƒโ€ƒv0.3.0rc7โ€ƒโ€ƒโ€ƒUpdated dependencies for grunt v0.4.0rc6/rc7
  • 2013-01-08โ€ƒโ€ƒโ€ƒv0.3.0rc5โ€ƒโ€ƒโ€ƒUpdating to work with grunt v0.4.0rc5. Switching to this.filesSrc API. Added JUnit xml output (via Kelvin Luck @vitch). Passing console.log from browser to verbose grunt logging. Support for templates as separate node modules. Removed internal requirejs template (see grunt-template-jasmine-requirejs).
  • 2012-12-03โ€ƒโ€ƒโ€ƒv0.2.0โ€ƒโ€ƒโ€ƒGeneralized requirejs template config. Added loader plugin. Tests for templates. Updated jasmine to 1.3.0.
  • 2012-11-24โ€ƒโ€ƒโ€ƒv0.1.2โ€ƒโ€ƒโ€ƒUpdated for new grunt/grunt-contrib APIs.
  • 2012-11-07โ€ƒโ€ƒโ€ƒv0.1.1โ€ƒโ€ƒโ€ƒFixed race condition in requirejs template.
  • 2012-11-07โ€ƒโ€ƒโ€ƒv0.1.0โ€ƒโ€ƒโ€ƒPorted grunt-jasmine-runner and grunt-jasmine-task to grunt-contrib.

Task submitted by Jarrod Overson

This is a generated file.

More Repositories

1

grunt

Grunt: The JavaScript Task Runner
JavaScript
12,273
star
2

grunt-contrib-watch

Run tasks whenever watched files change.
JavaScript
1,982
star
3

grunt-contrib-uglify

Minify files with UglifyJS.
JavaScript
1,483
star
4

grunt-contrib-imagemin

Minify PNG, JPG, GIF and SVG images.
JavaScript
1,214
star
5

grunt-contrib-sass

Compile Sass to CSS.
JavaScript
848
star
6

grunt-contrib-concat

Concatenate files.
JavaScript
811
star
7

grunt-contrib-cssmin

Compress CSS files.
JavaScript
793
star
8

grunt-contrib-copy

Copy files and folders.
JavaScript
726
star
9

grunt-contrib-connect

Start a static web server.
JavaScript
714
star
10

grunt-contrib-jshint

Validate files with JSHint.
JavaScript
709
star
11

grunt-cli

Grunt's command line interface.
JavaScript
707
star
12

grunt-contrib-less

Compile LESS files to CSS.
JavaScript
667
star
13

grunt-contrib-compass

Compile Compass to CSS.
JavaScript
625
star
14

grunt-contrib-clean

Clear files and folders.
JavaScript
512
star
15

grunt-contrib-requirejs

Optimize RequireJS projects using r.js.
JavaScript
504
star
16

grunt-contrib

[DEPRECATED] A collection of common grunt tasks.
JavaScript
475
star
17

grunt-contrib-htmlmin

Minify HTML.
JavaScript
425
star
18

grunt-contrib-compress

Compress files and folders.
JavaScript
345
star
19

grunt-contrib-coffee

Compile CoffeeScript files to JavaScript.
JavaScript
329
star
20

grunt-contrib-pug

Compile Pug templates.
JavaScript
328
star
21

grunt-contrib-handlebars

Precompile Handlebars templates to JST file.
JavaScript
282
star
22

grunt-contrib-csslint

Lint CSS files.
JavaScript
240
star
23

grunt-contrib-qunit

Run QUnit tests in Headless Chrome.
JavaScript
214
star
24

grunt-contrib-livereload

Reload assets live in the browser.
JavaScript
202
star
25

grunt-init

Generate project scaffolding from a template.
JavaScript
193
star
26

grunt-contrib-stylus

Compile Stylus files to CSS.
JavaScript
174
star
27

grunt-init-gruntfile

Create a basic Gruntfile with grunt-init.
JavaScript
156
star
28

gruntjs.com

Grunt website
Less
155
star
29

grunt-contrib-jst

Compile underscore templates to JST file.
JavaScript
113
star
30

grunt-lib-phantomjs

Grunt and PhantomJS, sitting in a tree.
JavaScript
93
star
31

grunt-next

Grunt v1.0 alpha
JavaScript
84
star
32

grunt-docs

Grunt documentation. https://github.com/gruntjs/gruntjs.com
79
star
33

grunt-init-gruntplugin

Create a gruntplugin module with grunt-init, including Nodeunit unit tests.
JavaScript
77
star
34

grunt-contrib-yuidoc

Compile YUIDoc Documentation.
JavaScript
75
star
35

grunt-contrib-nodeunit

Run Nodeunit unit tests.
JavaScript
70
star
36

grunt-init-jquery

Create a jQuery plugin with grunt-init, including QUnit unit tests.
JavaScript
58
star
37

grunt-contrib-symlink

Create symbolic links.
JavaScript
56
star
38

grunt-init-node

Create a Node.js module with grunt-init, including Nodeunit unit tests.
JavaScript
55
star
39

grunt-contrib-bump

A work-in-progress Grunt plugin for bumping a version number in JSON files.
JavaScript
52
star
40

grunt-init-commonjs

Create a commonjs module with grunt-init, including Nodeunit unit tests.
JavaScript
17
star
41

grunt-contrib-internal

Internal tasks for managing the grunt-contrib project.
JavaScript
16
star
42

grunt-init-gruntfile-sample

This is sample output generated by the grunt-init "gruntfile" template.
JavaScript
14
star
43

grunt-init-jquery-sample

This is sample output generated by the grunt-init "jquery" template.
JavaScript
12
star
44

grunt-lib-contrib

Common functionality shared across grunt-contrib tasks.
JavaScript
12
star
45

example-subgrunt

Run a Gruntfile in multiple subdirectories.
JavaScript
11
star
46

grunt-contrib-mincss

Renamed to grunt-contrib-cssmin.
9
star
47

grunt-init-gruntplugin-sample

This is sample output generated by the grunt-init "gruntplugin" template.
JavaScript
9
star
48

grunt-init-node-sample

This is sample output generated by the grunt-init "node" template.
JavaScript
8
star
49

grunt-known-options

The known options used in Grunt
JavaScript
7
star
50

grunt-init-commonjs-sample

This is sample output generated by the grunt-init "commonjs" template.
JavaScript
7
star
51

clone-repos

Quickly clone all gruntjs repos (for grunt development)
Ruby
6
star
52

grunt-lib-legacyhelpers

Some old grunt helpers provided for backwards compatability.
JavaScript
6
star
53

grunt-legacy-util

deprecated utility methods
JavaScript
5
star
54

grunt-legacy-log

The Grunt logger.
JavaScript
5
star
55

rfcs

RFCs for changes to Grunt
4
star
56

grunt-legacy-log-utils

Static methods for the Grunt 0.4.x logger.
JavaScript
4
star
57

grunt-plugin-list

[Deprecated] Generates a list of all grunt plugins as json
JavaScript
4
star
58

grunt-legacy-event-logger

Event logger for Grunt legacy libs.
JavaScript
3
star
59

grunt-legacy-config

Grunt's config methods, as a standalone library.
JavaScript
2
star
60

grunt-legacy-option

Grunt's option methods, as a standalone library.
JavaScript
1
star
61

grunt-legacy-cli

Grunt's CLI methods, as a standalone library.
JavaScript
1
star
62

grunt-legacy-task

Grunt's task methods, as a standalone library.
JavaScript
1
star