Skip to content
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.

Commit

Permalink
Cross browser testing in Saucelabs (#100)
Browse files Browse the repository at this point in the history
* Cross browser testing in Saucelabs

* Use proper badge

* Update test scripts
  • Loading branch information
daffl authored Oct 22, 2016
1 parent 8096584 commit d00efd5
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 36 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ language: node_js
node_js: "node"
before_install:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- sh -e /etc/init.d/xvfb start
script: npm run ci
58 changes: 58 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const server = require('./test/server');

module.exports = function (grunt) {
const browsers = [{
browserName: 'firefox',
platform: 'Windows 10'
}, {
browserName: 'googlechrome',
platform: 'linux'
}, {
browserName: 'safari',
platform: 'OS X 10.11',
version: '9.0'
}, {
browserName: 'internet explorer',
platform: 'Windows 8',
version: '10'
}, {
browserName: 'internet explorer',
platform: 'Windows 10',
version: '11'
}, {
browserName: 'internet explorer',
platform: 'Vista',
version: '9'
}
];

grunt.registerTask('server', 'Start the test server', function() {
server.listen(3000).on('listening', () => {
console.log('Test server listening on port 3000');
});
});

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
server: {},

'saucelabs-mocha': {
all: {
options: {
urls: [
'http://127.0.0.1:3000/test/browser/index.html'
],
browsers: browsers,
build: process.env.TRAVIS_JOB_ID,
testname: 'feathers-client mocha tests',
throttled: 1
}
}
},
watch: {}
});

grunt.loadNpmTasks('grunt-saucelabs');

grunt.registerTask('default', [ 'server', 'saucelabs-mocha' ]);
};
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
"watch": "babel --watch -d lib/ src/",
"jshint": "jshint src/. test/. --config",
"mocha": "mocha test/*/**.test.js --compilers js:babel-core/register --recursive --timeout 10000",
"test": "npm run clean && npm run browserify && npm run jshint && npm run mocha"
"saucelabs": "grunt",
"test": "npm run clean && npm run browserify && npm run jshint && npm run mocha",
"ci": "npm test && npm run saucelabs"
},
"directories": {
"lib": "lib"
Expand Down Expand Up @@ -69,14 +71,16 @@
"body-parser": "^1.12.4",
"browserify": "^13.0.0",
"feathers-memory": "^0.8.0",
"grunt": "^1.0.1",
"grunt-cli": "^1.2.0",
"grunt-saucelabs": "^9.0.0",
"jsdom": "8.1.0",
"jshint": "^2.8.0",
"mocha": "^3.0.0",
"node-fetch": "^1.3.3",
"request": "^2.56.0",
"socket.io-client": "^1.3.5",
"superagent": "^2.0.0",
"testee": "^0.2.5",
"uglifyjs": "^2.4.10"
}
}
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

[![Build Status](https://travis-ci.org/feathersjs/feathers-client.png?branch=master)](https://travis-ci.org/feathersjs/feathers-client)

[![Sauce Test Status](https://saucelabs.com/browser-matrix/feathersjs.svg)](https://saucelabs.com/u/feathersjs)

> A client for Feathers services supporting many different transport libraries.
## About
Expand Down
24 changes: 0 additions & 24 deletions test/browser/browser.test.js

This file was deleted.

33 changes: 31 additions & 2 deletions test/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,44 @@
</head>
<body>
<div id="mocha"></div>
<script src="http://localhost:7979/socket.io/socket.io.js" type="text/javascript"></script>
<script src="/socket.io/socket.io.js" type="text/javascript"></script>
<script src="../../node_modules/babel-polyfill/browser.js" type="text/javascript"></script>
<script src="../../node_modules/mocha/mocha.js" type="text/javascript"></script>
<script>mocha.setup('bdd');</script>
<script src="../../dist/feathers.js" type="text/javascript"></script>
<script src="../../dist/browser.test.js" type="text/javascript"></script>
<script>
onload = function(){
mocha.run();
var runner = mocha.run();
var failedTests = [];

runner.on('end', function(){
window.mochaResults = runner.stats;
window.mochaResults.reports = failedTests;
});

runner.on('fail', logFailure);

function logFailure(test, err) {
var flattenTitles = function(test) {
var titles = [];

while (test.parent.title) {
titles.push(test.parent.title);
test = test.parent;
}

return titles.reverse();
};

failedTests.push({
name: test.title,
result: false,
message: err.message,
stack: err.stack,
titles: flattenTitles(test)
});
}
};
</script>
</body>
Expand Down
4 changes: 3 additions & 1 deletion test/browser/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import assert from 'assert';
import baseTests from 'feathers-commons/lib/test/client';

const feathers = window.feathers;
const socket = window.io('http://localhost:7979');
const socket = window.io();

describe('Universal Feathers client browser tests', function() {
const app = feathers()
Expand All @@ -29,6 +29,8 @@ describe('Universal Feathers client browser tests', function() {
hook.result.ran = true;
}
});

after(() => app.service('todos').remove(null));

baseTests(app, 'todos');

Expand Down
30 changes: 24 additions & 6 deletions test/fixture.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import feathers from 'feathers';
import rest from 'feathers-rest';
import bodyParser from 'body-parser';
import memory from 'feathers-memory';
const feathers = require('feathers');
const hooks = require('feathers-hooks');
const rest = require('feathers-rest');
const bodyParser = require('body-parser');
const memory = require('feathers-memory');
const path = require('path');

Object.defineProperty(Error.prototype, 'toJSON', {
value: function () {
Expand Down Expand Up @@ -31,6 +33,7 @@ module.exports = function(configurer) {
});

var app = feathers()
.configure(hooks())
// Set up REST and SocketIO APIs
.configure(rest());

Expand All @@ -42,11 +45,26 @@ module.exports = function(configurer) {
app.use(bodyParser.json())
.use(bodyParser.urlencoded({ extended: true }))
// Host the current directory (for index.html)
.use(feathers.static(__dirname))
.use(feathers.static(path.join(__dirname, '..')))
// Host our Todos service on the /todos path
.use('/todos', todoService);

app.service('todos').create({ text: 'some todo', complete: false }, {}, function() {});
const testTodo = {
text: 'some todo',
complete: false
};
const service = app.service('todos');

service.create(testTodo);
service.after({
remove(hook) {
if(hook.id === null) {
service._uId = 0;
return service.create(testTodo)
.then(() => hook);
}
}
});

return app;
};
7 changes: 7 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const socketio = require('feathers-socketio');
const createApp = require('./fixture');
const app = createApp(function() {
this.configure(socketio());
});

module.exports = app;

0 comments on commit d00efd5

Please sign in to comment.