mirror of
https://github.com/Redocly/redoc.git
synced 2025-02-16 18:00:33 +03:00
Add basic e2e tests
This commit is contained in:
parent
a81caaf8ad
commit
4e2be888dc
34
build/tasks/e2e.js
Normal file
34
build/tasks/e2e.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
var gulp = require('gulp');
|
||||
var gp = require('gulp-protractor');
|
||||
var browserSync = require('browser-sync').create('bs-e2e');
|
||||
|
||||
gulp.task('test-server', function (done) {
|
||||
browserSync.init({
|
||||
open: false,
|
||||
notify: false,
|
||||
port: 3000,
|
||||
ghostMode: false,
|
||||
server: {
|
||||
baseDir: './tests/e2e',
|
||||
routes: {
|
||||
'/dist': './dist',
|
||||
'/swagger.json': './demo/swagger.json'
|
||||
},
|
||||
}
|
||||
}, done);
|
||||
});
|
||||
|
||||
|
||||
gulp.task('e2e', ['test-server'], function(done) {
|
||||
gulp.src(['tests/e2e/**/*.js'], { read:false })
|
||||
.pipe(gp.protractor({
|
||||
configFile: './protractor.conf.js'
|
||||
})).on('error', function(e) {
|
||||
browserSync.exit();
|
||||
throw e;
|
||||
done();
|
||||
}).on('end', function() {
|
||||
browserSync.exit();
|
||||
done();
|
||||
});
|
||||
});
|
|
@ -54,7 +54,7 @@ module.exports = function (config) {
|
|||
|
||||
jspm: {
|
||||
config: 'system.config.js',
|
||||
loadFiles: ['tests/**/*.spec.js', 'tests/helpers.js', 'lib/**/*.js'],
|
||||
loadFiles: ['tests/unit/*.spec.js', 'tests/helpers.js', 'lib/**/*.js'],
|
||||
serveFiles: ['tests/schemas/**/*.json', 'lib/**/*.html', '.tmp/lib/**/*.css'],
|
||||
nocache: true
|
||||
},
|
||||
|
|
|
@ -84,6 +84,7 @@
|
|||
"karma-should": "^1.0.0",
|
||||
"karma-sinon": "^1.0.4",
|
||||
"phantomjs": "^1.9.19",
|
||||
"protractor": "^3.0.0",
|
||||
"reflect-metadata": "^0.1.2",
|
||||
"require-dir": "^0.3.0",
|
||||
"run-sequence": "^1.1.5",
|
||||
|
|
23
protractor.conf.js
Normal file
23
protractor.conf.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
'use strict';
|
||||
|
||||
const loadJson = require('./tests/e2e/helpers').loadJson;
|
||||
exports.config = {
|
||||
specs: ['./tests/e2e/**/*.js'],
|
||||
capabilities: {
|
||||
browserName: 'chrome'
|
||||
},
|
||||
baseUrl: 'http://localhost:3000',
|
||||
framework: 'jasmine2',
|
||||
onPrepare: function() {
|
||||
// load APIs.guru list
|
||||
return loadJson('https://apis-guru.github.io/api-models/api/v1/list.json').then((list) => {
|
||||
global.apisGuruList = list;
|
||||
});
|
||||
},
|
||||
directConnect: true,
|
||||
useAllAngular2AppRoots: true,
|
||||
jasmineNodeOpts: {
|
||||
showTiming: true,
|
||||
showColors: true
|
||||
}
|
||||
};
|
9
tests/e2e/.eslintrc
Normal file
9
tests/e2e/.eslintrc
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"parser": "babel-eslint",
|
||||
"extends": "eslint:recommended",
|
||||
"env": {
|
||||
"node": true,
|
||||
"jasmine": true,
|
||||
"protractor": true
|
||||
}
|
||||
}
|
BIN
tests/e2e/favicon.ico
Normal file
BIN
tests/e2e/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 318 B |
55
tests/e2e/helpers.js
Normal file
55
tests/e2e/helpers.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
'use strict';
|
||||
|
||||
var https = require('https');
|
||||
|
||||
function loadJson(url) {
|
||||
let promise = new Promise((resolve, reject) => {
|
||||
https.get(url, function(res){
|
||||
var body = '';
|
||||
|
||||
res.on('data', function(chunk){
|
||||
body += chunk;
|
||||
});
|
||||
|
||||
res.on('end', function(){
|
||||
let resp = JSON.parse(body);
|
||||
resolve(resp);
|
||||
});
|
||||
}).on('error', function(e){
|
||||
reject(e);
|
||||
});
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
|
||||
//copied from angular/modules/angular2/src/testing/e2e_util.ts
|
||||
function verifyNoBrowserErrors() {
|
||||
// Bug in ChromeDriver: Need to execute at least one command
|
||||
// so that the browser logs can be read out!
|
||||
browser.executeScript('1+1');
|
||||
browser.manage().logs().get('browser').then(function(browserLog) {
|
||||
var filteredLog = browserLog.filter(function(logEntry) {
|
||||
if (logEntry.level.value >= browser.webdriver.logging.Level.INFO.value) {
|
||||
//console.log('>> ' + logEntry.message);
|
||||
}
|
||||
return logEntry.level.value > browser.webdriver.logging.Level.WARNING.value;
|
||||
});
|
||||
expect(filteredLog.length).toEqual(0);
|
||||
});
|
||||
}
|
||||
|
||||
function scrollToEl(selector) {
|
||||
let script = `
|
||||
document.querySelector('${selector}').scrollIntoView(true);
|
||||
window.scrollBy(0, 10);
|
||||
`;
|
||||
|
||||
return browser.driver.executeScript(script);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
loadJson: loadJson,
|
||||
verifyNoBrowserErrors: verifyNoBrowserErrors,
|
||||
scrollToEl: scrollToEl
|
||||
}
|
19
tests/e2e/index.html
Normal file
19
tests/e2e/index.html
Normal file
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>ReDoc</title>
|
||||
</head>
|
||||
<body>
|
||||
<redoc scroll-y-offset="body > nav">
|
||||
Loading...
|
||||
</redoc>
|
||||
|
||||
<!-- ReDoc built file with all dependencies included -->
|
||||
<script src="dist/redoc.full.min.js"> </script>
|
||||
<script>
|
||||
/* init redoc */
|
||||
var url = window.location.search.substr(5) || 'swagger.json';
|
||||
Redoc.init(decodeURIComponent(url));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
53
tests/e2e/redoc.spec.js
Normal file
53
tests/e2e/redoc.spec.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
'use strict';
|
||||
const verifyNoBrowserErrors = require('./helpers').verifyNoBrowserErrors;
|
||||
const scrollToEl = require('./helpers').scrollToEl;
|
||||
|
||||
const URL = 'index.html';
|
||||
|
||||
function basicTests(swaggerUrl, title) {
|
||||
describe(`Basic suite for ${title}`, () => {
|
||||
let specUrl = URL;
|
||||
if (swaggerUrl) {
|
||||
specUrl += `?url=${encodeURIComponent(swaggerUrl)}`;
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
verifyNoBrowserErrors();
|
||||
});
|
||||
|
||||
it('should exist redoc element', () => {
|
||||
browser.get(specUrl);
|
||||
let $redoc = $('redoc');
|
||||
expect($redoc.isPresent()).toBe(true);
|
||||
let $methods = $$('method');
|
||||
expect($methods.count()).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
basicTests();
|
||||
|
||||
|
||||
describe('Scroll sync', () => {
|
||||
it('should update active menu entries on page scroll', () => {
|
||||
browser.get(URL);
|
||||
scrollToEl('[tag="store"]').then(function() {
|
||||
expect($('.menu-cat-header.active').getText()).toBe('STORE');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('APIs.guru specs test', ()=> {
|
||||
|
||||
// global.apisGuruList was loaded in onPrepare method of protractor config
|
||||
let apisGuruList = global.apisGuruList;
|
||||
for (let apiName of Object.keys(apisGuruList)) {
|
||||
let apiInfo = apisGuruList[apiName].versions[apisGuruList[apiName].preferred];
|
||||
let url = apiInfo.swaggerUrl;
|
||||
|
||||
// temporary hack due to this issue: https://github.com/substack/https-browserify/issues/6
|
||||
url = url.replace('https://', 'http://');
|
||||
url = url.replace('apis-guru.github.io/', 'apis-guru.github.io:80/');
|
||||
basicTests(url, `${apiName} ${apiInfo.version}`);
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user