diff --git a/__tests__/__snapshots__/index.js.snap b/__tests__/__snapshots__/index.js.snap new file mode 100644 index 0000000..109f90e --- /dev/null +++ b/__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`] = ` +" + +## 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\\" + } +]" +`; diff --git a/__tests__/index.js b/__tests__/index.js new file mode 100644 index 0000000..ceeb374 --- /dev/null +++ b/__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); + } +});