Skip to content

Commit

Permalink
Merge pull request #174 from seanpoulter/master
Browse files Browse the repository at this point in the history
Update tests for Windows `\r\n` newline and `\` path delimeter
  • Loading branch information
LinusU authored Mar 13, 2017
2 parents 8447322 + 43a30f3 commit 3266a23
Showing 1 changed file with 50 additions and 50 deletions.
100 changes: 50 additions & 50 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function compareStackTrace(sourceMap, source, expected) {
delete require.cache[require.resolve('./.generated')];
require('./.generated').test();
} catch (e) {
compareLines(e.stack.split('\n'), expected);
compareLines(e.stack.split(/\r\n|\n/), expected);
}
fs.unlinkSync('.generated.js');
fs.unlinkSync('.generated.js.map');
Expand All @@ -105,7 +105,7 @@ function compareStackTrace(sourceMap, source, expected) {
delete require.cache[require.resolve('./.generated')];
require('./.generated').test();
} catch (e) {
compareLines(e.stack.split('\n'), expected);
compareLines(e.stack.split(/\r\n|\n/), expected);
}
fs.unlinkSync('.generated.js');
}
Expand All @@ -120,7 +120,7 @@ function compareStdout(done, sourceMap, source, expected) {
compareLines(
(stdout + stderr)
.trim()
.split('\n')
.split(/\r\n|\n/)
.filter(function (line) { return line !== '' }), // Empty lines are not relevant.
expected
);
Expand All @@ -139,7 +139,7 @@ it('normal throw', function() {
'throw new Error("test");'
], [
'Error: test',
/^ at Object\.exports\.test \((?:.*\/)?line1\.js:1001:101\)$/
/^ at Object\.exports\.test \((?:.*[/\\])?line1\.js:1001:101\)$/
]);
});

Expand All @@ -151,8 +151,8 @@ it('throw inside function', function() {
'foo();'
], [
'Error: test',
/^ at foo \((?:.*\/)?line2\.js:1002:102\)$/,
/^ at Object\.exports\.test \((?:.*\/)?line4\.js:1004:104\)$/
/^ at foo \((?:.*[/\\])?line2\.js:1002:102\)$/,
/^ at Object\.exports\.test \((?:.*[/\\])?line4\.js:1004:104\)$/
]);
});

Expand All @@ -167,9 +167,9 @@ it('throw inside function inside function', function() {
'foo();'
], [
'Error: test',
/^ at bar \((?:.*\/)?line3\.js:1003:103\)$/,
/^ at foo \((?:.*\/)?line5\.js:1005:105\)$/,
/^ at Object\.exports\.test \((?:.*\/)?line7\.js:1007:107\)$/
/^ at bar \((?:.*[/\\])?line3\.js:1003:103\)$/,
/^ at foo \((?:.*[/\\])?line5\.js:1005:105\)$/,
/^ at Object\.exports\.test \((?:.*[/\\])?line7\.js:1007:107\)$/
]);
});

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

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

/^ at Object\.exports\.test \((?:.*\/)?line1\.js:1001:101\)$/
/^ at Object\.exports\.test \((?:.*[/\\])?line1\.js:1001:101\)$/
]);
});

Expand All @@ -191,9 +191,9 @@ it('eval inside eval', function() {
'eval("eval(\'throw new Error(\\"test\\")\')");'
], [
'Error: test',
/^ at (?:Object\.)?eval \(eval at (<anonymous>|exports.test) \(eval at (<anonymous>|exports.test) \((?:.*\/)?line1\.js:1001:101\)/,
/^ at (?:Object\.)?eval \(eval at (<anonymous>|exports.test) \((?:.*\/)?line1\.js:1001:101\)/,
/^ at Object\.exports\.test \((?:.*\/)?line1\.js:1001:101\)$/
/^ at (?:Object\.)?eval \(eval at (<anonymous>|exports.test) \(eval at (<anonymous>|exports.test) \((?:.*[/\\])?line1\.js:1001:101\)/,
/^ at (?:Object\.)?eval \(eval at (<anonymous>|exports.test) \((?:.*[/\\])?line1\.js:1001:101\)/,
/^ at Object\.exports\.test \((?:.*[/\\])?line1\.js:1001:101\)$/
]);
});

Expand All @@ -205,9 +205,9 @@ it('eval inside function', function() {
'foo();'
], [
'Error: test',
/^ at eval \(eval at foo \((?:.*\/)?line2\.js:1002:102\)/,
/^ at foo \((?:.*\/)?line2\.js:1002:102\)/,
/^ at Object\.exports\.test \((?:.*\/)?line4\.js:1004:104\)$/
/^ at eval \(eval at foo \((?:.*[/\\])?line2\.js:1002:102\)/,
/^ at foo \((?:.*[/\\])?line2\.js:1002:102\)/,
/^ at Object\.exports\.test \((?:.*[/\\])?line4\.js:1004:104\)$/
]);
});

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

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

Expand All @@ -237,7 +237,7 @@ it('native function', function() {
'[1].map(function(x) { throw new Error(x); });'
], [
'Error: 1',
/\/.original\.js/,
/[/\\].original\.js/,
/at Array\.map \(native\)/
]);
});
Expand All @@ -255,7 +255,7 @@ it('throw with empty source map', function() {
'throw new Error("test");'
], [
'Error: test',
/^ at Object\.exports\.test \((?:.*\/)?.generated.js:1:34\)$/
/^ at Object\.exports\.test \((?:.*[/\\])?.generated.js:1:34\)$/
]);
});

Expand All @@ -266,11 +266,11 @@ it('throw in Timeout with empty source map', function(done) {
' throw new Error("this is the error")',
'})'
], [
/\/.generated.js:3$/,
/[/\\].generated.js:3$/,
' throw new Error("this is the error")',
/^ \^$/,
'Error: this is the error',
/^ at ((null)|(Timeout))\._onTimeout \((?:.*\/)?.generated.js:3:11\)$/
/^ at ((null)|(Timeout))\._onTimeout \((?:.*[/\\])?.generated.js:3:11\)$/
]);
});

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

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

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

Expand All @@ -310,11 +310,11 @@ it('default options', function(done) {
'process.nextTick(foo);',
'process.nextTick(function() { process.exit(1); });'
], [
/\/.original\.js:1$/,
/[/\\].original\.js:1$/,
'this is the original code',
'^',
'Error: this is the error',
/^ at foo \((?:.*\/)?.original\.js:1:1\)$/
/^ at foo \((?:.*[/\\])?.original\.js:1:1\)$/
]);
});

Expand All @@ -325,11 +325,11 @@ it('handleUncaughtExceptions is true', function(done) {
'require("./source-map-support").install({ handleUncaughtExceptions: true });',
'process.nextTick(foo);'
], [
/\/.original\.js:1$/,
/[/\\].original\.js:1$/,
'this is the original code',
'^',
'Error: this is the error',
/^ at foo \((?:.*\/)?.original\.js:1:1\)$/
/^ at foo \((?:.*[/\\])?.original\.js:1:1\)$/
]);
});

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

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

'Error: this is the error',
/^ at foo \((?:.*\/)?.original\.js:1:1\)$/
/^ at foo \((?:.*[/\\])?.original\.js:1:1\)$/
]);
});

Expand All @@ -359,11 +359,11 @@ it('default options with empty source map', function(done) {
'require("./source-map-support").install();',
'process.nextTick(foo);'
], [
/\/.generated.js:2$/,
/[/\\].generated.js:2$/,
'function foo() { throw new Error("this is the error"); }',
/^ (?: )?\^$/,
'Error: this is the error',
/^ at foo \((?:.*\/)?.generated.js:2:24\)$/
/^ at foo \((?:.*[/\\])?.generated.js:2:24\)$/
]);
});

Expand All @@ -374,11 +374,11 @@ it('default options with source map with gap', function(done) {
'require("./source-map-support").install();',
'process.nextTick(foo);'
], [
/\/.generated.js:2$/,
/[/\\].generated.js:2$/,
'function foo() { throw new Error("this is the error"); }',
/^ (?: )?\^$/,
'Error: this is the error',
/^ at foo \((?:.*\/)?.generated.js:2:24\)$/
/^ at foo \((?:.*[/\\])?.generated.js:2:24\)$/
]);
});

Expand All @@ -391,7 +391,7 @@ it('specifically requested error source', function(done) {
'process.on("uncaughtException", function (e) { console.log("SRC:" + sms.getErrorSource(e)); });',
'process.nextTick(foo);'
], [
/^SRC:.*\/.original.js:1$/,
/^SRC:.*[/\\].original.js:1$/,
'this is the original code',
'^'
]);
Expand All @@ -405,11 +405,11 @@ it('sourcesContent', function(done) {
'process.nextTick(foo);',
'process.nextTick(function() { process.exit(1); });'
], [
/\/original\.js:1002$/,
/[/\\]original\.js:1002$/,
' line 2',
' ^',
'Error: this is the error',
/^ at foo \((?:.*\/)?original\.js:1002:5\)$/
/^ at foo \((?:.*[/\\])?original\.js:1002:5\)$/
]);
});

Expand All @@ -432,9 +432,9 @@ it('missing source maps should also be cached', function(done) {
'process.nextTick(function() { console.log(count); });',
], [
'Error: this is the error',
/^ at foo \((?:.*\/)?.generated.js:4:15\)$/,
/^ at foo \((?:.*[/\\])?.generated.js:4:15\)$/,
'Error: this is the error',
/^ at foo \((?:.*\/)?.generated.js:4:15\)$/,
/^ at foo \((?:.*[/\\])?.generated.js:4:15\)$/,
'1', // The retrieval should only be attempted once
]);
});
Expand Down Expand Up @@ -465,9 +465,9 @@ it('should consult all retrieve source map providers', function(done) {
'process.nextTick(function() { console.log(count); });',
], [
'Error: this is the error',
/^ at foo \((?:.*\/)?original.js:1004:5\)$/,
/^ at foo \((?:.*[/\\])?original.js:1004:5\)$/,
'Error: this is the error',
/^ at foo \((?:.*\/)?original.js:1004:5\)$/,
/^ at foo \((?:.*[/\\])?original.js:1004:5\)$/,
'1', // The retrieval should only be attempted once
]);
});
Expand Down Expand Up @@ -502,9 +502,9 @@ it('should allow for runtime inline source maps', function(done) {
'require("./.generated.jss");',
], [
'Error: this is the error',
/^ at foo \(.*\/original.js:1004:5\)$/,
/^ at foo \(.*[/\\]original.js:1004:5\)$/,
'Error: this is the error',
/^ at foo \(.*\/original.js:1004:5\)$/,
/^ at foo \(.*[/\\]original.js:1004:5\)$/,
'0', // The retrieval should only be attempted once
]);
});
Expand All @@ -518,7 +518,7 @@ it('finds source maps with charset specified', function() {
var source = [ 'throw new Error("test");' ];
var expected = [
'Error: test',
/^ at Object\.exports\.test \((?:.*\/)?line1\.js:1001:101\)$/
/^ at Object\.exports\.test \((?:.*[/\\])?line1\.js:1001:101\)$/
];

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

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

0 comments on commit 3266a23

Please sign in to comment.