Tom MacWright 11d9045a00 Native Flow, use Jest (#767)
* build: Use Flow syntax without comments.

We're switching to Flow annotations - not Flow comments. This
gives documentation.js the ability to self-document without
JSDoc types and improves our compatibility with tools like
prettier.

Fixes #729. Fixes #709
2017-05-08 20:46:21 -04:00

87 lines
1.6 KiB
JavaScript

/* eslint no-unused-vars: 0 */
var mock = require('mock-fs'),
path = require('path'),
mockRepo = require('../utils').mockRepo,
parse = require('../../src/parsers/javascript'),
github = require('../../src/github');
function toComment(fn, filename) {
return parse(
{
file: filename,
source: fn instanceof Function ? '(' + fn.toString() + ')' : fn
},
{}
).map(github);
}
const root = path.parse(__dirname).root;
function evaluate(fn) {
return toComment(
fn,
root + path.join('my', 'repository', 'path', 'index.js')
);
}
test('github', function() {
mock(mockRepo.master);
expect(
evaluate(function() {
/**
* get one
* @returns {number} one
*/
function getOne() {
return 1;
}
})[0].context.github
).toEqual({
path: 'index.js',
url: 'https://github.com/foo/bar/blob/this_is_the_sha/index.js#L6-L8'
});
mock.restore();
});
test('malformed repository', function() {
mock(mockRepo.malformed);
expect(
evaluate(function() {
/**
* get one
* @returns {number} one
*/
function getOne() {
return 1;
}
})[0].context.github
).toBe(undefined);
mock.restore();
});
test('enterprise repository', function() {
mock(mockRepo.enterprise);
expect(
evaluate(function() {
/**
* get one
* @returns {number} one
*/
function getOne() {
return 1;
}
})[0].context.github
).toEqual({
path: 'index.js',
url: 'https://github.enterprise.com/foo/bar/blob/this_is_the_sha/index.js#L6-L8'
});
mock.restore();
});