Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
Avoid too many repeatations
  • Loading branch information
mohsen1 committed Feb 28, 2015
1 parent 98eaa42 commit 59c6af5
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 64 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@
"swagger-client": "2.1.9-M1"
},
"devDependencies": {
"chai": "^1.10.0",
"cors": "^2.1.1",
"docco": "^0.4.0",
"chai": "^2.1.0",
"cors": "^2.5.3",
"docco": "^0.7.0",
"event-stream": "^3.2.2",
"express": "^3.20.0",
"express": "^4.12.0",
"gulp": "^3.8.11",
"gulp-clean": "^0.3.1",
"gulp-coffee": "^2.3.1",
"gulp-concat": "^2.5.2",
"gulp-connect": "^2.2.0",
"gulp-declare": "^0.3.0",
"gulp-handlebars": "^3.0.1",
"gulp-header": "1.2.2",
"gulp-header": "^1.2.2",
"gulp-less": "^3.0.1",
"gulp-order": "^1.1.1",
"gulp-rename": "^1.2.0",
"gulp-uglify": "^1.1.0",
"gulp-util": "^3.0.4",
"gulp-watch": "^4.1.1",
"gulp-wrap": "^0.10.1",
"gulp-wrap": "^0.11.0",
"http-server": "^0.7.5",
"less": "^1.4.2",
"less": "^2.4.0",
"mocha": "^2.1.0",
"selenium-webdriver": "^2.45.0"
}
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/driver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Web driver manager
*/

var webdriver = require('selenium-webdriver');

var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.firefox()).build();

module.exports = driver;
41 changes: 41 additions & 0 deletions test/e2e/servers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Swagger UI and Specs Servers
*/
var path = require('path')
var createServer = require('http-server').createServer;

var dist = path.join(__dirname, '..', '..', 'dist');
var specs = path.join(__dirname, '..', '..', 'test', 'specs');
var DOCS_PORT = 8080;
var SPEC_SERVER_PORT = 8081;

var driver = require('./driver');

var headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept'
};

var swaggerUI;
var specServer;

module.exports.start = function (specsLocation, done) {
swaggerUI = createServer({ root: dist, headers: headers });
specServer = createServer({ root: specs, headers: headers });

swaggerUI.listen(DOCS_PORT);
specServer.listen(SPEC_SERVER_PORT);

var swaggerSpecLocation = encodeURIComponent('http://localhost:' + SPEC_SERVER_PORT + specsLocation)
var url = 'http://localhost:' + DOCS_PORT + '/index.html?url=' + swaggerSpecLocation;

setTimeout(function(){
driver.get(url);
done();
}, 3000);
};

module.exports.close = function(){
swaggerUI.close();
specServer.close();
}
36 changes: 7 additions & 29 deletions test/e2e/v1.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
var webdriver = require('selenium-webdriver');
var createServer = require('http-server').createServer;
var expect = require('chai').expect;
var path = require('path')

var dist = path.join(__dirname, '..', '..', 'dist');
var specs = path.join(__dirname, '..', '..', 'test', 'specs');
var DOCS_PORT = 8080;
var SPEC_SERVER_PORT = 8081

var headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept'
};
var driver = require('./driver');
var servers = require('./servers');
var webdriver = require('selenium-webdriver');

var elements = [
'swagger-ui-container',
Expand All @@ -25,19 +15,9 @@ var elements = [

describe('swagger 1.x spec tests', function (done) {
this.timeout(10 * 1000);
var swaggerUI, specServer, driver;

before(function () {
swaggerUI = createServer({ root: dist, headers: headers });
specServer = createServer({ root: specs, headers: headers });
driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.firefox()).build();

swaggerUI.listen(DOCS_PORT);
specServer.listen(SPEC_SERVER_PORT);

var swaggerSpecLocation = encodeURIComponent('http://localhost:' + SPEC_SERVER_PORT + '/v1.2/petstore/api-docs')
driver.get('http://localhost:' + DOCS_PORT + '/index.html?url=' + swaggerSpecLocation);
before(function (done) {
servers.start('/v1.2/petstore/api-docs', done);
});

afterEach(function(){
Expand Down Expand Up @@ -113,9 +93,7 @@ describe('swagger 1.x spec tests', function (done) {
});
});

after(function() {
swaggerUI.close();
specServer.close();
driver.quit();
after(function(){
servers.close();
});
});
33 changes: 6 additions & 27 deletions test/e2e/v2.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
var webdriver = require('selenium-webdriver');
var createServer = require('http-server').createServer;
var expect = require('chai').expect;
var path = require('path')

var dist = path.join(__dirname, '..', '..', 'dist');
var specs = path.join(__dirname, '..', '..', 'test', 'specs');
var DOCS_PORT = 8080;
var SPEC_SERVER_PORT = 8081
var webdriver = require('selenium-webdriver');
var driver = require('./driver');
var servers = require('./servers');

var headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept'
};

var elements = [
'swagger-ui-container',
Expand All @@ -25,19 +16,9 @@ var elements = [

describe('swagger 2.0 spec tests', function (done) {
this.timeout(10 * 1000);
var swaggerUI, specServer, driver;

before(function () {
swaggerUI = createServer({ root: dist, headers: headers });
specServer = createServer({ root: specs, headers: headers });
driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.firefox()).build();

swaggerUI.listen(DOCS_PORT);
specServer.listen(SPEC_SERVER_PORT);

var swaggerSpecLocation = encodeURIComponent('http://localhost:' + SPEC_SERVER_PORT + '/v2/petstore.json')
driver.get('http://localhost:' + DOCS_PORT + '/index.html?url=' + swaggerSpecLocation);
before(function (done) {
servers.start('/v2/petstore.json', done);
});

afterEach(function(){
Expand Down Expand Up @@ -130,8 +111,6 @@ describe('swagger 2.0 spec tests', function (done) {
});

after(function() {
swaggerUI.close();
specServer.close();
driver.quit();
servers.close();
});
});
2 changes: 1 addition & 1 deletion test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--recursive
--recursive --timeout 5000

0 comments on commit 59c6af5

Please sign in to comment.