Skip to content

Commit

Permalink
fix: adding vue support broke tests that are not file based (#1058)
Browse files Browse the repository at this point in the history
* fix: adding vue support broke tests that are not file based

fix #1057

* Got the tests and code working for supporting non-file documenting

* Added fresh snapshot
  • Loading branch information
batje authored and tmcw committed Apr 23, 2018
1 parent e5cb9fb commit 9d7bd2e
Show file tree
Hide file tree
Showing 3 changed files with 312 additions and 0 deletions.
281 changes: 281 additions & 0 deletions __tests__/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
27 changes: 27 additions & 0 deletions __tests__/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,30 @@ 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 }], {
shallow: true
});
normalize(data);
expect(data).toMatchSnapshot();
});
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ function buildInternal(inputsAndConfig) {
sourceFile.source = fs.readFileSync(sourceFile.file, 'utf8');
}

if (!sourceFile.file) {
sourceFile.file = '';
}

if (path.extname(sourceFile.file) === '.vue') {
return parseVueScript(sourceFile, config).map(buildPipeline);
}
Expand Down

0 comments on commit 9d7bd2e

Please sign in to comment.