Skip to content
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
*.swo
node_modules
dist
*xunit.xml
116 changes: 38 additions & 78 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*global module:false*/
module.exports = function(grunt) {

grunt.loadNpmTasks('grunt-mocha-test');

// Project configuration.
grunt.initConfig({
// Metadata.
Expand Down Expand Up @@ -53,87 +55,39 @@ module.exports = function(grunt) {
}
}
},
karma: {
unit: {
mochaTest: {
'unit': {
src: 'test/*.js',
options: {
// base path, that will be used to resolve files and exclude
basePath: '',

// frameworks to use
frameworks: ['mocha', 'browserify'],

// list of files / patterns to load in the browser
files: [
'test/support.js',
'test/model.test.js',
'test/geo-point.test.js',
'test/app.test.js'
],

// list of files to exclude
exclude: [

],

// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['dots'],

// web server port
port: 9876,

// cli runner port
runnerPort: 9100,

// 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: 'warn',

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

// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: [
'Chrome'
],

// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,

// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false,

// Browserify config (all optional)
browserify: {
// extensions: ['.coffee'],
ignore: [
'nodemailer',
'passport',
'passport-local',
'superagent',
'supertest'
],
// transform: ['coffeeify'],
// debug: true,
// noParse: ['jquery'],
watch: true,
},

// Add browserify to preprocessors
preprocessors: {'test/*': ['browserify']}
reporter: 'dot',
}
},
'unit-xml': {
src: 'test/*.js',
options: {
reporter: 'xunit',
captureFile: 'xunit.xml'
}
}
},
karma: {
'unit-once': {
configFile: 'test/karma.conf.js',
browsers: [ 'PhantomJS' ],
singleRun: true,
reporters: ['dots', 'junit'],

// increase the timeout for slow build slaves (e.g. Travis-ci)
browserNoActivityTimeout: 30000,

// CI friendly test output
junitReporter: {
outputFile: 'karma-xunit.xml'
},
},
unit: {
configFile: 'test/karma.conf.js',
},
e2e: {
options: {
// base path, that will be used to resolve files and exclude
Expand Down Expand Up @@ -234,4 +188,10 @@ module.exports = function(grunt) {
// Default task.
grunt.registerTask('default', ['browserify']);

grunt.registerTask('test', [
process.env.JENKINS_HOME ? 'mochaTest:unit-xml' : 'mochaTest:unit',
'karma:unit-once']);

// alias for sl-ci-run and `npm test`
grunt.registerTask('mocha-and-karma', ['test']);
};
4 changes: 4 additions & 0 deletions lib/loopback.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ function createApplication() {
function mixin(source) {
for (var key in source) {
var desc = Object.getOwnPropertyDescriptor(source, key);

// Fix for legacy (pre-ES5) browsers like PhantomJS
if (!desc) continue;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't this breaking?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

AFAIK it is not breaking. This check is preventing the following situation:

$ node
> Object.defineProperty({}, 'foo', undefined)
TypeError: Property description must be an object: undefined
    at Function.defineProperty (native)

desc is not defined when the key is not an own property of the source. MDN on getOwnPropertyDescriptor:

Return value
A property descriptor of the given property if it exists on the object, undefined otherwise.

What happens in PhantomJS:

  • for (var key in source) enumerates over bind function
  • the bind function is not an own property, getOwnPropertyDescriptor returns undefined
  • Object.defineProperty throws when the descriptor is not defined


Object.defineProperty(loopback, key, desc);
}
}
Expand Down
38 changes: 21 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
],
"version": "2.0.0-beta3",
"scripts": {
"test": "mocha -R spec"
"test": "grunt mocha-and-karma"
},
"dependencies": {
"debug": "~0.8.1",
Expand All @@ -46,34 +46,38 @@
"canonical-json": "0.0.4"
},
"peerDependencies": {
"loopback-datasource-juggler": "~2.0.0-beta1"
"loopback-datasource-juggler": "~2.0.0-beta2"
},
"devDependencies": {
"browserify": "~4.1.6",
"chai": "~1.9.1",
"cookie-parser": "~1.1.0",
"errorhandler": "~1.0.1",
"serve-favicon": "~2.0.0",
"loopback-datasource-juggler": "~2.0.0-beta1",
"mocha": "~1.20.1",
"strong-task-emitter": "0.0.x",
"supertest": "~0.13.0",
"chai": "~1.9.1",
"loopback-boot": "1.x >=1.1",
"loopback-testing": "~0.2.0",
"browserify": "~4.1.6",
"es5-shim": "^3.4.0",
"grunt": "~0.4.5",
"grunt-browserify": "~2.1.0",
"grunt-contrib-uglify": "~0.4.0",
"grunt-cli": "^0.1.13",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-uglify": "~0.4.0",
"grunt-contrib-watch": "~0.6.1",
"karma-script-launcher": "~0.1.0",
"grunt-karma": "~0.8.3",
"grunt-mocha-test": "^0.11.0",
"karma": "~0.12.16",
"karma-browserify": "~0.2.1",
"karma-chrome-launcher": "~0.1.4",
"karma-firefox-launcher": "~0.1.3",
"karma-html2js-preprocessor": "~0.1.0",
"karma-junit-reporter": "^0.2.2",
"karma-mocha": "^0.1.4",
"karma-phantomjs-launcher": "~0.1.4",
"karma": "~0.12.16",
"karma-browserify": "~0.2.1",
"karma-mocha": "~0.1.3",
"grunt-karma": "~0.8.3"
"karma-script-launcher": "~0.1.0",
"loopback-boot": "1.x >=1.1",
"loopback-datasource-juggler": "~2.0.0-beta2",
"loopback-testing": "~0.2.0",
"mocha": "~1.20.1",
"serve-favicon": "~2.0.0",
"strong-task-emitter": "0.0.x",
"supertest": "~0.13.0"
},
"repository": {
"type": "git",
Expand Down
98 changes: 98 additions & 0 deletions test/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Karma configuration
// http://karma-runner.github.io/0.12/config/configuration-file.html

module.exports = function(config) {
config.set({
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,

// base path, that will be used to resolve files and exclude
basePath: '../',

// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['mocha', 'browserify'],

// list of files / patterns to load in the browser
files: [
'node_modules/es5-shim/es5-shim.js',
'test/support.js',
'test/model.test.js',
'test/geo-point.test.js',
'test/app.test.js'
],

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

// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['dots'],

// web server port
port: 9876,

// cli runner port
runnerPort: 9100,

// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: [
'Chrome'
],

// Which plugins to enable
plugins: [
'karma-browserify',
'karma-mocha',
'karma-phantomjs-launcher',
'karma-chrome-launcher',
'karma-junit-reporter'
],

// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,

// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false,

colors: true,

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

// Uncomment the following lines if you are using grunt's server to run the tests
// proxies: {
// '/': 'http://localhost:9000/'
// },
// URL root prevent conflicts with the site root
// urlRoot: '_karma_'

// Browserify config (all optional)
browserify: {
// extensions: ['.coffee'],
ignore: [
'nodemailer',
'passport',
'passport-local',
'superagent',
'supertest'
],
// transform: ['coffeeify'],
debug: true,
// noParse: ['jquery'],
watch: true,
},

// Add browserify to preprocessors
preprocessors: {'test/*': ['browserify']}
});
};