Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Commit

Permalink
(#4) use laxarSpec meta to find runSpec and jasmine
Browse files Browse the repository at this point in the history
  • Loading branch information
x1B committed Jul 15, 2015
1 parent ba2c59c commit b31305b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 49 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Last Changes

- [#4](https://github.com/LaxarJS/karma-laxar/issues/4): use laxarSpec meta to find `runSpec` and jasmine


## v1.1.0-alpha.0

Expand Down
79 changes: 31 additions & 48 deletions lib/adapter_post.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
( function( karma, requirejs, jasmineRequireOrJasmine, laxarSpec, locationPathname ) {
( function( karma, requirejs, laxarSpec, locationPathname ) {


/* Original source:
Expand Down Expand Up @@ -400,56 +400,39 @@ var Jasmine2KarmaReporter = function(karma, jasmineEnv) {
*/
/*jshint browser: true*/
/*global Jasmine1KarmaReporter, Jasmine2KarmaReporter*/
function createStartFn( karma, requirejs, jasmineRequireOrJasmine, laxarSpec ) {
'use strict';

var jasmine;
var jasmineEnv;
if( typeof jasmineRequireOrJasmine.version === 'function' &&
jasmineRequireOrJasmine.version().indexOf( '2.' ) === 0 ) {
// We have jasmine version 2.x.x and thus assume widget tests running with LaxarJS/laxar-testing
// instead of the old LaxarJs/laxar/laxar_testing.
var jasmineRequire = jasmineRequireOrJasmine;
// We need to expose jasmine on the global object for angular-mocks
jasmine = window.jasmine = jasmineRequire.core( jasmineRequire );
jasmineEnv = jasmine.getEnv();

jasmineEnv.addReporter( new Jasmine2KarmaReporter( karma, jasmineEnv ) );

var jasmineInterface = jasmineRequire.interface(jasmine, jasmineEnv);
for( var property in jasmineInterface ) {
if( jasmineInterface.hasOwnProperty( property ) ) {
window[property] = jasmineInterface[property];
}
function createStartFn( karma, requirejs, laxarSpec ) {
'use strict';

var testRunner = laxarSpec.testRunner || 'laxar/laxar_testing';
var jasmineMajor = laxarSpec.jasmineMajorVersion || 1;
var jasmine = ( jasmineMajor > 1 ) ? window.jasmineRequire.core( window.jasmineRequire ) : window.jasmine;
// We need to expose jasmine on the global object for angular-mocks:
window.jasmine = jasmine;

var jasmineEnv = jasmine.getEnv();
jasmineEnv.addReporter( jasmineMajor > 1 ?
new Jasmine2KarmaReporter( karma, jasmineEnv ) :
new Jasmine1KarmaReporter( karma, jasmineEnv ) );

if( jasmineMajor > 1 ) {
var jasmineInterface = jasmineRequire.interface( jasmine, jasmineEnv );
for( var property in jasmineInterface ) {
if( jasmineInterface.hasOwnProperty( property ) ) {
window[ property ] = jasmineInterface[ property ];
}
}
}

return function() {
requirejs.config( laxarSpec.requireConfig );
requirejs( [
'laxar-testing'
], function( testing ) {
testing.runSpec( laxarSpec, jasmineEnv );
} );
};
}

jasmine = window.jasmine = jasmineRequireOrJasmine;
// We have jasmine version 1.x.x and hence assume old style laxar_testing
jasmineEnv = jasmine.getEnv();

jasmineEnv.addReporter( new Jasmine1KarmaReporter( karma, jasmineEnv ) );

return function() {
requirejs.config( laxarSpec.requireConfig );
requirejs( [
'laxar/laxar_testing'
], function( ax ) {
ax.testing.runSpec( laxarSpec, jasmineEnv );
} );
};
return function() {
requirejs.config( laxarSpec.requireConfig );
requirejs( [ testRunner ], function( runner ) {
// Works with both test-runners: 'laxar/laxar_testing' and new 'laxar-testing':
( runner.testing || runner ).runSpec( laxarSpec, jasmineEnv );
} );
};
}

requirejs.load = createPatchedLoad( karma.files, requirejs.load, locationPathname );
karma.start = createStartFn( karma, requirejs, jasmineRequireOrJasmine, laxarSpec );
karma.start = createStartFn( karma, requirejs, laxarSpec );

} )( window.__karma__, window.requirejs, window.jasmineRequire || window.jasmine, window.laxarSpec, window.location.pathname );
} )( window.__karma__, window.requirejs, window.laxarSpec, window.location.pathname );
5 changes: 4 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@ function initLaxar( config ) {

config.preprocessors[ '**/*.html' ] = '';

var jasmineMajorVersion = laxar.jasmineMajorVersion > 1 ? laxar.jasmineMajorVersion : '';
var jasminePath = path.join( baseUrl, rconfig.paths[ 'jasmine' + jasmineMajorVersion ] );

files.unshift.apply( files, [
requireConfig,
specRunner,
require.resolve( 'es5-shim' ),
__dirname + '/adapter_pre.js',
path.resolve( path.join( baseUrl, rconfig.paths.jasmine ) ) + '.js',
path.resolve( jasminePath ) + '.js',
path.resolve( path.join( baseUrl, rconfig.paths.requirejs ) ) + '.js',
__dirname + '/adapter_post.js'
].map( createPattern ) );
Expand Down

0 comments on commit b31305b

Please sign in to comment.