mirror of
https://github.com/documentationjs/documentation.git
synced 2026-01-25 14:26:29 +00:00
* feat(core): Switch to Promises everywhere. Adopt Node v4 ES6 Big changes: * Uses template strings where appropriate * Config and argument parsing is unified and there is no such thing as formatterOptions anymore. All user-passed options go through mergeConfig. * The node API surface changed (again): `buildSync` is removed, building operations return Promises. * Now using Flow for internal type annotations. More changes: * Remove buildSync command * feat(inference): Partially implement object shorthand support * Refs #649 * Use Flow annotations to enforce types * Keep flow but switch to comment syntax * Clarify types * More flow improvements * Turn server into class * LinkerStack becomes class too * Fix comment description type * Run flow on lint * Many more flow fixes * More intense flow refactoring * Simplify inference steps * Update inference tests, flow errors down to 1 * Continue refining types * Fix more flow issues * Use 'use strict' everywhere * Make 'ast' property configurable * Fix many tests * Fix more tests * Fix more tests * Fix augments * Test Markdown meta support * Improve test coverage * Switch back from for of to for for speed
94 lines
2.2 KiB
JavaScript
94 lines
2.2 KiB
JavaScript
'use strict';
|
|
|
|
var test = require('tap').test,
|
|
get = require('../utils').get,
|
|
File = require('vinyl'),
|
|
Server = require('../../lib/serve/server');
|
|
|
|
var jsFile = new File({
|
|
cwd: '/',
|
|
base: '/test/',
|
|
path: '/test/file.js',
|
|
contents: new Buffer('var test = 123;')
|
|
});
|
|
|
|
var coffeeFile = new File({
|
|
cwd: '/',
|
|
base: '/test/',
|
|
path: '/test/file.coffee',
|
|
contents: new Buffer('test = 123')
|
|
});
|
|
|
|
var indexFile = new File({
|
|
cwd: '/',
|
|
base: '/test/',
|
|
path: '/test/index.html',
|
|
contents: new Buffer('<html>')
|
|
});
|
|
|
|
test('server - throws on bad port', function (t) {
|
|
t.throws(function () {
|
|
var server = new Server('4001');
|
|
}, 'port must be a number');
|
|
t.throws(function () {
|
|
var server = new Server();
|
|
}, 'port must be provided');
|
|
t.end();
|
|
});
|
|
|
|
test('server', function (t) {
|
|
var server = new Server(4001);
|
|
t.ok(server, 'server is initialized');
|
|
server.start().then(function () {
|
|
|
|
t.test('start can be called more than once, without a callback', function (tt) {
|
|
server.start();
|
|
tt.end();
|
|
});
|
|
|
|
t.test('base path', function (tt) {
|
|
get('http://localhost:4001/file.coffee', function (code) {
|
|
tt.equal(code, 404, 'does not have a file, emits 404');
|
|
tt.end();
|
|
});
|
|
});
|
|
|
|
t.test('base path', function (tt) {
|
|
server.setFiles([coffeeFile]);
|
|
get('http://localhost:4001/file.coffee', function (text) {
|
|
tt.equal(text, 'test = 123', 'emits response');
|
|
tt.end();
|
|
});
|
|
});
|
|
|
|
t.test('reset files', function (tt) {
|
|
server.setFiles([coffeeFile, jsFile]);
|
|
get('http://localhost:4001/file.js', function (text) {
|
|
tt.equal(text, 'var test = 123;', 'emits response');
|
|
tt.end();
|
|
});
|
|
});
|
|
|
|
t.test('index.html special case', function (tt) {
|
|
server.setFiles([coffeeFile, indexFile, jsFile]);
|
|
get('http://localhost:4001/', function (text) {
|
|
tt.equal(text, '<html>', 'sends index.html when / is requested');
|
|
tt.end();
|
|
});
|
|
});
|
|
|
|
t.test('cleanup', function (tt) {
|
|
server.stop().then(function () {
|
|
tt.end();
|
|
});
|
|
});
|
|
|
|
t.test('stop can be called more than once, without a callback', function (tt) {
|
|
server.stop();
|
|
tt.end();
|
|
});
|
|
|
|
t.end();
|
|
});
|
|
});
|