fix: adding vue support broke tests that are not file based (#1058)

* 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
This commit is contained in:
Reinier Battenberg 2018-04-23 19:53:07 +02:00 committed by Tom MacWright
parent e5cb9fb6ae
commit 9d7bd2eff6
3 changed files with 312 additions and 0 deletions

View File

@ -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 {

View File

@ -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();
});

View File

@ -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);
}