Skip to content

Commit 40e7a99

Browse files
committed
Add docblock test for valid line terminators
This test failed before Recast v0.10.31 because Recast did not respect all valid JavaScript line terminator sequences. I'm not publishing a new version, reinstalling react-docgen should fix the issue.
1 parent 849cf4a commit 40e7a99

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"babylon": "~5.8.3",
3030
"node-dir": "^0.1.6",
3131
"nomnom": "^1.8.1",
32-
"recast": "^0.10.17"
32+
"recast": "^0.10.31"
3333
},
3434
"devDependencies": {
3535
"babel": "^5.6.23",

src/utils/__tests__/docblock-test.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jest
1616
describe('docblock', () => {
1717

1818
describe('getDoclets', () => {
19-
var getDoclets;
19+
let getDoclets;
2020

2121
beforeEach(() => {
22-
getDoclets = require('../docblock').getDoclets;
22+
({getDoclets} = require('../docblock'));
2323
});
2424

2525
it('extracts single line doclets', () => {
@@ -38,4 +38,42 @@ describe('docblock', () => {
3838
});
3939
});
4040

41+
describe.only('getDocblock', () => {
42+
let comment = ['This is a docblock.', 'This is the second line.'];
43+
let source = [
44+
'/**',
45+
` * ${comment[0]}`,
46+
` * ${comment[1]}`,
47+
' */',
48+
'foo;',
49+
];
50+
51+
let getDocblock;
52+
let statement;
53+
54+
beforeEach(() => {
55+
({getDocblock} = require('../docblock'));
56+
({statement} = require('../../../tests/utils'));
57+
});
58+
59+
it('gets the closest docblock of the given node', () => {
60+
let node = statement(source.join('\n'));
61+
expect(getDocblock(node)).toEqual(comment.join('\n'));
62+
});
63+
64+
let terminators = [
65+
'\u000A',
66+
'\u000D',
67+
'\u2028',
68+
'\u2029',
69+
'\u000D\u000A',
70+
];
71+
terminators.forEach(t => {
72+
it('can handle ' + escape(t) + ' as line terminator', () => {
73+
let node = statement(source.join(t));
74+
expect(getDocblock(node)).toEqual(comment.join('\n'));
75+
});
76+
});
77+
});
78+
4179
});

0 commit comments

Comments
 (0)