angular-requirejs-seed
angular-requirejs-seed copied to clipboard
How to move tests into different area?
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'
],
Hi @sjl2024 ,Try this method
- Create a folder named "unit-tests" in root of the project and move all tests in to that folder.
- 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$/, '');
- 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