npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grunt-template-jasmine-requirejs-preloader

v0.0.3

Published

Requirejs + modulesLoader template for grunt-contrib-jasmine + preload plugins

Downloads

6

Readme

RequireJS template for Jasmine unit tests + moduleLoader plugin Build Status

Installation

npm install grunt-template-jasmine-requirejs-preloader

Sample usage

// Example configuration using a single requireJS config file
grunt.initConfig({
  connect: {
    test : {
      port : 8000
    }
  },
  jasmine: {
    taskName: {
      src: 'src/**/*.js',
      options: {
        specs: 'spec/*Spec.js',
        helpers: 'spec/*Helper.js',
        keepRunner: true,
        host: 'http://127.0.0.1:8000/',
        template: require('grunt-template-jasmine-requirejs-preloader'),
        templateOptions: {
          requireConfig: requireConfig,
          preloads: ['modulesLoader']
        }
      }
    }
  }
});

RequireJS template for Jasmine unit tests Build Status

Conflict with grunt-contrib-jasmine 0.6.x

The host package of this template has been upgraded to 0.6.x, which enables Jasmine 2.0 support.

Unfortunately, there's major conflict which can't be solved by code changes.

You cannot use this template in conjunction with 0.6.x of grunt-contrib-jasmine until the host package fixes that conflict.

We released v0.1.9 patch version with strict peerDependencies of host package to notify version conflict.

If you meet that error message, please downgrade your grunt-contrib-jasmine to ~0.5.3 by running below command:

npm install [email protected] --save-dev

Installation

npm install grunt-template-jasmine-requirejs --save-dev

Template Options

templateOptions.version

Type: String Options: 2.0.0 to 2.1.10 or path to a local file system version(relative to Gruntfile.js). Absolute path is allowed as well. Default: latest requirejs version included

The version of requirejs to use.

templateOptions.requireConfigFile

Type String or Array

This can be a single path to a require config file or an array of paths to multiple require config files. The configuration is extracted from the require.config({}) call(s) in the file, and is passed into the require.config({}) call in the template.

Files are loaded from left to right (using a deep merge). This is so you can have a main config and then override specific settings in additional config files (like a test config) without having to duplicate entire requireJS configs.

If requireConfig is also specified then it will be deep-merged onto the settings specified by this directive.

templateOptions.requireConfig

Type: Object

This object is JSON.stringify()-ed ( support serialize Function object ) into the template and passed into var require variable

If requireConfigFile is specified then it will be loaded first and the settings specified by this directive will be deep-merged onto those.

Sample usage

// Example configuration using a single requireJS config file
grunt.initConfig({
  connect: {
    test : {
      port : 8000
    }
  },
  jasmine: {
    taskName: {
      src: 'src/**/*.js',
      options: {
        specs: 'spec/*Spec.js',
        helpers: 'spec/*Helper.js',
        host: 'http://127.0.0.1:8000/',
        template: require('grunt-template-jasmine-requirejs'),
        templateOptions: {
          requireConfigFile: 'src/main.js'
        }
      }
    }
  }
});
// Example configuration using an inline requireJS config
grunt.initConfig({
  connect: {
    test : {
      port : 8000
    }
  },
  jasmine: {
    taskName: {
      src: 'src/**/*.js',
      options: {
        specs: 'spec/*Spec.js',
        helpers: 'spec/*Helper.js',
        host: 'http://127.0.0.1:8000/',
        template: require('grunt-template-jasmine-requirejs'),
        templateOptions: {
          requireConfig: {
            baseUrl: 'src/',
            paths: {
              "jquery": "path/to/jquery"
            },
            shim: {
              'foo': {
                deps: ['bar'],
                exports: 'Foo',
                init: function (bar) {
                  return this.Foo.noConflict();
                }
              }
            },
            deps: ['jquery'],
            callback: function($) {
              // do initialization stuff
              /*

              */
            }
          }
        }
      }
    }
  }
});
// Example using a base requireJS config file and specifying
// overrides with an inline requireConfig file.
grunt.initConfig({
  connect: {
    test : {
      port : 8000
    }
  },
  jasmine: {
    taskName: {
      src: 'src/**/*.js',
      options: {
        specs: 'spec/*Spec.js',
        helpers: 'spec/*Helper.js',
        host: 'http://127.0.0.1:8000/',
        template: require('grunt-template-jasmine-requirejs'),
        templateOptions: {
          requireConfigFile: 'src/main.js',
          requireConfig: {
            baseUrl: 'overridden/baseUrl',
            shim: {
              // foo will override the 'foo' shim in main.js
              'foo': {
                deps: ['bar'],
                exports: 'Foo'
              }
            }
          }
        }
      }
    }
  }
});
// Example using a multiple requireJS config files. Useful for
// testing.
grunt.initConfig({
  connect: {
    test : {
      port : 8000
    }
  },
  jasmine: {
    taskName: {
      src: 'src/**/*.js',
      options: {
        specs: 'spec/*Spec.js',
        helpers: 'spec/*Helper.js',
        host: 'http://127.0.0.1:8000/',
        template: require('grunt-template-jasmine-requirejs'),
        templateOptions: {
          requireConfigFile: ['src/config.js', 'spec/config.js']
          requireConfig: {
            baseUrl: 'overridden/baseUrl'
          }
        }
      }
    }
  }
});

Note the usage of the 'connect' task configuration. You will need to use a task like grunt-contrib-connect if you need to test your tasks on a running server.

RequireJS notes

If you end up using this template, it's worth looking at the source in order to familiarize yourself with how it loads your files. The load process consists of a series of nested require blocks, incrementally loading your source and specs:

require([*YOUR SOURCE*], function() {
  require([*YOUR SPECS*], function() {
    require([*GRUNT-CONTRIB-JASMINE FILES*], function() {
      // at this point your tests are already running.
    }
  }
}

If "callback" function is defined in requireConfig, above code will be injected to the end of body of "callback" definition

templateOptions: {
  callback: function() {
    // suppose we define a module here
    define("config", {
      "endpoint": "/path/to/endpoint"
    })
  }
}

Generated runner page with require configuration looks like:

var require = {
  ...
  callback: function() {
    // suppose we define a module here
    define("config", {
      "endpoint": "/path/to/endpoint"
    })

    require([*YOUR SOURCE*], function() {
      require([*YOUR SPECS*], function() {
        require([*GRUNT-CONTRIB-JASMINE FILES*], function() {
          // at this point your tests are already running.
        }
      }
    }
  }
  ...
}

This automation can help to avoid unexpected dependency order issue

Change Log

  • v0.1.10 03.14.14, Fixed #53, #52, #46, #36 wrong path error when runner outfile is specified at elsewhere
  • v0.1.9, 02.04.14, #57 prevents conflict with grunt-contrib-jasmine 0.6.x, added requirejs 2.1.9 & 2.1.10

Authors / Maintainers

  • Jarrod Overson (@jsoverson)
  • Cloud Chen (@cloudchen)