mirror of
https://github.com/documentationjs/documentation.git
synced 2026-02-01 14:53:07 +00:00
Testing: Support defining options for fixture tests (#492)
This reads the fixture file and looks for ```js // Options: <JSON> ``` which it uses as the options for documentation.build and documentation.buildSync.
This commit is contained in:
parent
06412eaad8
commit
662c2f96ed
@ -1,3 +1,5 @@
|
||||
// Options: {"inferPrivate": "^_"}
|
||||
|
||||
/**
|
||||
* _p description
|
||||
*/
|
||||
|
||||
@ -1,95 +1,4 @@
|
||||
[
|
||||
{
|
||||
"description": {
|
||||
"type": "root",
|
||||
"children": [
|
||||
{
|
||||
"type": "paragraph",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "_p description",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 15,
|
||||
"offset": 14
|
||||
},
|
||||
"indent": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 15,
|
||||
"offset": 14
|
||||
},
|
||||
"indent": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 15,
|
||||
"offset": 14
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": [],
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"context": {
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 16
|
||||
}
|
||||
}
|
||||
},
|
||||
"errors": [],
|
||||
"name": "_p",
|
||||
"kind": "function",
|
||||
"members": {
|
||||
"instance": [],
|
||||
"static": []
|
||||
},
|
||||
"path": [
|
||||
{
|
||||
"name": "_p",
|
||||
"kind": "function"
|
||||
}
|
||||
],
|
||||
"namespace": "_p"
|
||||
},
|
||||
{
|
||||
"description": {
|
||||
"type": "root",
|
||||
@ -146,22 +55,22 @@
|
||||
"tags": [],
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 6,
|
||||
"line": 8,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"line": 8,
|
||||
"column": 20
|
||||
}
|
||||
},
|
||||
"context": {
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 7,
|
||||
"line": 9,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 12,
|
||||
"line": 14,
|
||||
"column": 1
|
||||
}
|
||||
}
|
||||
@ -227,22 +136,22 @@
|
||||
"tags": [],
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 8,
|
||||
"line": 10,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 8,
|
||||
"line": 10,
|
||||
"column": 22
|
||||
}
|
||||
},
|
||||
"context": {
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 9,
|
||||
"line": 11,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 9,
|
||||
"line": 11,
|
||||
"column": 8
|
||||
}
|
||||
}
|
||||
@ -268,104 +177,6 @@
|
||||
}
|
||||
],
|
||||
"namespace": "C#m"
|
||||
},
|
||||
{
|
||||
"description": {
|
||||
"type": "root",
|
||||
"children": [
|
||||
{
|
||||
"type": "paragraph",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "_p description",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 15,
|
||||
"offset": 14
|
||||
},
|
||||
"indent": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 15,
|
||||
"offset": 14
|
||||
},
|
||||
"indent": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 15,
|
||||
"offset": 14
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": [],
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 10,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 10,
|
||||
"column": 23
|
||||
}
|
||||
},
|
||||
"context": {
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 11,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 11,
|
||||
"column": 9
|
||||
}
|
||||
}
|
||||
},
|
||||
"errors": [],
|
||||
"name": "_p",
|
||||
"kind": "function",
|
||||
"memberof": "C",
|
||||
"scope": "instance",
|
||||
"members": {
|
||||
"instance": [],
|
||||
"static": []
|
||||
},
|
||||
"path": [
|
||||
{
|
||||
"name": "C",
|
||||
"kind": "class"
|
||||
},
|
||||
{
|
||||
"name": "_p",
|
||||
"kind": "function",
|
||||
"scope": "instance"
|
||||
}
|
||||
],
|
||||
"namespace": "C#_p"
|
||||
}
|
||||
],
|
||||
"static": [],
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
||||
|
||||
# \_p
|
||||
|
||||
\_p description
|
||||
|
||||
# C
|
||||
|
||||
C description
|
||||
@ -11,7 +7,3 @@ C description
|
||||
## m
|
||||
|
||||
m description
|
||||
|
||||
## \_p
|
||||
|
||||
\_p description
|
||||
|
||||
@ -5,51 +5,6 @@
|
||||
"type": "html",
|
||||
"value": "<!-- Generated by documentation.js. Update this documentation by updating the source code. -->"
|
||||
},
|
||||
{
|
||||
"depth": 1,
|
||||
"type": "heading",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "_p"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "paragraph",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "_p description",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 15,
|
||||
"offset": 14
|
||||
},
|
||||
"indent": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 15,
|
||||
"offset": 14
|
||||
},
|
||||
"indent": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"depth": 1,
|
||||
"type": "heading",
|
||||
@ -139,51 +94,6 @@
|
||||
},
|
||||
"indent": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"depth": 2,
|
||||
"type": "heading",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "_p"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "paragraph",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "_p description",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 15,
|
||||
"offset": 14
|
||||
},
|
||||
"indent": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 15,
|
||||
"offset": 14
|
||||
},
|
||||
"indent": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
20
test/test.js
20
test/test.js
@ -20,6 +20,18 @@ function makePOJO(ast) {
|
||||
return JSON.parse(JSON.stringify(ast));
|
||||
}
|
||||
|
||||
function readOptionsFromFile(file) {
|
||||
var s = fs.readFileSync(file, 'utf-8');
|
||||
var lines = s.split(/\n/, 20);
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
var m = lines[i].match(/^\/\/\s+Options:\s*(.+)$/);
|
||||
if (m) {
|
||||
return JSON.parse(m[1]);
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
if (fs.existsSync(path.join(__dirname, '../.git'))) {
|
||||
test('git option', function (t) {
|
||||
var file = path.join(__dirname, './fixture/simple.input.js');
|
||||
@ -68,7 +80,7 @@ test('external modules option', function (t) {
|
||||
test('bad input', function (tt) {
|
||||
glob.sync(path.join(__dirname, 'fixture/bad', '*.input.js')).forEach(function (file) {
|
||||
tt.test(path.basename(file), function (t) {
|
||||
documentation.build([file], {}, function (error, res) {
|
||||
documentation.build([file], readOptionsFromFile(file), function (error, res) {
|
||||
t.equal(res, undefined);
|
||||
// make error a serializable object
|
||||
error = JSON.parse(JSON.stringify(error));
|
||||
@ -91,7 +103,7 @@ test('bad input', function (tt) {
|
||||
test('html', function (tt) {
|
||||
glob.sync(path.join(__dirname, 'fixture/html', '*.input.js')).forEach(function (file) {
|
||||
tt.test(path.basename(file), function (t) {
|
||||
documentation.build([file], {}, function (err, result) {
|
||||
documentation.build([file], readOptionsFromFile(file), function (err, result) {
|
||||
t.ifError(err);
|
||||
outputHtml(result, null, function (err, result) {
|
||||
t.ifError(err);
|
||||
@ -119,7 +131,7 @@ test('html', function (tt) {
|
||||
test('outputs', function (ttt) {
|
||||
glob.sync(path.join(__dirname, 'fixture', '*.input.js')).forEach(function (file) {
|
||||
ttt.test(path.basename(file), function (tt) {
|
||||
documentation.build([file], {}, function (err, result) {
|
||||
documentation.build([file], readOptionsFromFile(file), function (err, result) {
|
||||
tt.ifError(err);
|
||||
|
||||
tt.test('markdown', function (t) {
|
||||
@ -174,7 +186,7 @@ test('outputs', function (ttt) {
|
||||
test('outputs - sync', function (ttt) {
|
||||
glob.sync(path.join(__dirname, 'fixture/sync', '*.input.js')).forEach(function (file) {
|
||||
ttt.test(path.basename(file), function (tt) {
|
||||
var result = documentation.buildSync([file]);
|
||||
var result = documentation.buildSync([file], readOptionsFromFile(file));
|
||||
|
||||
tt.test('markdown', function (t) {
|
||||
outputMarkdown(result, {}, function (err, result) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user