documentation/test/lib/github.js
Tom MacWright 631c6925d4 feat(core): Switch to Promises everywhere. Adopt Node v4 ES6 (#648)
* 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
2017-01-27 16:14:19 -05:00

84 lines
1.6 KiB
JavaScript

'use strict';
/* eslint no-unused-vars: 0 */
var test = require('tap').test,
mock = require('mock-fs'),
mockRepo = require('./git/mock_repo'),
parse = require('../../lib/parsers/javascript'),
github = require('../../lib/github');
function toComment(fn, filename) {
return parse({
file: filename,
source: fn instanceof Function ? '(' + fn.toString() + ')' : fn
}, {}).map(github);
}
function evaluate(fn) {
return toComment(fn, '/my/repository/path/index.js');
}
test('github', function (t) {
mock(mockRepo.master);
t.deepEqual(evaluate(function () {
/**
* get one
* @returns {number} one
*/
function getOne() {
return 1;
}
})[0].context.github, {
path: 'index.js',
url: 'https://github.com/foo/bar/blob/this_is_the_sha/index.js#L6-L8'
}, 'gets github url');
mock.restore();
t.end();
});
test('malformed repository', function (t) {
mock(mockRepo.malformed);
t.equal(evaluate(function () {
/**
* get one
* @returns {number} one
*/
function getOne() {
return 1;
}
})[0].context.github, undefined, 'does not crash');
mock.restore();
t.end();
});
test('enterprise repository', function (t) {
mock(mockRepo.enterprise);
t.deepEqual(evaluate(function () {
/**
* get one
* @returns {number} one
*/
function getOne() {
return 1;
}
})[0].context.github, {
path: 'index.js',
url: 'https://github.enterprise.com/foo/bar/blob/this_is_the_sha/index.js#L6-L8'
}, 'gets github enterprise url');
mock.restore();
t.end();
});