Renamed the trace feature to debugLog[s]

"trace" was ambiguous and could easily be understood to have something
to do with stack traces.
This commit is contained in:
Steve Gravrock
2021-12-02 14:46:56 -08:00
parent 5eb42d67a7
commit 40fac8b6a2
12 changed files with 97 additions and 117 deletions

View File

@@ -436,17 +436,17 @@ jasmineRequire.HtmlReporter = function(j$) {
); );
} }
if (result.trace) { if (result.debugLogs) {
messages.appendChild(traceTable(result.trace)); messages.appendChild(debugLogTable(result.debugLogs));
} }
return failure; return failure;
} }
function traceTable(trace) { function debugLogTable(debugLogs) {
var tbody = createDom('tbody'); var tbody = createDom('tbody');
trace.forEach(function(entry) { debugLogs.forEach(function(entry) {
tbody.appendChild( tbody.appendChild(
createDom( createDom(
'tr', 'tr',
@@ -459,11 +459,11 @@ jasmineRequire.HtmlReporter = function(j$) {
return createDom( return createDom(
'div', 'div',
{ className: 'jasmine-trace' }, { className: 'jasmine-debug-log' },
createDom( createDom(
'div', 'div',
{ className: 'jasmine-trace-header' }, { className: 'jasmine-debug-log-header' },
'Trace information' 'Debug logs'
), ),
createDom( createDom(
'table', 'table',

View File

@@ -288,16 +288,16 @@ body {
margin-left: 14px; margin-left: 14px;
padding: 5px; padding: 5px;
} }
.jasmine_html-reporter .jasmine-trace { .jasmine_html-reporter .jasmine-debug-log {
margin: 5px 0 0 0; margin: 5px 0 0 0;
padding: 5px; padding: 5px;
color: #666; color: #666;
border: 1px solid #ddd; border: 1px solid #ddd;
background: white; background: white;
} }
.jasmine_html-reporter .jasmine-trace table { .jasmine_html-reporter .jasmine-debug-log table {
border-spacing: 0; border-spacing: 0;
} }
.jasmine_html-reporter .jasmine-trace table, .jasmine_html-reporter .jasmine-trace th, .jasmine_html-reporter .jasmine-trace td { .jasmine_html-reporter .jasmine-debug-log table, .jasmine_html-reporter .jasmine-debug-log th, .jasmine_html-reporter .jasmine-debug-log td {
border: 1px solid #ddd; border: 1px solid #ddd;
} }

View File

@@ -575,12 +575,12 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
* This method should be called only when a spec (including any associated * This method should be called only when a spec (including any associated
* beforeEach or afterEach functions) is running. * beforeEach or afterEach functions) is running.
* @function * @function
* @name jasmine.trace * @name jasmine.debugLog
* @since 3.10.0 * @since 4.0.0
* @param {String} msg - The message to log * @param {String} msg - The message to log
*/ */
j$.trace = function(msg) { j$.debugLog = function(msg) {
j$.getEnv().trace(msg); j$.getEnv().debugLog(msg);
}; };
}; };
@@ -804,7 +804,7 @@ getJasmineRequireObj().Spec = function(j$) {
* @property {String} status - Once the spec has completed, this string represents the pass/fail status of this spec. * @property {String} status - Once the spec has completed, this string represents the pass/fail status of this spec.
* @property {number} duration - The time in ms used by the spec execution, including any before/afterEach. * @property {number} duration - The time in ms used by the spec execution, including any before/afterEach.
* @property {Object} properties - User-supplied properties, if any, that were set using {@link Env#setSpecProperty} * @property {Object} properties - User-supplied properties, if any, that were set using {@link Env#setSpecProperty}
* @property {TraceEntry[]|null} trace - Trace messages, if any, that were logged using {@link jasmine.trace} during a failing spec. * @property {DebugLogEntry[]|null} debugLogs - Messages, if any, that were logged using {@link jasmine.debugLog} during a failing spec.
* @since 2.0.0 * @since 2.0.0
*/ */
this.result = { this.result = {
@@ -817,7 +817,7 @@ getJasmineRequireObj().Spec = function(j$) {
pendingReason: '', pendingReason: '',
duration: null, duration: null,
properties: null, properties: null,
trace: null debugLogs: null
}; };
} }
@@ -866,7 +866,7 @@ getJasmineRequireObj().Spec = function(j$) {
self.result.duration = self.timer.elapsed(); self.result.duration = self.timer.elapsed();
if (self.result.status !== 'failed') { if (self.result.status !== 'failed') {
self.result.trace = null; self.result.debugLogs = null;
} }
self.resultCallback(self.result, done); self.resultCallback(self.result, done);
@@ -917,21 +917,6 @@ getJasmineRequireObj().Spec = function(j$) {
}; };
Spec.prototype.reset = function() { Spec.prototype.reset = function() {
/**
* @typedef SpecResult
* @property {Int} id - The unique id of this spec.
* @property {String} description - The description passed to the {@link it} that created this spec.
* @property {String} fullName - The full description including all ancestors of this spec.
* @property {Expectation[]} failedExpectations - The list of expectations that failed during execution of this spec.
* @property {Expectation[]} passedExpectations - The list of expectations that passed during execution of this spec.
* @property {Expectation[]} deprecationWarnings - The list of deprecation warnings that occurred during execution this spec.
* @property {String} pendingReason - If the spec is {@link pending}, this will be the reason.
* @property {String} status - Once the spec has completed, this string represents the pass/fail status of this spec.
* @property {number} duration - The time in ms used by the spec execution, including any before/afterEach.
* @property {Object} properties - User-supplied properties, if any, that were set using {@link Env#setSpecProperty}
* @property {TraceEntry[]|null} trace - Trace messages, if any, that were logged using {@link Env#trace} during a failing spec.
* @since 2.0.0
*/
this.result = { this.result = {
id: this.id, id: this.id,
description: this.description, description: this.description,
@@ -942,7 +927,7 @@ getJasmineRequireObj().Spec = function(j$) {
pendingReason: this.excludeMessage, pendingReason: this.excludeMessage,
duration: null, duration: null,
properties: null, properties: null,
trace: null debugLogs: null
}; };
this.markedPending = this.markedExcluding; this.markedPending = this.markedExcluding;
}; };
@@ -1041,18 +1026,21 @@ getJasmineRequireObj().Spec = function(j$) {
); );
}; };
Spec.prototype.trace = function(msg) { Spec.prototype.debugLog = function(msg) {
if (!this.result.trace) { if (!this.result.debugLogs) {
this.result.trace = []; this.result.debugLogs = [];
} }
/** /**
* @typedef TraceEntry * @typedef DebugLogEntry
* @property {String} message - The message that was passed to {@link jasmine.trace}. * @property {String} message - The message that was passed to {@link jasmine.debugLog}.
* @property {number} timestamp - The time when the entry was added, in * @property {number} timestamp - The time when the entry was added, in
* milliseconds from the spec's start time * milliseconds from the spec's start time
*/ */
this.result.trace.push({ message: msg, timestamp: this.timer.elapsed() }); this.result.debugLogs.push({
message: msg,
timestamp: this.timer.elapsed()
});
}; };
var extractCustomPendingMessage = function(e) { var extractCustomPendingMessage = function(e) {
@@ -2353,14 +2341,14 @@ getJasmineRequireObj().Env = function(j$) {
currentSuite().setSuiteProperty(key, value); currentSuite().setSuiteProperty(key, value);
}; };
this.trace = function(msg) { this.debugLog = function(msg) {
var maybeSpec = currentRunnable(); var maybeSpec = currentRunnable();
if (!maybeSpec || !maybeSpec.trace) { if (!maybeSpec || !maybeSpec.debugLog) {
throw new Error("'trace' was called when there was no current spec"); throw new Error("'debugLog' was called when there was no current spec");
} }
maybeSpec.trace(msg); maybeSpec.debugLog(msg);
}; };
this.expect = function(actual) { this.expect = function(actual) {

View File

@@ -234,7 +234,7 @@ describe('Spec', function() {
pendingReason: '', pendingReason: '',
duration: jasmine.any(Number), duration: jasmine.any(Number),
properties: null, properties: null,
trace: null debugLogs: null
}, },
'things' 'things'
); );
@@ -562,13 +562,15 @@ describe('Spec', function() {
t2 = 456; t2 = 456;
spec.execute(); spec.execute();
expect(spec.result.trace).toBeNull(); expect(spec.result.debugLogs).toBeNull();
timer.elapsed.and.returnValue(t1); timer.elapsed.and.returnValue(t1);
spec.trace('msg 1'); spec.debugLog('msg 1');
expect(spec.result.trace).toEqual([{ message: 'msg 1', timestamp: t1 }]); expect(spec.result.debugLogs).toEqual([
{ message: 'msg 1', timestamp: t1 }
]);
timer.elapsed.and.returnValue(t2); timer.elapsed.and.returnValue(t2);
spec.trace('msg 2'); spec.debugLog('msg 2');
expect(spec.result.trace).toEqual([ expect(spec.result.debugLogs).toEqual([
{ message: 'msg 1', timestamp: t1 }, { message: 'msg 1', timestamp: t1 },
{ message: 'msg 2', timestamp: t2 } { message: 'msg 2', timestamp: t2 }
]); ]);
@@ -583,7 +585,7 @@ describe('Spec', function() {
}, },
resultCallback: resultCallback, resultCallback: resultCallback,
queueRunnerFactory: function(config) { queueRunnerFactory: function(config) {
spec.trace('msg'); spec.debugLog('msg');
for (const fn of config.queueableFns) { for (const fn of config.queueableFns) {
fn.fn(); fn.fn();
} }
@@ -593,7 +595,7 @@ describe('Spec', function() {
spec.execute(function() {}); spec.execute(function() {});
expect(resultCallback).toHaveBeenCalledWith( expect(resultCallback).toHaveBeenCalledWith(
jasmine.objectContaining({ trace: null }), jasmine.objectContaining({ debugLogs: null }),
undefined undefined
); );
}); });
@@ -606,7 +608,7 @@ describe('Spec', function() {
}, },
resultCallback: resultCallback, resultCallback: resultCallback,
queueRunnerFactory: function(config) { queueRunnerFactory: function(config) {
spec.trace('msg'); spec.debugLog('msg');
for (const fn of config.queueableFns) { for (const fn of config.queueableFns) {
fn.fn(); fn.fn();
} }
@@ -616,7 +618,7 @@ describe('Spec', function() {
spec.execute(function() {}); spec.execute(function() {});
expect(resultCallback).toHaveBeenCalled(); expect(resultCallback).toHaveBeenCalled();
expect(spec.result.trace).toBeNull(); expect(spec.result.debugLogs).toBeNull();
}); });
}); });
@@ -630,7 +632,7 @@ describe('Spec', function() {
}, },
resultCallback: resultCallback, resultCallback: resultCallback,
queueRunnerFactory: function(config) { queueRunnerFactory: function(config) {
spec.trace('msg'); spec.debugLog('msg');
spec.onException(new Error('nope')); spec.onException(new Error('nope'));
for (const fn of config.queueableFns) { for (const fn of config.queueableFns) {
fn.fn(); fn.fn();
@@ -646,7 +648,7 @@ describe('Spec', function() {
spec.execute(function() {}); spec.execute(function() {});
expect(resultCallback).toHaveBeenCalledWith( expect(resultCallback).toHaveBeenCalledWith(
jasmine.objectContaining({ jasmine.objectContaining({
trace: [{ message: 'msg', timestamp: timestamp }] debugLogs: [{ message: 'msg', timestamp: timestamp }]
}), }),
undefined undefined
); );

View File

@@ -199,11 +199,13 @@ describe('base helpers', function() {
}); });
}); });
describe('trace', function() { describe('debugLog', function() {
it("forwards to the current env's trace function", function() { it("forwards to the current env's debugLog function", function() {
spyOn(jasmineUnderTest.getEnv(), 'trace'); spyOn(jasmineUnderTest.getEnv(), 'debugLog');
jasmineUnderTest.trace('a message'); jasmineUnderTest.debugLog('a message');
expect(jasmineUnderTest.getEnv().trace).toHaveBeenCalledWith('a message'); expect(jasmineUnderTest.getEnv().debugLog).toHaveBeenCalledWith(
'a message'
);
}); });
}); });
}); });

View File

@@ -3335,7 +3335,7 @@ describe('Env integration', function() {
}); });
}); });
it('sends traces to the reporter when the spec fails', function(done) { it('sends debug logs to the reporter when the spec fails', function(done) {
var reporter = jasmine.createSpyObj('reporter', ['specDone']), var reporter = jasmine.createSpyObj('reporter', ['specDone']),
startTime, startTime,
endTime; endTime;
@@ -3345,14 +3345,14 @@ describe('Env integration', function() {
env.it('fails', function() { env.it('fails', function() {
startTime = new Date().getTime(); startTime = new Date().getTime();
env.trace('message 1'); env.debugLog('message 1');
env.trace('message 2'); env.debugLog('message 2');
env.expect(1).toBe(2); env.expect(1).toBe(2);
endTime = new Date().getTime(); endTime = new Date().getTime();
}); });
env.it('passes', function() { env.it('passes', function() {
env.trace('message that should not be reported'); env.debugLog('message that should not be reported');
}); });
env.execute(null, function() { env.execute(null, function() {
@@ -3373,7 +3373,7 @@ describe('Env integration', function() {
duration = reporter.specDone.calls.argsFor(0)[0].duration; duration = reporter.specDone.calls.argsFor(0)[0].duration;
expect(reporter.specDone.calls.argsFor(0)[0]).toEqual( expect(reporter.specDone.calls.argsFor(0)[0]).toEqual(
jasmine.objectContaining({ jasmine.objectContaining({
trace: [ debugLogs: [
{ {
timestamp: numberInRange(0, duration), timestamp: numberInRange(0, duration),
message: 'message 1' message: 'message 1'
@@ -3385,17 +3385,17 @@ describe('Env integration', function() {
] ]
}) })
); );
expect(reporter.specDone.calls.argsFor(1)[0].trace).toBeFalsy(); expect(reporter.specDone.calls.argsFor(1)[0].debugLogs).toBeFalsy();
done(); done();
}); });
}); });
it('reports an error when trace is used when a spec is not running', function(done) { it('reports an error when debugLog is used when a spec is not running', function(done) {
var reporter = jasmine.createSpyObj('reporter', ['suiteDone']); var reporter = jasmine.createSpyObj('reporter', ['suiteDone']);
env.describe('a suite', function() { env.describe('a suite', function() {
env.beforeAll(function() { env.beforeAll(function() {
env.trace('a message'); env.debugLog('a message');
}); });
env.it('a spec', function() {}); env.it('a spec', function() {});
@@ -3408,7 +3408,7 @@ describe('Env integration', function() {
failedExpectations: [ failedExpectations: [
jasmine.objectContaining({ jasmine.objectContaining({
message: jasmine.stringContaining( message: jasmine.stringContaining(
"'trace' was called when there was no current spec" "'debugLog' was called when there was no current spec"
) )
}) })
] ]

View File

@@ -1510,7 +1510,7 @@ describe('HtmlReporter', function() {
} }
] ]
}; };
var failingSpecResultWithTrace = { var failingSpecResultWithDebugLogs = {
id: 567, id: 567,
status: 'failed', status: 'failed',
description: 'a failing spec', description: 'a failing spec',
@@ -1522,7 +1522,7 @@ describe('HtmlReporter', function() {
stack: 'a stack trace' stack: 'a stack trace'
} }
], ],
trace: [ debugLogs: [
{ timestamp: 123, message: 'msg 1' }, { timestamp: 123, message: 'msg 1' },
{ timestamp: 456, message: 'msg 1' } { timestamp: 456, message: 'msg 1' }
] ]
@@ -1544,8 +1544,8 @@ describe('HtmlReporter', function() {
reporter.suiteDone(passingSuiteResult); reporter.suiteDone(passingSuiteResult);
reporter.suiteDone(failingSuiteResult); reporter.suiteDone(failingSuiteResult);
reporter.suiteDone(passingSuiteResult); reporter.suiteDone(passingSuiteResult);
reporter.specStarted(failingSpecResultWithTrace); reporter.specStarted(failingSpecResultWithDebugLogs);
reporter.specDone(failingSpecResultWithTrace); reporter.specDone(failingSpecResultWithDebugLogs);
reporter.jasmineDone({}); reporter.jasmineDone({});
}); });
@@ -1602,11 +1602,11 @@ describe('HtmlReporter', function() {
var specFailure = container.querySelectorAll( var specFailure = container.querySelectorAll(
'.jasmine-spec-detail.jasmine-failed' '.jasmine-spec-detail.jasmine-failed'
)[2], )[2],
trace = specFailure.querySelector('.jasmine-trace table'), debugLogs = specFailure.querySelector('.jasmine-debug-log table'),
rows; rows;
expect(trace).toBeTruthy(); expect(debugLogs).toBeTruthy();
rows = trace.querySelectorAll('tbody tr'); rows = debugLogs.querySelectorAll('tbody tr');
expect(rows.length).toEqual(2); expect(rows.length).toEqual(2);
}); });

View File

@@ -1190,14 +1190,14 @@ getJasmineRequireObj().Env = function(j$) {
currentSuite().setSuiteProperty(key, value); currentSuite().setSuiteProperty(key, value);
}; };
this.trace = function(msg) { this.debugLog = function(msg) {
var maybeSpec = currentRunnable(); var maybeSpec = currentRunnable();
if (!maybeSpec || !maybeSpec.trace) { if (!maybeSpec || !maybeSpec.debugLog) {
throw new Error("'trace' was called when there was no current spec"); throw new Error("'debugLog' was called when there was no current spec");
} }
maybeSpec.trace(msg); maybeSpec.debugLog(msg);
}; };
this.expect = function(actual) { this.expect = function(actual) {

View File

@@ -71,7 +71,7 @@ getJasmineRequireObj().Spec = function(j$) {
* @property {String} status - Once the spec has completed, this string represents the pass/fail status of this spec. * @property {String} status - Once the spec has completed, this string represents the pass/fail status of this spec.
* @property {number} duration - The time in ms used by the spec execution, including any before/afterEach. * @property {number} duration - The time in ms used by the spec execution, including any before/afterEach.
* @property {Object} properties - User-supplied properties, if any, that were set using {@link Env#setSpecProperty} * @property {Object} properties - User-supplied properties, if any, that were set using {@link Env#setSpecProperty}
* @property {TraceEntry[]|null} trace - Trace messages, if any, that were logged using {@link jasmine.trace} during a failing spec. * @property {DebugLogEntry[]|null} debugLogs - Messages, if any, that were logged using {@link jasmine.debugLog} during a failing spec.
* @since 2.0.0 * @since 2.0.0
*/ */
this.result = { this.result = {
@@ -84,7 +84,7 @@ getJasmineRequireObj().Spec = function(j$) {
pendingReason: '', pendingReason: '',
duration: null, duration: null,
properties: null, properties: null,
trace: null debugLogs: null
}; };
} }
@@ -133,7 +133,7 @@ getJasmineRequireObj().Spec = function(j$) {
self.result.duration = self.timer.elapsed(); self.result.duration = self.timer.elapsed();
if (self.result.status !== 'failed') { if (self.result.status !== 'failed') {
self.result.trace = null; self.result.debugLogs = null;
} }
self.resultCallback(self.result, done); self.resultCallback(self.result, done);
@@ -184,21 +184,6 @@ getJasmineRequireObj().Spec = function(j$) {
}; };
Spec.prototype.reset = function() { Spec.prototype.reset = function() {
/**
* @typedef SpecResult
* @property {Int} id - The unique id of this spec.
* @property {String} description - The description passed to the {@link it} that created this spec.
* @property {String} fullName - The full description including all ancestors of this spec.
* @property {Expectation[]} failedExpectations - The list of expectations that failed during execution of this spec.
* @property {Expectation[]} passedExpectations - The list of expectations that passed during execution of this spec.
* @property {Expectation[]} deprecationWarnings - The list of deprecation warnings that occurred during execution this spec.
* @property {String} pendingReason - If the spec is {@link pending}, this will be the reason.
* @property {String} status - Once the spec has completed, this string represents the pass/fail status of this spec.
* @property {number} duration - The time in ms used by the spec execution, including any before/afterEach.
* @property {Object} properties - User-supplied properties, if any, that were set using {@link Env#setSpecProperty}
* @property {TraceEntry[]|null} trace - Trace messages, if any, that were logged using {@link Env#trace} during a failing spec.
* @since 2.0.0
*/
this.result = { this.result = {
id: this.id, id: this.id,
description: this.description, description: this.description,
@@ -209,7 +194,7 @@ getJasmineRequireObj().Spec = function(j$) {
pendingReason: this.excludeMessage, pendingReason: this.excludeMessage,
duration: null, duration: null,
properties: null, properties: null,
trace: null debugLogs: null
}; };
this.markedPending = this.markedExcluding; this.markedPending = this.markedExcluding;
}; };
@@ -308,18 +293,21 @@ getJasmineRequireObj().Spec = function(j$) {
); );
}; };
Spec.prototype.trace = function(msg) { Spec.prototype.debugLog = function(msg) {
if (!this.result.trace) { if (!this.result.debugLogs) {
this.result.trace = []; this.result.debugLogs = [];
} }
/** /**
* @typedef TraceEntry * @typedef DebugLogEntry
* @property {String} message - The message that was passed to {@link jasmine.trace}. * @property {String} message - The message that was passed to {@link jasmine.debugLog}.
* @property {number} timestamp - The time when the entry was added, in * @property {number} timestamp - The time when the entry was added, in
* milliseconds from the spec's start time * milliseconds from the spec's start time
*/ */
this.result.trace.push({ message: msg, timestamp: this.timer.elapsed() }); this.result.debugLogs.push({
message: msg,
timestamp: this.timer.elapsed()
});
}; };
var extractCustomPendingMessage = function(e) { var extractCustomPendingMessage = function(e) {

View File

@@ -406,11 +406,11 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
* This method should be called only when a spec (including any associated * This method should be called only when a spec (including any associated
* beforeEach or afterEach functions) is running. * beforeEach or afterEach functions) is running.
* @function * @function
* @name jasmine.trace * @name jasmine.debugLog
* @since 3.10.0 * @since 4.0.0
* @param {String} msg - The message to log * @param {String} msg - The message to log
*/ */
j$.trace = function(msg) { j$.debugLog = function(msg) {
j$.getEnv().trace(msg); j$.getEnv().debugLog(msg);
}; };
}; };

View File

@@ -405,17 +405,17 @@ jasmineRequire.HtmlReporter = function(j$) {
); );
} }
if (result.trace) { if (result.debugLogs) {
messages.appendChild(traceTable(result.trace)); messages.appendChild(debugLogTable(result.debugLogs));
} }
return failure; return failure;
} }
function traceTable(trace) { function debugLogTable(debugLogs) {
var tbody = createDom('tbody'); var tbody = createDom('tbody');
trace.forEach(function(entry) { debugLogs.forEach(function(entry) {
tbody.appendChild( tbody.appendChild(
createDom( createDom(
'tr', 'tr',
@@ -428,11 +428,11 @@ jasmineRequire.HtmlReporter = function(j$) {
return createDom( return createDom(
'div', 'div',
{ className: 'jasmine-trace' }, { className: 'jasmine-debug-log' },
createDom( createDom(
'div', 'div',
{ className: 'jasmine-trace-header' }, { className: 'jasmine-debug-log-header' },
'Trace information' 'Debug logs'
), ),
createDom( createDom(
'table', 'table',

View File

@@ -414,7 +414,7 @@ body {
padding: 5px; padding: 5px;
} }
.jasmine-trace { .jasmine-debug-log {
margin: 5px 0 0 0; margin: 5px 0 0 0;
padding: 5px; padding: 5px;
color: $light-text-color; color: $light-text-color;