From f5e369f89ed8dee7344ccec8339d3519bd466e52 Mon Sep 17 00:00:00 2001 From: Reinier Battenberg Date: Mon, 23 Apr 2018 11:47:52 +0200 Subject: [PATCH 1/3] fix: adding vue support broke tests that are not file based fix #1057 --- __tests__/test.js | 25 +++++++++++++++++++++++++ src/index.js | 5 ++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/__tests__/test.js b/__tests__/test.js index 69ba36f0d..ed34157ce 100644 --- a/__tests__/test.js +++ b/__tests__/test.js @@ -241,3 +241,28 @@ test('Vue file', async function() { normalize(data); expect(data).toMatchSnapshot(); }); + +test('Use Source attribute only', async function() { + await pify(chdir)(__dirname); + const documentationSource = ` +/** + * This Vue Component is a test + * @returns {vue-tested} vue-tested component + */ +export default { + + props: { + + /** + * This is a number + */ + myNumber: { + default: 42, + type: Number + } + } +}`; + const data = await documentation.build([{ source: documentationSource }], {}); + normalize(data); + expect(data).toMatchSnapshot(); +}); diff --git a/src/index.js b/src/index.js index 81deb259d..1fd8261a5 100644 --- a/src/index.js +++ b/src/index.js @@ -105,7 +105,10 @@ function buildInternal(inputsAndConfig) { sourceFile.source = fs.readFileSync(sourceFile.file, 'utf8'); } - if (path.extname(sourceFile.file) === '.vue') { + if ( + typeof sourceFile.file === 'string' && + path.extname(sourceFile.file) === '.vue' + ) { return parseVueScript(sourceFile, config).map(buildPipeline); } return parseJavaScript(sourceFile, config).map(buildPipeline); From 83c845b94e5d4ef6f23e37e4271fd635c3476162 Mon Sep 17 00:00:00 2001 From: Reinier Battenberg Date: Mon, 23 Apr 2018 14:30:08 +0200 Subject: [PATCH 2/3] Got the tests and code working for supporting non-file documenting --- __tests__/test.js | 4 +++- src/index.js | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/__tests__/test.js b/__tests__/test.js index ed34157ce..824630635 100644 --- a/__tests__/test.js +++ b/__tests__/test.js @@ -262,7 +262,9 @@ export default { } } }`; - const data = await documentation.build([{ source: documentationSource }], {}); + const data = await documentation.build([{ source: documentationSource }], { + shallow: true + }); normalize(data); expect(data).toMatchSnapshot(); }); diff --git a/src/index.js b/src/index.js index 1fd8261a5..49490e1f2 100644 --- a/src/index.js +++ b/src/index.js @@ -105,10 +105,11 @@ function buildInternal(inputsAndConfig) { sourceFile.source = fs.readFileSync(sourceFile.file, 'utf8'); } - if ( - typeof sourceFile.file === 'string' && - path.extname(sourceFile.file) === '.vue' - ) { + if (!sourceFile.file) { + sourceFile.file = ''; + } + + if (path.extname(sourceFile.file) === '.vue') { return parseVueScript(sourceFile, config).map(buildPipeline); } return parseJavaScript(sourceFile, config).map(buildPipeline); From 64fdd1fd19e53befad656caf9b9ce9ff9501e7f0 Mon Sep 17 00:00:00 2001 From: Reinier Battenberg Date: Mon, 23 Apr 2018 14:32:57 +0200 Subject: [PATCH 3/3] Added fresh snapshot --- __tests__/__snapshots__/test.js.snap | 281 +++++++++++++++++++++++++++ 1 file changed, 281 insertions(+) diff --git a/__tests__/__snapshots__/test.js.snap b/__tests__/__snapshots__/test.js.snap index c13d34517..cbfa02d94 100644 --- a/__tests__/__snapshots__/test.js.snap +++ b/__tests__/__snapshots__/test.js.snap @@ -1,5 +1,286 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Use Source attribute only 1`] = ` +Array [ + Object { + "augments": Array [], + "context": Object { + "loc": SourceLocation { + "end": Position { + "column": 1, + "line": 18, + }, + "start": Position { + "column": 0, + "line": 6, + }, + }, + }, + "description": Object { + "children": Array [ + Object { + "children": Array [ + Object { + "position": Position { + "end": Object { + "column": 29, + "line": 1, + "offset": 28, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "text", + "value": "This Vue Component is a test", + }, + ], + "position": Position { + "end": Object { + "column": 29, + "line": 1, + "offset": 28, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "paragraph", + }, + ], + "position": Object { + "end": Object { + "column": 29, + "line": 1, + "offset": 28, + }, + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "root", + }, + "errors": Array [ + Object { + "message": "could not determine @name for hierarchy", + }, + ], + "examples": Array [], + "loc": SourceLocation { + "end": Position { + "column": 3, + "line": 5, + }, + "start": Position { + "column": 0, + "line": 2, + }, + }, + "members": Object { + "events": Array [], + "global": Array [], + "inner": Array [], + "instance": Array [], + "static": Array [], + }, + "name": "", + "namespace": "", + "params": Array [], + "path": Array [ + Object { + "kind": undefined, + "name": "", + }, + ], + "properties": Array [], + "returns": Array [ + Object { + "description": Object { + "children": Array [ + Object { + "children": Array [ + Object { + "position": Position { + "end": Object { + "column": 21, + "line": 1, + "offset": 20, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "text", + "value": "vue-tested component", + }, + ], + "position": Position { + "end": Object { + "column": 21, + "line": 1, + "offset": 20, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "paragraph", + }, + ], + "position": Object { + "end": Object { + "column": 21, + "line": 1, + "offset": 20, + }, + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "root", + }, + "title": "returns", + "type": Object { + "name": "vue-tested", + "type": "NameExpression", + }, + }, + ], + "sees": Array [], + "tags": Array [ + Object { + "description": "vue-tested component", + "lineNumber": 2, + "title": "returns", + "type": Object { + "name": "vue-tested", + "type": "NameExpression", + }, + }, + ], + "throws": Array [], + "todos": Array [], + }, + Object { + "augments": Array [], + "context": Object { + "loc": SourceLocation { + "end": Position { + "column": 5, + "line": 16, + }, + "start": Position { + "column": 4, + "line": 13, + }, + }, + }, + "description": Object { + "children": Array [ + Object { + "children": Array [ + Object { + "position": Position { + "end": Object { + "column": 17, + "line": 1, + "offset": 16, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "text", + "value": "This is a number", + }, + ], + "position": Position { + "end": Object { + "column": 17, + "line": 1, + "offset": 16, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "paragraph", + }, + ], + "position": Object { + "end": Object { + "column": 17, + "line": 1, + "offset": 16, + }, + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "root", + }, + "errors": Array [], + "examples": Array [], + "loc": SourceLocation { + "end": Position { + "column": 7, + "line": 12, + }, + "start": Position { + "column": 4, + "line": 10, + }, + }, + "members": Object { + "events": Array [], + "global": Array [], + "inner": Array [], + "instance": Array [], + "static": Array [], + }, + "name": "myNumber", + "namespace": "myNumber", + "params": Array [], + "path": Array [ + Object { + "kind": undefined, + "name": "myNumber", + }, + ], + "properties": Array [], + "returns": Array [], + "sees": Array [], + "tags": Array [], + "throws": Array [], + "todos": Array [], + }, +] +`; + exports[`Vue file 1`] = ` Array [ Object {