Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring Grunt, Jasmine and RequireJS all together

I'm a complete noob with Jasmine and RequireJS so any help is appreciated.

We have the following directory structure

/assets
      /libs <- populated by Jam
      /scripts
/tests

I'm trying to setup Jasmine + Grunt + RequireJS to run my tests however I keep getting the following error, when I run my grunt task grunt jasmine I've reviewed the error on RequireJS site but in my view everything is in place.

Error: scripterror: Illegal path or script error: ['scripts/MyModule']

Here is my Jasmine setup in my gruntfile.js

jasmine: {
    src: 'assets/scripts/**/*.js',
    options: {
        specs: 'tests/*spec.js',
        template: require('grunt-template-jasmine-requirejs'),
        templateOptions: {
            requireConfig: {
                baseUrl: '/assets',
                paths: {
                'jquery': 'libs/jquery/dist/jquery'
                }
            }
        }
    }

Here is a dead simple test spec :)

require(['scripts/MyModule'], function (myModule) {
    'use strict';

    describe('A suite', function() {
        it('should pass this test', function() {
            expect(myModule).not.toBe(null);
        });
    });
});

RequireJS works fine in my project, here is the setup that I run for that...

<script>
var require =
{
    baseUrl: '/assets'
};
</script>
<script src="/assets/libs/require.js"></script>

Where am I going wrong, what can I do to fix it?

like image 315
BarendB Avatar asked Apr 29 '13 21:04

BarendB


1 Answers

Well I got it running, had to make the following change in the Jasmine config in my Gruntfile.js

baseUrl: './assets/'

It needed to step one directory up.

like image 87
BarendB Avatar answered Sep 27 '22 23:09

BarendB