mirror of
https://github.com/documentationjs/documentation.git
synced 2026-01-25 14:26:29 +00:00
test: Even more tests
This commit is contained in:
parent
e02b91f8d5
commit
c6bf13db38
196
__tests__/__snapshots__/index.js.snap
Normal file
196
__tests__/__snapshots__/index.js.snap
Normal file
@ -0,0 +1,196 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`build 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
"augments": Array [],
|
||||
"description": Object {
|
||||
"children": Array [
|
||||
Object {
|
||||
"children": Array [
|
||||
Object {
|
||||
"position": Position {
|
||||
"end": Object {
|
||||
"column": 3,
|
||||
"line": 1,
|
||||
"offset": 2,
|
||||
},
|
||||
"indent": Array [],
|
||||
"start": Object {
|
||||
"column": 1,
|
||||
"line": 1,
|
||||
"offset": 0,
|
||||
},
|
||||
},
|
||||
"type": "text",
|
||||
"value": "hi",
|
||||
},
|
||||
],
|
||||
"position": Position {
|
||||
"end": Object {
|
||||
"column": 3,
|
||||
"line": 1,
|
||||
"offset": 2,
|
||||
},
|
||||
"indent": Array [],
|
||||
"start": Object {
|
||||
"column": 1,
|
||||
"line": 1,
|
||||
"offset": 0,
|
||||
},
|
||||
},
|
||||
"type": "paragraph",
|
||||
},
|
||||
],
|
||||
"position": Object {
|
||||
"end": Object {
|
||||
"column": 3,
|
||||
"line": 1,
|
||||
"offset": 2,
|
||||
},
|
||||
"start": Object {
|
||||
"column": 1,
|
||||
"line": 1,
|
||||
"offset": 0,
|
||||
},
|
||||
},
|
||||
"type": "root",
|
||||
},
|
||||
"errors": Array [],
|
||||
"examples": Array [],
|
||||
"loc": SourceLocation {
|
||||
"end": Position {
|
||||
"column": 9,
|
||||
"line": 1,
|
||||
},
|
||||
"start": Position {
|
||||
"column": 0,
|
||||
"line": 1,
|
||||
},
|
||||
},
|
||||
"members": Object {
|
||||
"events": Array [],
|
||||
"global": Array [],
|
||||
"inner": Array [],
|
||||
"instance": Array [],
|
||||
"static": Array [],
|
||||
},
|
||||
"name": "name",
|
||||
"namespace": "name",
|
||||
"params": Array [],
|
||||
"path": Array [
|
||||
Object {
|
||||
"kind": undefined,
|
||||
"name": "name",
|
||||
},
|
||||
],
|
||||
"properties": Array [],
|
||||
"returns": Array [],
|
||||
"sees": Array [],
|
||||
"tags": Array [],
|
||||
"throws": Array [],
|
||||
"todos": Array [],
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`build 2`] = `
|
||||
"<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
||||
|
||||
## name
|
||||
|
||||
hi
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`build 3`] = `
|
||||
"[
|
||||
{
|
||||
\\"description\\": {
|
||||
\\"type\\": \\"root\\",
|
||||
\\"children\\": [
|
||||
{
|
||||
\\"type\\": \\"paragraph\\",
|
||||
\\"children\\": [
|
||||
{
|
||||
\\"type\\": \\"text\\",
|
||||
\\"value\\": \\"hi\\",
|
||||
\\"position\\": {
|
||||
\\"start\\": {
|
||||
\\"line\\": 1,
|
||||
\\"column\\": 1,
|
||||
\\"offset\\": 0
|
||||
},
|
||||
\\"end\\": {
|
||||
\\"line\\": 1,
|
||||
\\"column\\": 3,
|
||||
\\"offset\\": 2
|
||||
},
|
||||
\\"indent\\": []
|
||||
}
|
||||
}
|
||||
],
|
||||
\\"position\\": {
|
||||
\\"start\\": {
|
||||
\\"line\\": 1,
|
||||
\\"column\\": 1,
|
||||
\\"offset\\": 0
|
||||
},
|
||||
\\"end\\": {
|
||||
\\"line\\": 1,
|
||||
\\"column\\": 3,
|
||||
\\"offset\\": 2
|
||||
},
|
||||
\\"indent\\": []
|
||||
}
|
||||
}
|
||||
],
|
||||
\\"position\\": {
|
||||
\\"start\\": {
|
||||
\\"line\\": 1,
|
||||
\\"column\\": 1,
|
||||
\\"offset\\": 0
|
||||
},
|
||||
\\"end\\": {
|
||||
\\"line\\": 1,
|
||||
\\"column\\": 3,
|
||||
\\"offset\\": 2
|
||||
}
|
||||
}
|
||||
},
|
||||
\\"tags\\": [],
|
||||
\\"loc\\": {
|
||||
\\"start\\": {
|
||||
\\"line\\": 1,
|
||||
\\"column\\": 0
|
||||
},
|
||||
\\"end\\": {
|
||||
\\"line\\": 1,
|
||||
\\"column\\": 9
|
||||
}
|
||||
},
|
||||
\\"augments\\": [],
|
||||
\\"examples\\": [],
|
||||
\\"params\\": [],
|
||||
\\"properties\\": [],
|
||||
\\"returns\\": [],
|
||||
\\"sees\\": [],
|
||||
\\"throws\\": [],
|
||||
\\"todos\\": [],
|
||||
\\"name\\": \\"name\\",
|
||||
\\"members\\": {
|
||||
\\"global\\": [],
|
||||
\\"inner\\": [],
|
||||
\\"instance\\": [],
|
||||
\\"events\\": [],
|
||||
\\"static\\": []
|
||||
},
|
||||
\\"path\\": [
|
||||
{
|
||||
\\"name\\": \\"name\\"
|
||||
}
|
||||
],
|
||||
\\"namespace\\": \\"name\\"
|
||||
}
|
||||
]"
|
||||
`;
|
||||
68
__tests__/index.js
Normal file
68
__tests__/index.js
Normal file
@ -0,0 +1,68 @@
|
||||
var documentation = require('../src/');
|
||||
var os = require('os');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
|
||||
function inputs(contents) {
|
||||
var dirEntry = os.tmpdir();
|
||||
var paths = {};
|
||||
for (var filename in contents) {
|
||||
paths[filename] = path.join(dirEntry, '/', filename);
|
||||
fs.writeFileSync(paths[filename], contents[filename]);
|
||||
}
|
||||
return {
|
||||
paths
|
||||
};
|
||||
}
|
||||
|
||||
function cleanup(comments) {
|
||||
comments.forEach(c => {
|
||||
delete c.context;
|
||||
});
|
||||
}
|
||||
|
||||
test('lint', async function() {
|
||||
var { paths } = inputs({
|
||||
'index.js': '/** hi */var name = 1;'
|
||||
});
|
||||
|
||||
const data = await documentation.lint([paths['index.js']], {});
|
||||
expect(data).toEqual('');
|
||||
});
|
||||
|
||||
test('build', async function() {
|
||||
var { paths } = inputs({
|
||||
'index.js': '/** hi */var name = 1;'
|
||||
});
|
||||
|
||||
const data = await documentation.build([paths['index.js']], {});
|
||||
cleanup(data);
|
||||
expect(data).toMatchSnapshot();
|
||||
|
||||
const md = await documentation.formats.md(data);
|
||||
expect(md).toMatchSnapshot();
|
||||
|
||||
const json = await documentation.formats.json(data, {});
|
||||
expect(json).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('expandInputs', async function() {
|
||||
var { paths } = inputs({
|
||||
'index.js': '/** hi */var name = 1;'
|
||||
});
|
||||
|
||||
{
|
||||
const data = await documentation.expandInputs([paths['index.js']], {
|
||||
parseExtension: ['js']
|
||||
});
|
||||
expect(data.length).toEqual(1);
|
||||
}
|
||||
|
||||
{
|
||||
const data = await documentation.expandInputs([paths['index.js']], {
|
||||
parseExtension: ['js'],
|
||||
shallow: true
|
||||
});
|
||||
expect(data.length).toEqual(1);
|
||||
}
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user