Skip to content

Commit f6e781d

Browse files
committed
Remove duplicate dedent definition
1 parent 819a59c commit f6e781d

File tree

1 file changed

+18
-43
lines changed

1 file changed

+18
-43
lines changed

src/utilities/__tests__/assertValidName-test.js

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,12 @@
66
*/
77

88
import { afterEach, beforeEach, describe, it } from 'mocha';
9-
import { default as chai, expect } from 'chai';
9+
import chai, { expect } from 'chai';
1010
import { formatWarning } from '../assertValidName';
11+
import dedent from '../../jsutils/dedent';
1112

1213
/* eslint-disable no-console */
1314

14-
/**
15-
* Helper for dedenting indented template literals. This helps us to
16-
* keep the tests pretty.
17-
*/
18-
function dedent(string) {
19-
// Get lines, discarding empty leading and trailing lines.
20-
const lines = string.replace(/^[ \t]*\n|\n[ \t]*$/g, '').split('\n');
21-
22-
// Find smallest indent.
23-
const indent = lines.reduce((currentMinimum, line) => {
24-
const whitespace = line.match(/^ +/);
25-
return Math.min(whitespace ? whitespace[0].length : 0, currentMinimum);
26-
}, Infinity);
27-
28-
// Remove indent from each line.
29-
return lines.map(line => line.slice(indent)).join('\n');
30-
}
31-
3215
/**
3316
* Convenience method for creating an Error object with a defined stack.
3417
*/
@@ -101,27 +84,25 @@ describe('assertValidName()', () => {
10184

10285
describe('formatWarning()', () => {
10386
it('formats given a Chrome-style stack property', () => {
104-
const chromeStack = dedent(`
87+
const chromeStack = dedent`
10588
Error: foo
10689
at z (<anonymous>:1:21)
10790
at y (<anonymous>:1:15)
10891
at x (<anonymous>:1:15)
109-
at <anonymous>:1:6
110-
`);
92+
at <anonymous>:1:6`;
11193
const error = createErrorObject('foo', chromeStack);
11294
expect(formatWarning(error)).to.equal(
113-
dedent(`
95+
dedent`
11496
foo
11597
at z (<anonymous>:1:21)
11698
at y (<anonymous>:1:15)
11799
at x (<anonymous>:1:15)
118-
at <anonymous>:1:6
119-
`),
100+
at <anonymous>:1:6`,
120101
);
121102
});
122103

123104
it('formats given a Node-style stack property', () => {
124-
const nodeStack = dedent(`
105+
const nodeStack = dedent`
125106
Error: foo
126107
at z (repl:1:29)
127108
at y (repl:1:23)
@@ -132,11 +113,10 @@ describe('formatWarning()', () => {
132113
at bound (domain.js:280:14)
133114
at REPLServer.runBound [as eval] (domain.js:293:12)
134115
at REPLServer.onLine (repl.js:537:10)
135-
at emitOne (events.js:101:20)
136-
`);
116+
at emitOne (events.js:101:20)`;
137117
const error = createErrorObject('foo', nodeStack);
138118
expect(formatWarning(error)).to.equal(
139-
dedent(`
119+
dedent`
140120
foo
141121
at z (repl:1:29)
142122
at y (repl:1:23)
@@ -147,44 +127,40 @@ describe('formatWarning()', () => {
147127
at bound (domain.js:280:14)
148128
at REPLServer.runBound [as eval] (domain.js:293:12)
149129
at REPLServer.onLine (repl.js:537:10)
150-
at emitOne (events.js:101:20)
151-
`),
130+
at emitOne (events.js:101:20)`,
152131
);
153132
});
154133

155134
it('formats given a Firefox-style stack property', () => {
156-
const firefoxStack = dedent(`
135+
const firefoxStack = dedent`
157136
z@debugger eval code:1:20
158137
y@debugger eval code:1:14
159138
x@debugger eval code:1:14
160-
@debugger eval code:1:5
161-
`);
139+
@debugger eval code:1:5`;
162140
const error = createErrorObject('foo', firefoxStack);
163141
expect(formatWarning(error)).to.equal(
164-
dedent(`
142+
dedent`
165143
foo
166144
z@debugger eval code:1:20
167145
y@debugger eval code:1:14
168146
x@debugger eval code:1:14
169-
@debugger eval code:1:5
170-
`),
147+
@debugger eval code:1:5`,
171148
);
172149
});
173150

174151
it('formats given a Safari-style stack property', () => {
175-
const safariStack = dedent(`
152+
const safariStack = dedent`
176153
z
177154
y
178155
x
179156
global code
180157
evaluateWithScopeExtension@[native code]
181158
_evaluateOn
182159
_evaluateAndWrap
183-
evaluate
184-
`);
160+
evaluate`;
185161
const error = createErrorObject('foo', safariStack);
186162
expect(formatWarning(error)).to.equal(
187-
dedent(`
163+
dedent`
188164
foo
189165
z
190166
y
@@ -193,8 +169,7 @@ describe('formatWarning()', () => {
193169
evaluateWithScopeExtension@[native code]
194170
_evaluateOn
195171
_evaluateAndWrap
196-
evaluate
197-
`),
172+
evaluate`,
198173
);
199174
});
200175

0 commit comments

Comments
 (0)