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

chore(test): setup karma test runner against chrome browser #1007

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
61 changes: 61 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Karma configuration
// Generated on Tue Dec 08 2015 23:01:01 GMT-0800 (Pacific Standard Time)

module.exports = function (config) {
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: ['browserify', 'jasmine'],
Copy link
Member Author

Choose a reason for hiding this comment

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

to resolve commonjs lookup, using karma--browserify to bundling modules. there is karma-commonjs does job without bundling, but has some issues of resolving node_modules (karma-runner/karma-commonjs#29) blocks adaptation.


// list of files / patterns to load in the browser
files: [
'spec/helpers/marble-testing.js',
'spec/helpers/test-helper.js',
'spec/**/*-spec.js'
],

// list of files to exclude
exclude: [
],

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'spec/**/*.js': ['browserify']
},

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],

// web server port
port: 9876,

// enable / disable colors in the output (reporters and logs)
colors: true,

// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,

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

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,

// Concurrency level
// how many browser should be started simultanous
concurrency: 1
});
};
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,13 @@
"istanbul": "0.3.22",
"jasmine": "2.4.1",
"jasmine-core": "2.4.1",
"karma": "0.13.15",
"karma-browserify": "4.4.2",
"karma-chrome-launcher": "0.2.2",
"karma-jasmine": "0.3.6",
"lodash": "3.10.1",
"markdown-doctest": "^0.3.0",
"madge": "^0.5.3",
"markdown-doctest": "^0.3.0",
"mkdirp": "^0.5.1",
"platform": "1.3.0",
"promise": "7.0.3",
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/test-helper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//Fail timeouts faster
//Individual suites/specs should specify longer timeouts if needed.
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
Copy link
Member Author

Choose a reason for hiding this comment

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

timeout interval is increased to safely executed under browser.


var _ = require('lodash');
var root = require('../../dist/cjs/util/root').root;
Expand Down
61 changes: 43 additions & 18 deletions spec/observables/from-promise-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,49 @@ describe('Observable.fromPromise', function () {
});
});

it('should globally throw unhandled errors', function (done) {
var invoked = false;
process.on('uncaughtException', function (reason, p) {
if (invoked) {
return;
}
invoked = true;
expect(reason).toBe('fail');
done();
if (typeof process === 'object' && Object.prototype.toString.call(process) === '[object process]') {
it('should globally throw unhandled errors on process', function (done) {
var invoked = false;
process.on('uncaughtException', function (reason, p) {
if (invoked) {
return;
}
invoked = true;
expect(reason).toBe('fail');
done();
});

Observable.fromPromise(Promise.reject('bad'))
.subscribe(
done.fail,
function (e) {
expect(e).toBe('bad');
throw 'fail';
},
done.fail);
});
} else if (typeof window === 'object' && Object.prototype.toString.call(window) === '[object global]') {
it('should globally throw unhandled errors on window', function (done) {
var invoked = false;
function onException(e) {
if (invoked) {
return;
}
invoked = true;
expect(e).toBe('Uncaught fail');
done();
}

Observable.fromPromise(Promise.reject('bad'))
.subscribe(
done.fail,
function (e) {
expect(e).toBe('bad');
throw 'fail';
},
done.fail);
});
window.onerror = onException;
Copy link
Member Author

Choose a reason for hiding this comment

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

used onerror instead of addeventlistener(error), on chrome eventlistener triggers listener but still prints out error like http://jsbin.com/dipizajumu/3/edit?html,js,console (not first error actually thrown immediately)

Uncaught error
..listener behavior

happens same in Karma makes think global error is uncaught.

I'm feeling I missed some obvious thing and did some dumb thing with code snippet.. :(

Copy link
Member

Choose a reason for hiding this comment

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

on chrome eventlistener triggers listener but still prints out error like http://jsbin.com/dipizajumu/3/edit?html,js,console (not first error actually thrown immediately)

That's right! I was thinking to myself when I was writing that I had learned onerror was what you wanted to use, but I could find any supporting evidence, so I posted addEventListener. :)

Good find.


Observable.fromPromise(Promise.reject('bad'))
.subscribe(
done.fail,
function (e) {
expect(e).toBe('bad');
throw 'fail';
},
done.fail);
});
}
});