mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-13 04:16:34 +03:00
Setup unit tests + few simple tests
This commit is contained in:
parent
a08a3b9df3
commit
5ceb4b8858
13
build/tasks/test.js
Normal file
13
build/tasks/test.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
var gulp = require('gulp');
|
||||||
|
|
||||||
|
var Server = require('karma').Server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run test once and exit
|
||||||
|
*/
|
||||||
|
gulp.task('test', function (done) {
|
||||||
|
new Server({
|
||||||
|
configFile: __dirname + '/../../karma.conf.js',
|
||||||
|
singleRun: true
|
||||||
|
}, done).start();
|
||||||
|
});
|
30
karma.conf.js
Normal file
30
karma.conf.js
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
module.exports = function (config) {
|
||||||
|
config.set({
|
||||||
|
frameworks: ['phantomjs-shim', 'jspm', 'mocha', 'chai', 'sinon'],
|
||||||
|
|
||||||
|
//load angular dependencies and browser polyfills
|
||||||
|
files: [
|
||||||
|
'node_modules/zone.js/dist/zone-microtask.js',
|
||||||
|
'node_modules/babel-polyfill/dist/polyfill.js',
|
||||||
|
'node_modules/reflect-metadata/Reflect.js'
|
||||||
|
],
|
||||||
|
|
||||||
|
jspm: {
|
||||||
|
config: 'system.config.js',
|
||||||
|
loadFiles: ['tests/**/*.spec.js', 'lib/**/*.js'],
|
||||||
|
nocache: true
|
||||||
|
},
|
||||||
|
|
||||||
|
proxies: {
|
||||||
|
'/tests/': '/base/tests/',
|
||||||
|
'/lib/': '/base/lib/',
|
||||||
|
'/jspm_packages/': '/base/jspm_packages/',
|
||||||
|
'/node_modules/': '/base/node_modules/',
|
||||||
|
},
|
||||||
|
reporters: ['mocha'],
|
||||||
|
|
||||||
|
browsers: ['PhantomJS2'],
|
||||||
|
|
||||||
|
browserNoActivityTimeout: 60000
|
||||||
|
});
|
||||||
|
}
|
15
package.json
15
package.json
|
@ -5,7 +5,7 @@
|
||||||
"private": true,
|
"private": true,
|
||||||
"repository": "Rebilly/ReDoc",
|
"repository": "Rebilly/ReDoc",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "gulp lint",
|
"test": "gulp lint && gulp test",
|
||||||
"postinstall": "jspm install",
|
"postinstall": "jspm install",
|
||||||
"start": "gulp serve",
|
"start": "gulp serve",
|
||||||
"build": "gulp build"
|
"build": "gulp build"
|
||||||
|
@ -50,8 +50,11 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"babel": "^6.3.13",
|
||||||
"babel-eslint": "^4.1.3",
|
"babel-eslint": "^4.1.3",
|
||||||
|
"babel-polyfill": "^6.3.14",
|
||||||
"browser-sync": "^2.9.8",
|
"browser-sync": "^2.9.8",
|
||||||
|
"chai": "^3.4.1",
|
||||||
"del": "^2.0.2",
|
"del": "^2.0.2",
|
||||||
"gulp": "^3.9.0",
|
"gulp": "^3.9.0",
|
||||||
"gulp-concat": "^2.6.0",
|
"gulp-concat": "^2.6.0",
|
||||||
|
@ -63,9 +66,19 @@
|
||||||
"gulp-sourcemaps": "^1.6.0",
|
"gulp-sourcemaps": "^1.6.0",
|
||||||
"jshint-stylish": "^2.0.1",
|
"jshint-stylish": "^2.0.1",
|
||||||
"jspm": "^0.16.11",
|
"jspm": "^0.16.11",
|
||||||
|
"karma": "^0.13.15",
|
||||||
|
"karma-chai": "^0.1.0",
|
||||||
|
"karma-chrome-launcher": "^0.2.2",
|
||||||
|
"karma-jspm": "^2.0.2",
|
||||||
|
"karma-mocha": "^0.2.1",
|
||||||
|
"karma-mocha-reporter": "^1.1.3",
|
||||||
|
"karma-phantomjs2-launcher": "^0.3.2",
|
||||||
|
"karma-sinon": "^1.0.4",
|
||||||
|
"mocha": "^2.3.4",
|
||||||
"reflect-metadata": "^0.1.2",
|
"reflect-metadata": "^0.1.2",
|
||||||
"require-dir": "^0.3.0",
|
"require-dir": "^0.3.0",
|
||||||
"run-sequence": "^1.1.4",
|
"run-sequence": "^1.1.4",
|
||||||
|
"sinon": "^1.9.0",
|
||||||
"systemjs-builder": "^0.14.7",
|
"systemjs-builder": "^0.14.7",
|
||||||
"vinyl-paths": "^2.0.0",
|
"vinyl-paths": "^2.0.0",
|
||||||
"zone.js": "^0.5.8"
|
"zone.js": "^0.5.8"
|
||||||
|
|
42
tests/unit/schema-manager.spec.js
Normal file
42
tests/unit/schema-manager.spec.js
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
import SchemaManager from 'lib/utils/SchemaManager';
|
||||||
|
describe("Schema manager", () => {
|
||||||
|
let schemaMgr;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
schemaMgr = new SchemaManager();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should initialize with empty schema", ()=> {
|
||||||
|
schemaMgr.schema.should.be.empty;
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should be a singleton", ()=> {
|
||||||
|
(new SchemaManager()).should.be.equal(schemaMgr);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("load method", ()=> {
|
||||||
|
let req = null;
|
||||||
|
let xhr = null;
|
||||||
|
before(function () {
|
||||||
|
// fake XHR
|
||||||
|
xhr = sinon.useFakeXMLHttpRequest();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it("should return a promise", ()=> {
|
||||||
|
schemaMgr.load('http://test').should.be.instanceof(Promise);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should reject promise for non-existing schema", (done)=> {
|
||||||
|
schemaMgr.load('http://test').then(() => {
|
||||||
|
throw new Error("Should not be called")
|
||||||
|
}, (err) => {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function () {
|
||||||
|
xhr.restore();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user