Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example: commonjs/node based approach #44

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"jQuery",
"$",
"describe",
"ddescribe",
"it",
"iit",
"expect",
"beforeEach",
"afterEach",
Expand Down
21 changes: 6 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

Extensions to the Jasmine test framework for use with [Flight](https://github.com/flightjs/flight)

# Getting started
# Installation

Include [jasmine-flight.js](https://raw.github.com/flightjs/jasmine-flight/master/lib/jasmine-flight.js)
in your app and load it in your test runner.

Or install it with [Bower](http://bower.io/):
```bash
npm install --save-dev jasmine-flight
```

```bash
bower install --save-dev jasmine-flight
Expand All @@ -17,16 +16,8 @@ bower install --save-dev jasmine-flight
[jasmine](https://github.com/pivotal/jasmine) and
[jasmine-jquery](https://github.com/velesin/jasmine-jquery)

jasmine-flight assumes you'll be using RequireJS to load Flight modules, and
that you've configured the Flight directory path. For example:

```javascript
requirejs.config({
paths: {
flight: 'bower_components/flight'
}
});
```
`jasmine-flight` assumes you'll be loading Flight modules with a module loader
than implements `require`.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

than that


## Components

Expand Down
50 changes: 17 additions & 33 deletions lib/jasmine-flight.js → index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
* Licensed under the MIT License
*/

(function (root) {

(function (root, jasmine) {
'use strict';

var flight = require('flightjs');

jasmine.flight = {};

/**
Expand Down Expand Up @@ -49,13 +52,9 @@
this.component = (new this.Component()).initialize(this.$node, options);
};

var requireCallback = function (registry, Component) {
registry.reset();
this.Component = Component;
flight.registry.reset();
this.Component = require(componentPath);
done();
}.bind(this);

require(['flight/lib/registry', componentPath], requireCallback);
});

afterEach(function (done) {
Expand All @@ -64,17 +63,14 @@
this.$node = null;
}

var requireCallback = function (defineComponent) {

if (this.component) {
this.component = null;
}

this.Component = null;
defineComponent.teardownAll();
require('flightjs').component.teardownAll();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require('flightjs') -> flight

done();
}.bind(this);

require(['flight/lib/component'], requireCallback);
});

specDefinitions.apply(this);
Expand Down Expand Up @@ -130,13 +126,9 @@
this.component = (new this.Component()).initialize(this.$node, options);
};

var requireCallback = function (registry, defineComponent, Mixin) {
registry.reset();
this.Component = defineComponent(function () {}, Mixin);
flight.registry.reset();
this.Component = flight.component(function () {}, require(mixinPath));
done();
}.bind(this);

require(['flight/lib/registry', 'flight/lib/component', mixinPath], requireCallback);
});

afterEach(function (done) {
Expand All @@ -145,17 +137,13 @@
this.$node = null;
}

var requireCallback = function (defineComponent) {
if (this.component) {
this.component = null;
}

this.Component = null;
defineComponent.teardownAll();
flight.component.teardownAll();
done();
}.bind(this);

require(['flight/lib/component'], requireCallback);
});

specDefinitions.apply(this);
Expand Down Expand Up @@ -186,12 +174,8 @@
beforeEach(function (done) {
this.module = null;

var requireCallback = function (module) {
this.module = module;
this.module = require(modulePath);
done();
}.bind(this);

require([modulePath], requireCallback);
});

specDefinitions.apply(this);
Expand Down Expand Up @@ -363,7 +347,7 @@
pass: wasTriggeredWithData
};

result.message = function () {
result.message = (function () {
var $pp = function (obj) {
var description;
var attr;
Expand Down Expand Up @@ -397,7 +381,7 @@
'Expected event ' + eventName + ' not to have been triggered on ' + $pp(selector)
];
}
}();
}());

return result;

Expand All @@ -415,7 +399,7 @@
pass: wasTriggered
};

result.message = function () {
result.message = (function () {
var $pp = function (obj) {
var description;
var attr;
Expand Down Expand Up @@ -448,7 +432,7 @@
'Expected event ' + eventName + ' not to have been triggered on ' + $pp(selector)
];
}
}();
}());

return result;
}
Expand Down Expand Up @@ -505,4 +489,4 @@
jasmine.flight.events.cleanUp();
});

}(this));
}(this, this.jasmine));
57 changes: 28 additions & 29 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,49 @@ module.exports = function (config) {
'use strict';

config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
frameworks: [
'jasmine',
'commonjs'
],

preprocessors: {
'index.js': ['commonjs'],
'test/**/*.js': ['commonjs'],
'node_modules/flightjs/*.js': ['commonjs'],
'node_modules/flightjs/lib/*.js': ['commonjs']
},

// list of files / patterns to load in the browser
files: [
// es5 shim for PhantomJS & IE8 & below
'bower_components/es5-shim/es5-shim.js',
'bower_components/es5-shim/es5-sham.js',
// hack to load RequireJS after the shim libs
'node_modules/requirejs/require.js',
'node_modules/karma-requirejs/lib/adapter.js',
// jQuery
'bower_components/jquery/dist/jquery.js',
// jquery
'node_modules/flightjs/node_modules/jquery/dist/jquery.js',
// jasmine-jquery
'bower_components/jasmine-jquery/lib/jasmine-jquery.js',
// jasmine-flight (what we're actually testing!)
'lib/jasmine-flight.js',
'node_modules/jasmine-jquery/lib/jasmine-jquery.js',
// flight
{pattern: 'bower_components/flight/**/*.js', included: false},
// specs
{pattern: 'test/spec/**/*.js', included: false},
// mocks
{pattern: 'test/mock/**/*.js', included: false},
// test runner
'test/test-main.js',
'node_modules/flightjs/*.js',
'node_modules/flightjs/lib/*.js',
// library
'index.js',
// tests
'test/mock/**/*.js',
'test/spec/**/*.js'
],

// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: [
'Chrome'
],
// Start these browsers
// CLI --browsers Chrome, Firefox, Safari
browsers: [process.env.TRAVIS ? 'Firefox' : 'Chrome'],

// use dots reporter, as travis terminal does not support escaping sequences
// possible values: 'dots', 'progress'
// CLI --reporters progress
reporters: [process.env.TRAVIS ? 'dots' : 'progress'],

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
{
"name": "jasmine-flight",
"version": "3.0.0",
"dependencies": {
"flightjs": "git://github.com/flightjs/flight.git#0e390c8900567a4b14f8f81316a7fbab218a7847",
"jasmine-jquery": "git://github.com/velesin/jasmine-jquery.git"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lock down to fixed point

},
"devDependencies": {
"karma": "~0.12.6",
"karma-cli": "~0.0.4",
"karma-jasmine": "~0.2.0",
"requirejs": "^2.1.14",
"karma-requirejs": "~0.2.2",
"karma-chrome-launcher": "~0.1.4",
"karma-firefox-launcher": "~0.1.3"
"karma-firefox-launcher": "~0.1.3",
"karma-commonjs": "0.0.10"
},
"scripts": {
"test": "./node_modules/.bin/karma start --browsers Firefox --single-run"
"test": "./node_modules/.bin/karma start --single-run",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use karma since karma-cli is locally installed

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to use karma start --single-run instead. On npm install, npm adds the .bin folder to your PATH.

karma start --single-run won't work unless you have karma installed globally, but npm run test will Do The Right Thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, commented on the same thing. fyi, karma doesn't export their binary – karma-runner/karma#1078 – but when you install karma-cli it acts as you'd expect.

"watch": "./node_modules/.bin/karma start"
},
"repository": {
"type": "git",
Expand Down
8 changes: 2 additions & 6 deletions test/mock/example.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
define(function (require) {
'use strict';
var flight = require('flightjs');

var defineComponent = require('flight/lib/component');
module.exports = flight.component(Example);

function Example() {
this.defaultAttrs({
param: 'defaultParam'
});
}

return defineComponent(Example);
});
6 changes: 2 additions & 4 deletions test/mock/example_mixin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
define(function () {
return function Mixin() {
module.exports = function Mixin() {
this.defaultAttrs({
param: 'defaultParam'
});
}
});
};
16 changes: 5 additions & 11 deletions test/spec/describe_component.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
/*global describeComponent, setupComponent*/
var flight = require('flightjs');
var Example = require('../mock/example');

define(function (require) {
'use strict';

var defineComponent = require('flight/lib/component');
var Example = require('mock/example');

describeComponent('mock/example', function () {
describeComponent('./test/mock/example', function () {
describe('this.Component', function () {
it('should be an Example component', function () {
expect(this.Component).toEqual(Example);
Expand All @@ -29,11 +24,11 @@ define(function (require) {
});
});

describe('defineComponent.teardownAll()', function () {
describe('flight.component.teardownAll()', function () {
var result = [];

beforeEach(function () {
spyOn(defineComponent, 'teardownAll').and.callFake(function () {
spyOn(flight.component, 'teardownAll').and.callFake(function () {
result.push('call');
});
});
Expand Down Expand Up @@ -145,4 +140,3 @@ define(function (require) {
});
});
});
});
13 changes: 4 additions & 9 deletions test/spec/describe_mixin.spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
/*global describeComponent, setupComponent*/

define(function (require) {
'use strict';
var flight = require('flightjs');

var defineComponent = require('flight/lib/component');
var Example = require('mock/example');

describeMixin('mock/example_mixin', function () {
describe('defineComponent.teardownAll()', function () {
describeMixin('./test/mock/example_mixin', function () {
describe('flight.component.teardownAll()', function () {
var result = [];

beforeEach(function () {
spyOn(defineComponent, 'teardownAll').and.callFake(function () {
spyOn(flight.component, 'teardownAll').and.callFake(function () {
result.push('call');
});
});
Expand Down Expand Up @@ -123,4 +119,3 @@ define(function (require) {
});
});
});
});
4 changes: 0 additions & 4 deletions test/spec/spy-on-event.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/*global spyOnEvent*/

define(function (require) {
'use strict';

describe('spyOnEvent', function () {
it('returns a spy', function () {
var spy = spyOnEvent(document, 'test-event');
Expand Down Expand Up @@ -78,4 +75,3 @@ define(function (require) {
expect(this.spy).toHaveBeenTriggeredOnAndWithFuzzy(document, {test2: null});
});
});
});
Loading