Merge pull request #344 from strongloop/fix-phantomjs-tests

[2.0] Fix loopback in PhantomJS, fix karma tests
This commit is contained in:
Miroslav Bajtoš 2014-06-26 13:34:21 +02:00
commit dd5360a41a
5 changed files with 162 additions and 95 deletions

1
.gitignore vendored
View File

@ -12,3 +12,4 @@
*.swo *.swo
node_modules node_modules
dist dist
*xunit.xml

View File

@ -1,6 +1,8 @@
/*global module:false*/ /*global module:false*/
module.exports = function(grunt) { module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-mocha-test');
// Project configuration. // Project configuration.
grunt.initConfig({ grunt.initConfig({
// Metadata. // Metadata.
@ -53,87 +55,39 @@ module.exports = function(grunt) {
} }
} }
}, },
karma: { mochaTest: {
unit: { 'unit': {
src: 'test/*.js',
options: { options: {
// base path, that will be used to resolve files and exclude reporter: 'dot',
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']}
} }
}, },
'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: { e2e: {
options: { options: {
// base path, that will be used to resolve files and exclude // base path, that will be used to resolve files and exclude
@ -234,4 +188,10 @@ module.exports = function(grunt) {
// Default task. // Default task.
grunt.registerTask('default', ['browserify']); 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']);
}; };

View File

@ -80,6 +80,10 @@ function createApplication() {
function mixin(source) { function mixin(source) {
for (var key in source) { for (var key in source) {
var desc = Object.getOwnPropertyDescriptor(source, key); var desc = Object.getOwnPropertyDescriptor(source, key);
// Fix for legacy (pre-ES5) browsers like PhantomJS
if (!desc) continue;
Object.defineProperty(loopback, key, desc); Object.defineProperty(loopback, key, desc);
} }
} }

View File

@ -28,7 +28,7 @@
], ],
"version": "2.0.0-beta3", "version": "2.0.0-beta3",
"scripts": { "scripts": {
"test": "mocha -R spec" "test": "grunt mocha-and-karma"
}, },
"dependencies": { "dependencies": {
"debug": "~0.8.1", "debug": "~0.8.1",
@ -46,34 +46,38 @@
"canonical-json": "0.0.4" "canonical-json": "0.0.4"
}, },
"peerDependencies": { "peerDependencies": {
"loopback-datasource-juggler": "~2.0.0-beta1" "loopback-datasource-juggler": "~2.0.0-beta2"
}, },
"devDependencies": { "devDependencies": {
"browserify": "~4.1.6",
"chai": "~1.9.1",
"cookie-parser": "~1.1.0", "cookie-parser": "~1.1.0",
"errorhandler": "~1.0.1", "errorhandler": "~1.0.1",
"serve-favicon": "~2.0.0", "es5-shim": "^3.4.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",
"grunt": "~0.4.5", "grunt": "~0.4.5",
"grunt-browserify": "~2.1.0", "grunt-browserify": "~2.1.0",
"grunt-contrib-uglify": "~0.4.0", "grunt-cli": "^0.1.13",
"grunt-contrib-jshint": "~0.10.0", "grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-uglify": "~0.4.0",
"grunt-contrib-watch": "~0.6.1", "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-chrome-launcher": "~0.1.4",
"karma-firefox-launcher": "~0.1.3", "karma-firefox-launcher": "~0.1.3",
"karma-html2js-preprocessor": "~0.1.0", "karma-html2js-preprocessor": "~0.1.0",
"karma-junit-reporter": "^0.2.2",
"karma-mocha": "^0.1.4",
"karma-phantomjs-launcher": "~0.1.4", "karma-phantomjs-launcher": "~0.1.4",
"karma": "~0.12.16", "karma-script-launcher": "~0.1.0",
"karma-browserify": "~0.2.1", "loopback-boot": "1.x >=1.1",
"karma-mocha": "~0.1.3", "loopback-datasource-juggler": "~2.0.0-beta2",
"grunt-karma": "~0.8.3" "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": { "repository": {
"type": "git", "type": "git",

98
test/karma.conf.js Normal file
View File

@ -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']}
});
};