Skip to content

Commit 3ddf148

Browse files
printError shouldn't return trailing new line (#1983)
1 parent 84b416f commit 3ddf148

File tree

5 files changed

+18
-20
lines changed

5 files changed

+18
-20
lines changed

src/error/__tests__/printError-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('printError', () => {
3232
new Source('*', 'Test', { line: 9, column: 1 }),
3333
[0],
3434
);
35-
expect(printError(singleDigit)).to.equal(dedent`
35+
expect(printError(singleDigit) + '\n').to.equal(dedent`
3636
Single digit line number with no padding
3737
3838
Test:9:1
@@ -46,7 +46,7 @@ describe('printError', () => {
4646
new Source('*\n', 'Test', { line: 9, column: 1 }),
4747
[0],
4848
);
49-
expect(printError(doubleDigit)).to.equal(dedent`
49+
expect(printError(doubleDigit) + '\n').to.equal(dedent`
5050
Left padded first line number
5151
5252
Test:9:1
@@ -90,7 +90,7 @@ describe('printError', () => {
9090
fieldB.type,
9191
]);
9292

93-
expect(printError(error)).to.equal(dedent`
93+
expect(printError(error) + '\n').to.equal(dedent`
9494
Example error with two nodes
9595
9696
SourceA:2:10

src/error/printError.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function printError(error: GraphQLError): string {
2929
}
3030
return printedLocations.length === 0
3131
? error.message
32-
: [error.message, ...printedLocations].join('\n\n') + '\n';
32+
: [error.message, ...printedLocations].join('\n\n');
3333
}
3434

3535
/**

src/language/__tests__/lexer-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ describe('Lexer', () => {
118118
} catch (error) {
119119
caughtError = error;
120120
}
121-
expect(String(caughtError)).to.equal(dedent`
121+
expect(String(caughtError) + '\n').to.equal(dedent`
122122
Syntax Error: Cannot parse the unexpected character "?".
123123
124124
GraphQL request:3:5
@@ -138,7 +138,7 @@ describe('Lexer', () => {
138138
} catch (error) {
139139
caughtError = error;
140140
}
141-
expect(String(caughtError)).to.equal(dedent`
141+
expect(String(caughtError) + '\n').to.equal(dedent`
142142
Syntax Error: Cannot parse the unexpected character "?".
143143
144144
foo.js:13:6
@@ -157,7 +157,7 @@ describe('Lexer', () => {
157157
} catch (error) {
158158
caughtError = error;
159159
}
160-
expect(String(caughtError)).to.equal(dedent`
160+
expect(String(caughtError) + '\n').to.equal(dedent`
161161
Syntax Error: Cannot parse the unexpected character "?".
162162
163163
foo.js:1:5

src/language/__tests__/parser-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('Parser', () => {
4444
locations: [{ line: 1, column: 2 }],
4545
});
4646

47-
expect(String(caughtError)).to.equal(dedent`
47+
expect(String(caughtError) + '\n').to.equal(dedent`
4848
Syntax Error: Expected Name, found <EOF>
4949
5050
GraphQL request:1:2
@@ -81,7 +81,7 @@ describe('Parser', () => {
8181
} catch (error) {
8282
caughtError = error;
8383
}
84-
expect(String(caughtError)).to.equal(dedent`
84+
expect(String(caughtError) + '\n').to.equal(dedent`
8585
Syntax Error: Expected {, found <EOF>
8686
8787
MyQuery.graphql:1:6

src/utilities/__tests__/stripIgnoredCharacters-test.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,6 @@ function expectStripped(docString) {
8282
toStayTheSame() {
8383
this.toEqual(docString);
8484
},
85-
toThrow(expectedStringifyError) {
86-
let catchedError;
87-
88-
try {
89-
stripIgnoredCharacters(docString);
90-
} catch (e) {
91-
catchedError = e;
92-
}
93-
expect(String(catchedError)).to.equal(expectedStringifyError);
94-
},
9585
};
9686

9787
function inspectStr(str) {
@@ -155,7 +145,15 @@ describe('stripIgnoredCharacters', () => {
155145
});
156146

157147
it('report document with invalid token', () => {
158-
expectStripped('{ foo(arg: "\n"').toThrow(dedent`
148+
let catchedError;
149+
150+
try {
151+
stripIgnoredCharacters('{ foo(arg: "\n"');
152+
} catch (e) {
153+
catchedError = e;
154+
}
155+
156+
expect(String(catchedError) + '\n').to.equal(dedent`
159157
Syntax Error: Unterminated string.
160158
161159
GraphQL request:1:13

0 commit comments

Comments
 (0)