Skip to content

Latest commit

 

History

History
137 lines (116 loc) · 2.69 KB

jasmine-examples.md

File metadata and controls

137 lines (116 loc) · 2.69 KB

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'
      }
    }
  }
});