Skip to content

Commit 0168893

Browse files
authored
Merge pull request #73 from Kocal/fix/50
fix: Source point to the wrong line of code
2 parents 0f59029 + d04f598 commit 0168893

File tree

13 files changed

+237
-19
lines changed

13 files changed

+237
-19
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## NEXT
44

5+
### Fixes
6+
7+
- Fix documented methods source lines number (#73)
8+
59
### Internals
610

711
- In the folder `example`, write a JSDoc configuration file for each supported template (#74)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<template>
2+
<div>Hello world</div>
3+
</template>
4+
5+
<script>
6+
/**
7+
* My component
8+
*/
9+
export default {
10+
name: 'Component',
11+
methods: {
12+
/**
13+
* Show a dialog
14+
*/
15+
showDialog() {
16+
// ...
17+
}
18+
}
19+
};
20+
</script>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<template>
2+
<div>export default</div>
3+
</template>
4+
5+
<script>
6+
export default {
7+
name: 'Component',
8+
methods: {
9+
/**
10+
* Show a dialog
11+
*/
12+
showDialog() {
13+
// ...
14+
}
15+
}
16+
};
17+
</script>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
3+
4+
<template>
5+
<div>Hello world</div>
6+
</template>
7+
8+
9+
10+
<script>
11+
12+
13+
14+
export default
15+
16+
{
17+
name: 'Component',
18+
19+
methods: {
20+
21+
22+
/**
23+
* Show a dialog
24+
*/
25+
showDialog() {
26+
// ...
27+
}
28+
}
29+
};
30+
</script>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script>
2+
/**
3+
* @vue-data {String} [foo=bar] Foo description
4+
*/
5+
export default {
6+
name: 'ScriptBeforeTemplate',
7+
data() {
8+
return {
9+
foo: 'bar'
10+
};
11+
}
12+
};
13+
</script>
14+
15+
<template>
16+
<div>Hello world!</div>
17+
</template>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const path = require('path');
2+
const fs = require('fs');
3+
const seekExportDefaultLine = require('../../lib/core/seekExportDefaultLine');
4+
5+
const readComponent = (component, cb) => {
6+
const filename = path.join(__dirname, `__fixtures__/methods/${component}.vue`);
7+
8+
fs.readFile(filename, 'utf8', (err, source) => cb(source));
9+
};
10+
11+
describe('core.seekExportDefaultLine', () => {
12+
test('A normal component', (done) => {
13+
readComponent('Component', (source) => {
14+
expect(seekExportDefaultLine(source)).toBe(9);
15+
done();
16+
});
17+
});
18+
19+
test('A normal component with a lot of spaces', (done) => {
20+
readComponent('ComponentWithSpaces', (source) => {
21+
expect(seekExportDefaultLine(source)).toBe(14);
22+
done();
23+
});
24+
});
25+
26+
test('When <script> is before <template>', (done) => {
27+
readComponent('ScriptBeforeTemplate', (source) => {
28+
expect(seekExportDefaultLine(source)).toBe(5);
29+
done();
30+
});
31+
});
32+
test('When `export default` is inside <template>', (done) => {
33+
readComponent('ComponentWithExportDefaultInTemplate', (source) => {
34+
expect(seekExportDefaultLine(source)).toBe(6);
35+
done();
36+
});
37+
});
38+
});

cypress/integration/renderers/default.spec.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,26 @@ describe('Renderers: default', () => {
102102

103103
it('should render methods properly', () => {
104104
cy.contains('h3', 'Methods').should('have.attr', 'class', 'subsection-title');
105-
cy.get('#decrement').contains('decrement()');
106-
cy.get('#increment').contains('increment()');
107-
cy.get('#showDialog').contains('showDialog(counter)');
105+
106+
cy.get('#decrement')
107+
.contains('decrement()')
108+
.next('.description')
109+
.next('.details')
110+
.find('a[href="BetterCounter.vue.html#line43"]', 'line 43');
111+
112+
cy.get('#increment')
113+
.contains('increment()')
114+
.next('.description')
115+
.next('.details')
116+
.find('a[href="BetterCounter.vue.html#line36"]', 'line 36');
117+
118+
cy.get('#showDialog')
119+
.contains('showDialog(counter)')
120+
.next('.description')
121+
.next('h5')
122+
.next('.params')
123+
.next('.details')
124+
.find('a[href="BetterCounter.vue.html#line51"]', 'line 51');
108125

109126
cy.contains('created()').should('not.exist');
110127
});

cypress/integration/renderers/docstrap.spec.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,26 @@ describe('Renderers: docstrap', () => {
102102

103103
it('should render methods properly', () => {
104104
cy.contains('h3', 'Methods').should('have.attr', 'class', 'subsection-title');
105-
cy.get('#decrement').contains('decrement()');
106-
cy.get('#increment').contains('increment()');
107-
cy.get('#showDialog').contains('showDialog(counter)');
105+
cy.get('#decrement')
106+
.contains('decrement()')
107+
.parent()
108+
.next('dd')
109+
.find('.details')
110+
.find('a[href="BetterCounter.vue.html#sunlight-1-line-43"]', 'line 43');
111+
112+
cy.get('#increment')
113+
.contains('increment()')
114+
.parent()
115+
.next('dd')
116+
.find('.details')
117+
.find('a[href="BetterCounter.vue.html#sunlight-1-line-36"]', 'line 36');
118+
119+
cy.get('#showDialog')
120+
.contains('showDialog(counter)')
121+
.parent()
122+
.next('dd')
123+
.find('.details')
124+
.find('a[href="BetterCounter.vue.html#sunlight-1-line-51"]', 'line 51');
108125

109126
cy.contains('created()').should('not.exist');
110127
});

cypress/integration/renderers/minami.spec.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,23 @@ describe('Renderers: minami', () => {
106106

107107
it('should render methods properly', () => {
108108
cy.contains('h3', 'Methods').should('have.attr', 'class', 'subsection-title');
109-
cy.get('#decrement').contains('decrement()');
110-
cy.get('#increment').contains('increment()');
111-
cy.get('#showDialog').contains('showDialog(counter)');
109+
cy.get('#decrement')
110+
.contains('decrement()')
111+
.next('.description')
112+
.next('.details')
113+
.find('a[href="BetterCounter.vue.html#line43"]', 'line 43');
114+
115+
cy.get('#increment')
116+
.contains('increment()')
117+
.next('.description')
118+
.next('.details')
119+
.find('a[href="BetterCounter.vue.html#line36"]', 'line 36');
120+
121+
cy.get('#showDialog')
122+
.contains('showDialog(counter)')
123+
.next('.description')
124+
.next('.details')
125+
.find('a[href="BetterCounter.vue.html#line51"]', 'line 51');
112126

113127
cy.contains('created()').should('not.exist');
114128
});

cypress/integration/renderers/tui.spec.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,17 @@ describe('Renderers: tui', () => {
102102

103103
it('should render methods properly', () => {
104104
cy.contains('h3', 'Methods').should('have.attr', 'class', 'subsection-title');
105-
cy.get('#decrement').contains('decrement()');
106-
cy.get('#increment').contains('increment()');
107-
cy.get('#showDialog').contains('showDialog(counter)');
105+
cy.get('#decrement')
106+
.contains('decrement()')
107+
.contains('a[href="BetterCounter.vue.html#line43"]', 'line 43');
108+
109+
cy.get('#increment')
110+
.contains('increment()')
111+
.contains('a[href="BetterCounter.vue.html#line36"]', 'line 36');
112+
113+
cy.get('#showDialog')
114+
.contains('showDialog(counter)')
115+
.contains('a[href="BetterCounter.vue.html#line51"]', 'line 51');
108116

109117
cy.contains('created()').should('not.exist');
110118
});

0 commit comments

Comments
 (0)