Skip to content

Commit

Permalink
test: Even more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Sep 15, 2017
1 parent e02b91f commit c6bf13d
Show file tree
Hide file tree
Showing 2 changed files with 264 additions and 0 deletions.
196 changes: 196 additions & 0 deletions __tests__/__snapshots__/index.js.snap
@@ -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 changes: 68 additions & 0 deletions __tests__/index.js
@@ -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);
}
});

0 comments on commit c6bf13d

Please sign in to comment.