Skip to content

Commit 5772716

Browse files
silverspectroKocal
authored andcommitted
feat(parser): plain JavaScript files are now being parsed (#128)
- Add tests on js file parsing
1 parent 6b59fda commit 5772716

File tree

14 files changed

+772
-20
lines changed

14 files changed

+772
-20
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
/**
3+
* @vue-prop {String} test - test description
4+
* @vue-data {String} [foo=bar] - Foo description
5+
*/
6+
export default ({
7+
name: 'component',
8+
props: {
9+
test: {
10+
type: String,
11+
},
12+
},
13+
data() {
14+
return {
15+
foo: 'bar',
16+
};
17+
},
18+
methods: {},
19+
computed: {},
20+
});

__tests__/core/seekExportDefaultLine.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,43 @@ const path = require('path');
22
const fs = require('fs');
33
const seekExportDefaultLine = require('../../lib/core/seekExportDefaultLine');
44

5-
const readComponent = (component, cb) => {
6-
const filename = path.join(__dirname, `__fixtures__/methods/${component}.vue`);
5+
const readComponent = (componentPath, cb) => {
6+
const filename = path.join(__dirname, `__fixtures__/methods/${componentPath}`);
77

88
fs.readFile(filename, 'utf8', (err, source) => cb(source));
99
};
1010

1111
describe('core.seekExportDefaultLine', () => {
1212
test('A normal component', (done) => {
13-
readComponent('Component', (source) => {
13+
readComponent('Component.vue', (source) => {
1414
expect(seekExportDefaultLine(source)).toBe(9);
1515
done();
1616
});
1717
});
1818

1919
test('A normal component with a lot of spaces', (done) => {
20-
readComponent('ComponentWithSpaces', (source) => {
20+
readComponent('ComponentWithSpaces.vue', (source) => {
2121
expect(seekExportDefaultLine(source)).toBe(14);
2222
done();
2323
});
2424
});
2525

2626
test('When <script> is before <template>', (done) => {
27-
readComponent('ScriptBeforeTemplate', (source) => {
27+
readComponent('ScriptBeforeTemplate.vue', (source) => {
2828
expect(seekExportDefaultLine(source)).toBe(5);
2929
done();
3030
});
3131
});
3232
test('When `export default` is inside <template>', (done) => {
33-
readComponent('ComponentWithExportDefaultInTemplate', (source) => {
33+
readComponent('ComponentWithExportDefaultInTemplate.vue', (source) => {
3434
expect(seekExportDefaultLine(source)).toBe(6);
3535
done();
3636
});
3737
});
38+
test('When component is js file', (done) => {
39+
readComponent('Component/Component.js', (source) => {
40+
expect(seekExportDefaultLine(source, 'Component.js')).toBe(6);
41+
done();
42+
});
43+
});
3844
});

cypress/integration/templates/default.spec.js

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,169 @@ describe('Template: default', () => {
164164
cy.contains('created()').should('not.exist');
165165
});
166166
});
167+
168+
describe('Template JS: default', () => {
169+
/* eslint-disable newline-per-chained-call */
170+
before(() => {
171+
cy.visit('/../../../example/docs/module-CounterJS.html');
172+
cy.screenshot();
173+
});
174+
175+
it('should renders module name correctly', () => {
176+
cy
177+
.get('.page-title')
178+
.contains('Module: CounterJS');
179+
180+
cy
181+
.get('nav a[href="module-CounterJS.html"]')
182+
.contains('CounterJS');
183+
});
184+
185+
it('should renders props correctly', () => {
186+
const props = [
187+
{
188+
name: '<code>initialCounter</code>',
189+
type: 'Number',
190+
defaultValue: '-',
191+
required: '<b>Yes</b>',
192+
description: '-',
193+
},
194+
{
195+
name: '<code>step</code>',
196+
type: 'Number',
197+
defaultValue: '<code>1</code>',
198+
required: 'No',
199+
description: 'Step',
200+
},
201+
];
202+
203+
cy.get('[data-jsdoc-vuejs="section-props"]').contains('Props');
204+
cy.get('[data-jsdoc-vuejs="table-props"]').as('table-props');
205+
206+
cy
207+
.get('@table-props')
208+
.find('> thead > tr > th')
209+
.contains('Name')
210+
.next().contains('Type')
211+
.next().contains('Default value')
212+
.next().contains('Required?')
213+
.next().contains('Description');
214+
215+
cy
216+
.get('@table-props')
217+
.find('> tbody > tr')
218+
.then(($rows) => {
219+
expect($rows).to.have.length(2);
220+
221+
props.forEach((prop, i) => {
222+
const $row = $rows.eq(i);
223+
const $children = $row.children();
224+
225+
expect($children.eq(0).html()).to.eq(prop.name);
226+
expect($children.eq(1).html()).to.eq(prop.type);
227+
expect($children.eq(2).html()).to.eq(prop.defaultValue);
228+
expect($children.eq(3).html()).to.eq(prop.required);
229+
expect($children.eq(4).html()).to.eq(prop.description);
230+
});
231+
});
232+
});
233+
234+
it('should renders data correctly', () => {
235+
const data = [
236+
{
237+
name: '<code>counter</code>',
238+
type: 'Number',
239+
defaultValue: '-',
240+
description: "Current counter's value",
241+
},
242+
];
243+
244+
cy.get('[data-jsdoc-vuejs="section-data"]').contains('Data');
245+
cy.get('[data-jsdoc-vuejs="table-data"]').as('table-data');
246+
247+
cy
248+
.get('@table-data')
249+
.find('> thead > tr > th')
250+
.contains('Name')
251+
.next().contains('Type')
252+
.next().contains('Default value')
253+
.next().contains('Description');
254+
255+
cy
256+
.get('@table-data')
257+
.find('> tbody > tr')
258+
.then(($rows) => {
259+
expect($rows).to.have.length(1);
260+
261+
data.forEach((d, i) => {
262+
const $row = $rows.eq(i);
263+
const $children = $row.children();
264+
265+
expect($children.eq(0).html()).to.eq(d.name);
266+
expect($children.eq(1).html()).to.eq(d.type);
267+
expect($children.eq(2).html()).to.eq(d.defaultValue);
268+
expect($children.eq(3).html()).to.eq(d.description);
269+
});
270+
});
271+
});
272+
273+
it('should renders computed correctly', () => {
274+
const computeds = [
275+
{ name: '<code>fooList</code>', type: 'Array.&lt;String&gt;', description: 'A list of foo' },
276+
{ name: '<code>barList</code>', type: 'Array.&lt;String&gt;', description: 'A list of bar' },
277+
{ name: '<code>message</code>', type: 'String', description: 'A message' },
278+
];
279+
280+
cy.get('[data-jsdoc-vuejs="section-computed"]').contains('Computed');
281+
cy.get('[data-jsdoc-vuejs="table-computed"]').as('table-computed');
282+
283+
cy
284+
.get('@table-computed')
285+
.find('> thead > tr > th')
286+
.contains('Name')
287+
.next().contains('Type')
288+
.next().contains('Description');
289+
290+
cy
291+
.get('@table-computed')
292+
.find('> tbody > tr')
293+
.then(($rows) => {
294+
expect($rows).to.have.length(3);
295+
296+
computeds.forEach((computed, i) => {
297+
const $row = $rows.eq(i);
298+
const $children = $row.children();
299+
300+
expect($children.eq(0).html()).to.eq(computed.name);
301+
expect($children.eq(1).html()).to.eq(computed.type);
302+
expect($children.eq(2).html()).to.eq(computed.description);
303+
});
304+
});
305+
});
306+
307+
it('should render methods properly', () => {
308+
cy.contains('h3', 'Methods').should('have.attr', 'class', 'subsection-title');
309+
310+
cy.get('#decrement')
311+
.contains('decrement()')
312+
.next('.description')
313+
.next('.details')
314+
.contains('a[href="js_CounterJS.js.html#line43"]', 'line 43');
315+
316+
cy.get('#increment')
317+
.contains('increment()')
318+
.next('.description')
319+
.next('.details')
320+
.contains('a[href="js_CounterJS.js.html#line36"]', 'line 36');
321+
322+
cy.get('#showDialog')
323+
.contains('showDialog(counter)')
324+
.next('.description')
325+
.next('h5')
326+
.next('.params')
327+
.next('.details')
328+
.contains('a[href="js_CounterJS.js.html#line51"]', 'line 51');
329+
330+
cy.contains('created()').should('not.exist');
331+
});
332+
});

0 commit comments

Comments
 (0)