Skip to content

Commit 3266a23

Browse files
authored
Merge pull request #174 from seanpoulter/master
Update tests for Windows `\r\n` newline and `\` path delimeter
2 parents 8447322 + 43a30f3 commit 3266a23

File tree

1 file changed

+50
-50
lines changed

1 file changed

+50
-50
lines changed

test.js

+50-50
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function compareStackTrace(sourceMap, source, expected) {
9292
delete require.cache[require.resolve('./.generated')];
9393
require('./.generated').test();
9494
} catch (e) {
95-
compareLines(e.stack.split('\n'), expected);
95+
compareLines(e.stack.split(/\r\n|\n/), expected);
9696
}
9797
fs.unlinkSync('.generated.js');
9898
fs.unlinkSync('.generated.js.map');
@@ -105,7 +105,7 @@ function compareStackTrace(sourceMap, source, expected) {
105105
delete require.cache[require.resolve('./.generated')];
106106
require('./.generated').test();
107107
} catch (e) {
108-
compareLines(e.stack.split('\n'), expected);
108+
compareLines(e.stack.split(/\r\n|\n/), expected);
109109
}
110110
fs.unlinkSync('.generated.js');
111111
}
@@ -120,7 +120,7 @@ function compareStdout(done, sourceMap, source, expected) {
120120
compareLines(
121121
(stdout + stderr)
122122
.trim()
123-
.split('\n')
123+
.split(/\r\n|\n/)
124124
.filter(function (line) { return line !== '' }), // Empty lines are not relevant.
125125
expected
126126
);
@@ -139,7 +139,7 @@ it('normal throw', function() {
139139
'throw new Error("test");'
140140
], [
141141
'Error: test',
142-
/^ at Object\.exports\.test \((?:.*\/)?line1\.js:1001:101\)$/
142+
/^ at Object\.exports\.test \((?:.*[/\\])?line1\.js:1001:101\)$/
143143
]);
144144
});
145145

@@ -151,8 +151,8 @@ it('throw inside function', function() {
151151
'foo();'
152152
], [
153153
'Error: test',
154-
/^ at foo \((?:.*\/)?line2\.js:1002:102\)$/,
155-
/^ at Object\.exports\.test \((?:.*\/)?line4\.js:1004:104\)$/
154+
/^ at foo \((?:.*[/\\])?line2\.js:1002:102\)$/,
155+
/^ at Object\.exports\.test \((?:.*[/\\])?line4\.js:1004:104\)$/
156156
]);
157157
});
158158

@@ -167,9 +167,9 @@ it('throw inside function inside function', function() {
167167
'foo();'
168168
], [
169169
'Error: test',
170-
/^ at bar \((?:.*\/)?line3\.js:1003:103\)$/,
171-
/^ at foo \((?:.*\/)?line5\.js:1005:105\)$/,
172-
/^ at Object\.exports\.test \((?:.*\/)?line7\.js:1007:107\)$/
170+
/^ at bar \((?:.*[/\\])?line3\.js:1003:103\)$/,
171+
/^ at foo \((?:.*[/\\])?line5\.js:1005:105\)$/,
172+
/^ at Object\.exports\.test \((?:.*[/\\])?line7\.js:1007:107\)$/
173173
]);
174174
});
175175

@@ -180,9 +180,9 @@ it('eval', function() {
180180
'Error: test',
181181

182182
// Before Node 4, `Object.eval`, after just `eval`.
183-
/^ at (?:Object\.)?eval \(eval at (<anonymous>|exports.test) \((?:.*\/)?line1\.js:1001:101\)/,
183+
/^ at (?:Object\.)?eval \(eval at (<anonymous>|exports.test) \((?:.*[/\\])?line1\.js:1001:101\)/,
184184

185-
/^ at Object\.exports\.test \((?:.*\/)?line1\.js:1001:101\)$/
185+
/^ at Object\.exports\.test \((?:.*[/\\])?line1\.js:1001:101\)$/
186186
]);
187187
});
188188

@@ -191,9 +191,9 @@ it('eval inside eval', function() {
191191
'eval("eval(\'throw new Error(\\"test\\")\')");'
192192
], [
193193
'Error: test',
194-
/^ at (?:Object\.)?eval \(eval at (<anonymous>|exports.test) \(eval at (<anonymous>|exports.test) \((?:.*\/)?line1\.js:1001:101\)/,
195-
/^ at (?:Object\.)?eval \(eval at (<anonymous>|exports.test) \((?:.*\/)?line1\.js:1001:101\)/,
196-
/^ at Object\.exports\.test \((?:.*\/)?line1\.js:1001:101\)$/
194+
/^ at (?:Object\.)?eval \(eval at (<anonymous>|exports.test) \(eval at (<anonymous>|exports.test) \((?:.*[/\\])?line1\.js:1001:101\)/,
195+
/^ at (?:Object\.)?eval \(eval at (<anonymous>|exports.test) \((?:.*[/\\])?line1\.js:1001:101\)/,
196+
/^ at Object\.exports\.test \((?:.*[/\\])?line1\.js:1001:101\)$/
197197
]);
198198
});
199199

@@ -205,9 +205,9 @@ it('eval inside function', function() {
205205
'foo();'
206206
], [
207207
'Error: test',
208-
/^ at eval \(eval at foo \((?:.*\/)?line2\.js:1002:102\)/,
209-
/^ at foo \((?:.*\/)?line2\.js:1002:102\)/,
210-
/^ at Object\.exports\.test \((?:.*\/)?line4\.js:1004:104\)$/
208+
/^ at eval \(eval at foo \((?:.*[/\\])?line2\.js:1002:102\)/,
209+
/^ at foo \((?:.*[/\\])?line2\.js:1002:102\)/,
210+
/^ at Object\.exports\.test \((?:.*[/\\])?line4\.js:1004:104\)$/
211211
]);
212212
});
213213

@@ -217,7 +217,7 @@ it('eval with sourceURL', function() {
217217
], [
218218
'Error: test',
219219
/^ at (?:Object\.)?eval \(sourceURL\.js:1:7\)$/,
220-
/^ at Object\.exports\.test \((?:.*\/)?line1\.js:1001:101\)$/
220+
/^ at Object\.exports\.test \((?:.*[/\\])?line1\.js:1001:101\)$/
221221
]);
222222
});
223223

@@ -227,8 +227,8 @@ it('eval with sourceURL inside eval', function() {
227227
], [
228228
'Error: test',
229229
/^ at (?:Object\.)?eval \(sourceURL\.js:1:7\)$/,
230-
/^ at (?:Object\.)?eval \(eval at (<anonymous>|exports.test) \((?:.*\/)?line1\.js:1001:101\)/,
231-
/^ at Object\.exports\.test \((?:.*\/)?line1\.js:1001:101\)$/
230+
/^ at (?:Object\.)?eval \(eval at (<anonymous>|exports.test) \((?:.*[/\\])?line1\.js:1001:101\)/,
231+
/^ at Object\.exports\.test \((?:.*[/\\])?line1\.js:1001:101\)$/
232232
]);
233233
});
234234

@@ -237,7 +237,7 @@ it('native function', function() {
237237
'[1].map(function(x) { throw new Error(x); });'
238238
], [
239239
'Error: 1',
240-
/\/.original\.js/,
240+
/[/\\].original\.js/,
241241
/at Array\.map \(native\)/
242242
]);
243243
});
@@ -255,7 +255,7 @@ it('throw with empty source map', function() {
255255
'throw new Error("test");'
256256
], [
257257
'Error: test',
258-
/^ at Object\.exports\.test \((?:.*\/)?.generated.js:1:34\)$/
258+
/^ at Object\.exports\.test \((?:.*[/\\])?.generated.js:1:34\)$/
259259
]);
260260
});
261261

@@ -266,11 +266,11 @@ it('throw in Timeout with empty source map', function(done) {
266266
' throw new Error("this is the error")',
267267
'})'
268268
], [
269-
/\/.generated.js:3$/,
269+
/[/\\].generated.js:3$/,
270270
' throw new Error("this is the error")',
271271
/^ \^$/,
272272
'Error: this is the error',
273-
/^ at ((null)|(Timeout))\._onTimeout \((?:.*\/)?.generated.js:3:11\)$/
273+
/^ at ((null)|(Timeout))\._onTimeout \((?:.*[/\\])?.generated.js:3:11\)$/
274274
]);
275275
});
276276

@@ -279,7 +279,7 @@ it('throw with source map with gap', function() {
279279
'throw new Error("test");'
280280
], [
281281
'Error: test',
282-
/^ at Object\.exports\.test \((?:.*\/)?.generated.js:1:34\)$/
282+
/^ at Object\.exports\.test \((?:.*[/\\])?.generated.js:1:34\)$/
283283
]);
284284
});
285285

@@ -288,7 +288,7 @@ it('sourcesContent with data URL', function() {
288288
'throw new Error("test");'
289289
], [
290290
'Error: test',
291-
/^ at Object\.exports\.test \((?:.*\/)?original.js:1001:5\)$/
291+
/^ at Object\.exports\.test \((?:.*[/\\])?original.js:1001:5\)$/
292292
]);
293293
});
294294

@@ -298,7 +298,7 @@ it('finds the last sourceMappingURL', function() {
298298
'throw new Error("test");'
299299
], [
300300
'Error: test',
301-
/^ at Object\.exports\.test \((?:.*\/)?original.js:1002:5\)$/
301+
/^ at Object\.exports\.test \((?:.*[/\\])?original.js:1002:5\)$/
302302
]);
303303
});
304304

@@ -310,11 +310,11 @@ it('default options', function(done) {
310310
'process.nextTick(foo);',
311311
'process.nextTick(function() { process.exit(1); });'
312312
], [
313-
/\/.original\.js:1$/,
313+
/[/\\].original\.js:1$/,
314314
'this is the original code',
315315
'^',
316316
'Error: this is the error',
317-
/^ at foo \((?:.*\/)?.original\.js:1:1\)$/
317+
/^ at foo \((?:.*[/\\])?.original\.js:1:1\)$/
318318
]);
319319
});
320320

@@ -325,11 +325,11 @@ it('handleUncaughtExceptions is true', function(done) {
325325
'require("./source-map-support").install({ handleUncaughtExceptions: true });',
326326
'process.nextTick(foo);'
327327
], [
328-
/\/.original\.js:1$/,
328+
/[/\\].original\.js:1$/,
329329
'this is the original code',
330330
'^',
331331
'Error: this is the error',
332-
/^ at foo \((?:.*\/)?.original\.js:1:1\)$/
332+
/^ at foo \((?:.*[/\\])?.original\.js:1:1\)$/
333333
]);
334334
});
335335

@@ -340,15 +340,15 @@ it('handleUncaughtExceptions is false', function(done) {
340340
'require("./source-map-support").install({ handleUncaughtExceptions: false });',
341341
'process.nextTick(foo);'
342342
], [
343-
/\/.generated.js:2$/,
343+
/[/\\].generated.js:2$/,
344344
'function foo() { throw new Error("this is the error"); }',
345345

346346
// Before Node 4, the arrow points on the `new`, after on the
347347
// `throw`.
348348
/^ (?: )?\^$/,
349349

350350
'Error: this is the error',
351-
/^ at foo \((?:.*\/)?.original\.js:1:1\)$/
351+
/^ at foo \((?:.*[/\\])?.original\.js:1:1\)$/
352352
]);
353353
});
354354

@@ -359,11 +359,11 @@ it('default options with empty source map', function(done) {
359359
'require("./source-map-support").install();',
360360
'process.nextTick(foo);'
361361
], [
362-
/\/.generated.js:2$/,
362+
/[/\\].generated.js:2$/,
363363
'function foo() { throw new Error("this is the error"); }',
364364
/^ (?: )?\^$/,
365365
'Error: this is the error',
366-
/^ at foo \((?:.*\/)?.generated.js:2:24\)$/
366+
/^ at foo \((?:.*[/\\])?.generated.js:2:24\)$/
367367
]);
368368
});
369369

@@ -374,11 +374,11 @@ it('default options with source map with gap', function(done) {
374374
'require("./source-map-support").install();',
375375
'process.nextTick(foo);'
376376
], [
377-
/\/.generated.js:2$/,
377+
/[/\\].generated.js:2$/,
378378
'function foo() { throw new Error("this is the error"); }',
379379
/^ (?: )?\^$/,
380380
'Error: this is the error',
381-
/^ at foo \((?:.*\/)?.generated.js:2:24\)$/
381+
/^ at foo \((?:.*[/\\])?.generated.js:2:24\)$/
382382
]);
383383
});
384384

@@ -391,7 +391,7 @@ it('specifically requested error source', function(done) {
391391
'process.on("uncaughtException", function (e) { console.log("SRC:" + sms.getErrorSource(e)); });',
392392
'process.nextTick(foo);'
393393
], [
394-
/^SRC:.*\/.original.js:1$/,
394+
/^SRC:.*[/\\].original.js:1$/,
395395
'this is the original code',
396396
'^'
397397
]);
@@ -405,11 +405,11 @@ it('sourcesContent', function(done) {
405405
'process.nextTick(foo);',
406406
'process.nextTick(function() { process.exit(1); });'
407407
], [
408-
/\/original\.js:1002$/,
408+
/[/\\]original\.js:1002$/,
409409
' line 2',
410410
' ^',
411411
'Error: this is the error',
412-
/^ at foo \((?:.*\/)?original\.js:1002:5\)$/
412+
/^ at foo \((?:.*[/\\])?original\.js:1002:5\)$/
413413
]);
414414
});
415415

@@ -432,9 +432,9 @@ it('missing source maps should also be cached', function(done) {
432432
'process.nextTick(function() { console.log(count); });',
433433
], [
434434
'Error: this is the error',
435-
/^ at foo \((?:.*\/)?.generated.js:4:15\)$/,
435+
/^ at foo \((?:.*[/\\])?.generated.js:4:15\)$/,
436436
'Error: this is the error',
437-
/^ at foo \((?:.*\/)?.generated.js:4:15\)$/,
437+
/^ at foo \((?:.*[/\\])?.generated.js:4:15\)$/,
438438
'1', // The retrieval should only be attempted once
439439
]);
440440
});
@@ -465,9 +465,9 @@ it('should consult all retrieve source map providers', function(done) {
465465
'process.nextTick(function() { console.log(count); });',
466466
], [
467467
'Error: this is the error',
468-
/^ at foo \((?:.*\/)?original.js:1004:5\)$/,
468+
/^ at foo \((?:.*[/\\])?original.js:1004:5\)$/,
469469
'Error: this is the error',
470-
/^ at foo \((?:.*\/)?original.js:1004:5\)$/,
470+
/^ at foo \((?:.*[/\\])?original.js:1004:5\)$/,
471471
'1', // The retrieval should only be attempted once
472472
]);
473473
});
@@ -502,9 +502,9 @@ it('should allow for runtime inline source maps', function(done) {
502502
'require("./.generated.jss");',
503503
], [
504504
'Error: this is the error',
505-
/^ at foo \(.*\/original.js:1004:5\)$/,
505+
/^ at foo \(.*[/\\]original.js:1004:5\)$/,
506506
'Error: this is the error',
507-
/^ at foo \(.*\/original.js:1004:5\)$/,
507+
/^ at foo \(.*[/\\]original.js:1004:5\)$/,
508508
'0', // The retrieval should only be attempted once
509509
]);
510510
});
@@ -518,7 +518,7 @@ it('finds source maps with charset specified', function() {
518518
var source = [ 'throw new Error("test");' ];
519519
var expected = [
520520
'Error: test',
521-
/^ at Object\.exports\.test \((?:.*\/)?line1\.js:1001:101\)$/
521+
/^ at Object\.exports\.test \((?:.*[/\\])?line1\.js:1001:101\)$/
522522
];
523523

524524
fs.writeFileSync('.generated.js', 'exports.test = function() {' +
@@ -528,7 +528,7 @@ it('finds source maps with charset specified', function() {
528528
delete require.cache[require.resolve('./.generated')];
529529
require('./.generated').test();
530530
} catch (e) {
531-
compareLines(e.stack.split('\n'), expected);
531+
compareLines(e.stack.split(/\r\n|\n/), expected);
532532
}
533533
fs.unlinkSync('.generated.js');
534534
});
@@ -542,7 +542,7 @@ it('allows code/comments after sourceMappingURL', function() {
542542
var source = [ 'throw new Error("test");' ];
543543
var expected = [
544544
'Error: test',
545-
/^ at Object\.exports\.test \((?:.*\/)?line1\.js:1001:101\)$/
545+
/^ at Object\.exports\.test \((?:.*[/\\])?line1\.js:1001:101\)$/
546546
];
547547

548548
fs.writeFileSync('.generated.js', 'exports.test = function() {' +
@@ -553,7 +553,7 @@ it('allows code/comments after sourceMappingURL', function() {
553553
delete require.cache[require.resolve('./.generated')];
554554
require('./.generated').test();
555555
} catch (e) {
556-
compareLines(e.stack.split('\n'), expected);
556+
compareLines(e.stack.split(/\r\n|\n/), expected);
557557
}
558558
fs.unlinkSync('.generated.js');
559559
});

0 commit comments

Comments
 (0)