Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core: Fix "source" attribution for test definitions
Follows-up commits 07de4b1 and 835b7c1. This introduced `test.each()`, but also changed `QUnit.test()` to have 3 instead of 2 function calls until `new Test()` internally, which broke the stacktrace extraction in most cases. This was not covered well by tests. The `test.each()` itself also had a different offset. It had 6 frames until `new Test` for the case of array data, and 7 frames for the case of object data. This difference is due to `data.forEach(fn)` verses `keys.forEach(x => fn())`. * Cover it all with tests. * Increase default stackOffset from 2 to 3. * Change `runEach` to always have 5 frames, by using a for-loop. * Allow internal override. * Use the override. Fixes #1679.
- Loading branch information
Showing
9 changed files
with
142 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Skip on browsers that doesn't support stack trace | ||
(QUnit.stack() ? QUnit.module : QUnit.module.skip)('stacktrace', function () { | ||
function fooCurrent () { | ||
return QUnit.stack(); | ||
} | ||
function fooParent () { | ||
return fooCurrent(); | ||
} | ||
|
||
function fooInternal () { | ||
return QUnit.stack(2); | ||
} | ||
function fooPublic () { | ||
return fooInternal(); | ||
} | ||
function barCaller () { | ||
return fooPublic(); | ||
} | ||
|
||
function norm (str) { | ||
// CRLF | ||
return str.replace(/\\/g, '/'); | ||
} | ||
|
||
QUnit.test('QUnit.stack()', function (assert) { | ||
var simple = norm(QUnit.stack()); | ||
assert.pushResult({ | ||
result: simple.indexOf('/main/stacktrace.js') !== -1, | ||
actual: simple, | ||
message: 'current file' | ||
}); | ||
|
||
var nested = norm(fooParent()); | ||
assert.pushResult({ | ||
result: nested.indexOf('fooCurrent') !== -1, | ||
actual: nested, | ||
message: 'include current function' | ||
}); | ||
assert.pushResult({ | ||
result: nested.indexOf('fooParent') !== -1, | ||
actual: nested, | ||
message: 'include parent function' | ||
}); | ||
}); | ||
|
||
QUnit.test('QUnit.stack(offset)', function (assert) { | ||
var stack = norm(barCaller()); | ||
var line = stack.split('\n')[0]; | ||
|
||
assert.pushResult({ | ||
result: line.indexOf('/main/stacktrace.js') !== -1, | ||
actual: line, | ||
message: 'current file' | ||
}); | ||
assert.pushResult({ | ||
result: line.indexOf('barCaller') !== -1, | ||
actual: line, | ||
message: 'start at offset' | ||
}); | ||
assert.pushResult({ | ||
result: stack.indexOf('fooInternal') === -1, | ||
actual: stack, | ||
message: 'skip internals' | ||
}); | ||
}); | ||
|
||
QUnit.test('QUnit.test() source details', function (assert) { | ||
var stack = norm(QUnit.config.current.stack); | ||
var line = stack.split('\n')[0]; | ||
assert.pushResult({ | ||
result: line.indexOf('/main/stacktrace.js') !== -1, | ||
expected: '/main/stacktrace.js', | ||
actual: stack, | ||
message: 'start at current file' | ||
}); | ||
}); | ||
|
||
QUnit.test.each('QUnit.test.each(list) source details', [0], function (assert) { | ||
var stack = norm(QUnit.config.current.stack); | ||
var line = stack.split('\n')[0]; | ||
assert.pushResult({ | ||
result: line.indexOf('/main/stacktrace.js') !== -1, | ||
expected: '/main/stacktrace.js', | ||
actual: stack, | ||
message: 'start at current file' | ||
}); | ||
}); | ||
|
||
QUnit.test.each('QUnit.test.each(object) source details', { a: 0 }, function (assert) { | ||
var stack = norm(QUnit.config.current.stack); | ||
var line = stack.split('\n')[0]; | ||
assert.pushResult({ | ||
result: line.indexOf('/main/stacktrace.js') !== -1, | ||
expected: '/main/stacktrace.js', | ||
actual: stack, | ||
message: 'start at current file' | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters