Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

How to move tests into different area? #40

Open
samlevin opened this issue Mar 11, 2015 · 1 comment
Open

How to move tests into different area? #40

samlevin opened this issue Mar 11, 2015 · 1 comment

Comments

@samlevin
Copy link

I love the angularjs-requirejs seed, and have used it several times for a number of projects. For my current project, I'm required to move the tests OUT of the main code-base. I've tried a number of ways to add tests to a separate area, but then I get errors like this:

ERROR [karma]: Uncaught Error: Mismatched anonymous define() module: function (app) {
        describe('app.version module', function() {
                beforeEach(module('app.version'));

                describe('app-version directive', function() {
                        it('should print current version', function() {
                                module(function($provide) {
                                        $provide.value('version', 'TEST_VER');
                                });
                                inject(function($compile, $rootScope) {
                                        var element = $compile('<span app-version></span>')($rootScope);
                                        expect(element.text()).toEqual('TEST_VER');
                               });
                        });
                });
        });
}
http://requirejs.org/docs/errors.html#mismatch
at http://localhost:9876/absoluteC:/Users/zzz/zzz/node_modules/requirejs/require.js?3d820c829606b74b8680ffd0416fdb96d16ec957:141

I know that the project/test environment is correct, because when I move the tests back to their native folders, everything works okay. Here's a sample karma.conf (relevant parts):

    basePath : './public',

    files : [
        {pattern: 'libs/angular/angular.js', included: false},
        {pattern: 'libs/angular-mocks/angular-mocks.js', included: false},
        {pattern: 'libs/angular-translate/angular-translate.min.js', included: false},
        {pattern: 'libs/angular-bootstrap/ui-bootstrap.min.js', included: false},
        {pattern: 'libs/angular-ui-router/release/angular-ui-router.js', included: false},
        {pattern: 'libs/requirejs-text/text.js', included: false},
        {pattern: 'app/shared/version/*.js', included: false},
        {pattern: 'app/service/*.js', included: false},
        {pattern: 'app/model/*.js', included: false},
        {pattern: 'app.js', included: false},
        {pattern: 'test/*.js', included: true},
        'require-config.js'
    ],
@randika-srimal
Copy link

Hi @sjl2024 ,Try this method

  1. Create a folder named "unit-tests" in root of the project and move all tests in to that folder.
  2. Then replace following line in "require-config.js"
    return path.replace(/^\/base\/app\//, '').replace(/\.js$/, '');
    with this line.
    return path.replace(/^\/base\/unit-tests\//, '../unit-tests/').replace(/\.js$/, '');
  3. Include this line at a bottom of files section in "karma.conf.js" file {pattern: 'unit-tests/*.js', included: false},

I also created a project which I use for my own developments.You can check it Here

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants