Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit bd3b028

Browse files
alloykastermester
authored andcommitted
[FindGraphQLTags] Add first test.
1 parent f012a7d commit bd3b028

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/FindGraphQLTags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function getSourceLocationOffset(quasi: ts.TaggedTemplateExpression) {
170170
const pos = getTemplateNode(quasi).pos;
171171
const loc = quasi.getSourceFile().getLineAndCharacterOfPosition(pos);
172172
return {
173-
line: loc.line + 1,
173+
line: loc.line,
174174
column: loc.character + 1
175175
};
176176
}

test/FindGraphQLTags-test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as FindGraphQLTags from '../src/FindGraphQLTags'
2+
3+
describe('FindGraphQLTags', () => {
4+
function find(text) {
5+
return FindGraphQLTags.find(text, '/path/to/TestModule.ts')
6+
}
7+
8+
it('extracts a tag', () => {
9+
expect(find(`
10+
import { createFragmentContainer, graphql } from 'react-relay'
11+
export default createFragmentContainer(
12+
props => <div>{props.artist.name}</div>,
13+
graphql\`
14+
fragment TestModule_artist on Artist {
15+
name
16+
}
17+
\`
18+
)
19+
`)).toEqual([{
20+
keyName: null,
21+
template: `
22+
fragment TestModule_artist on Artist {
23+
name
24+
}
25+
`,
26+
sourceLocationOffset: { line: 4, column: 16 },
27+
}])
28+
})
29+
30+
// TODO: Cover all cases where tags are extracted
31+
})

0 commit comments

Comments
 (0)