Question

ReferenceError: Can't find variable: affix

I'm trying to run a Jasmine spec and it cannot find affix from jasmine-fixture. My spec isn't using a require, but I haven't seen any references that it is needed.

What is more troublesome is that there isn't any reference to affix or jasmine for that matter in my vendor.js because it is a devDependency only, so I'm not sure how it would be available to the karma runner/jasmine spec.

bower.json:

{
    "name": "af-calendar",
    "version": "0.0.1",
    "main": "public/js/app.js",
    "ignore": [
        "**/.*",
        "node_modules",
        "bower_components"
    ],
    "dependencies": {
        "moment": ">=2.5.1",
        "moment-range": "alienfast/moment-range#3454882ae8e0493b20ff1c6651956b906c8f975d",
        "jquery": ">=1.10.2",
        "jquery-ui": ">=1.10.3",
        "jquery-simulate": "*"
    },
    "devDependencies": {
        "jasmine-jquery": ">=2.0.3",
        "jasmine-fixture": ">=1.2.0"
    },
    "overrides": {
        "jquery-simulate": {
            "main": "jquery.simulate.js",
            "dependencies": {
                "jquery": "*"
            }
        }
    }
}

brunch-config.coffee

exports.config =
    files:
        javascripts:
            joinTo:
                'js/vendor.js': /^(bower_components|vendor)/
                'js/app.js': /^app/

#            pluginHelpers: 'js/app.js'

        stylesheets:
            joinTo:
                'css/vendor.css': /^(vendor|bower_components)/
                'css/app.css': /^app/

#       templates:
#            joinTo: 'js/app.js'

    plugins:
        autoReload:
            enabled:
                js: on
                css: on
                assets: off

        imageoptimizer:
            path: 'images'
            smushit: no

        coffeelint:
            pattern: /^app\/.*\.coffee$/

            options:
#                indentation:
#                    value: 4
#                    level: "warn"
#
                max_line_length:
                    level: "ignore"

    conventions:
        assets: /(assets|vendor\/assets|font)/

Question

I don't want to ship them or have them included in the vendor.js. How do I include/require them for just for my karma/jasmine spec testing?

Was it helpful?

Solution

So it seems that test-only dependencies are loaded via the files section of the karma.conf. While for most code we are used to just including a new dependency in the bower.json (which ends up in the app.js or vendor.js depending on the brunch config), devDependencies are not included in any combined file and must be referenced specifically such as:

    // list of files / patterns to load in the browser
    files: [
        'public/js/**/*.js',
        'bower_components/jasmine-jquery/lib/jasmine-jquery.js',
        'bower_components/jasmine-fixture/dist/jasmine-fixture.js',
        'spec/spec_helper.coffee',
        'spec/**/*.spec.coffee'
    ],      

This is not as convenient as how brunch combines files for vendor.js, and could be better, but the above works for now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top