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

View File

@@ -288,16 +288,16 @@ body {
margin-left: 14px;
padding: 5px;
}
.jasmine_html-reporter .jasmine-trace {
.jasmine_html-reporter .jasmine-debug-log {
margin: 5px 0 0 0;
padding: 5px;
color: #666;
border: 1px solid #ddd;
background: white;
}
.jasmine_html-reporter .jasmine-trace table {
.jasmine_html-reporter .jasmine-debug-log table {
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;
}

View File

@@ -575,12 +575,12 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
* This method should be called only when a spec (including any associated
* beforeEach or afterEach functions) is running.
* @function
* @name jasmine.trace
* @since 3.10.0
* @name jasmine.debugLog
* @since 4.0.0
* @param {String} msg - The message to log
*/
j$.trace = function(msg) {
j$.getEnv().trace(msg);
j$.debugLog = function(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 {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 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
*/
this.result = {
@@ -817,7 +817,7 @@ getJasmineRequireObj().Spec = function(j$) {
pendingReason: '',
duration: null,
properties: null,
trace: null
debugLogs: null
};
}
@@ -866,7 +866,7 @@ getJasmineRequireObj().Spec = function(j$) {
self.result.duration = self.timer.elapsed();
if (self.result.status !== 'failed') {
self.result.trace = null;
self.result.debugLogs = null;
}
self.resultCallback(self.result, done);
@@ -917,21 +917,6 @@ getJasmineRequireObj().Spec = function(j$) {
};
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 = {
id: this.id,
description: this.description,
@@ -942,7 +927,7 @@ getJasmineRequireObj().Spec = function(j$) {
pendingReason: this.excludeMessage,
duration: null,
properties: null,
trace: null
debugLogs: null
};
this.markedPending = this.markedExcluding;
};
@@ -1041,18 +1026,21 @@ getJasmineRequireObj().Spec = function(j$) {
);
};
Spec.prototype.trace = function(msg) {
if (!this.result.trace) {
this.result.trace = [];
Spec.prototype.debugLog = function(msg) {
if (!this.result.debugLogs) {
this.result.debugLogs = [];
}
/**
* @typedef TraceEntry
* @property {String} message - The message that was passed to {@link jasmine.trace}.
* @typedef DebugLogEntry
* @property {String} message - The message that was passed to {@link jasmine.debugLog}.
* @property {number} timestamp - The time when the entry was added, in
* 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) {
@@ -2353,14 +2341,14 @@ getJasmineRequireObj().Env = function(j$) {
currentSuite().setSuiteProperty(key, value);
};
this.trace = function(msg) {
this.debugLog = function(msg) {
var maybeSpec = currentRunnable();
if (!maybeSpec || !maybeSpec.trace) {
throw new Error("'trace' was called when there was no current spec");
if (!maybeSpec || !maybeSpec.debugLog) {
throw new Error("'debugLog' was called when there was no current spec");
}
maybeSpec.trace(msg);
maybeSpec.debugLog(msg);
};
this.expect = function(actual) {

View File

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

View File

@@ -199,11 +199,13 @@ describe('base helpers', function() {
});
});
describe('trace', function() {
it("forwards to the current env's trace function", function() {
spyOn(jasmineUnderTest.getEnv(), 'trace');
jasmineUnderTest.trace('a message');
expect(jasmineUnderTest.getEnv().trace).toHaveBeenCalledWith('a message');
describe('debugLog', function() {
it("forwards to the current env's debugLog function", function() {
spyOn(jasmineUnderTest.getEnv(), 'debugLog');
jasmineUnderTest.debugLog('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']),
startTime,
endTime;
@@ -3345,14 +3345,14 @@ describe('Env integration', function() {
env.it('fails', function() {
startTime = new Date().getTime();
env.trace('message 1');
env.trace('message 2');
env.debugLog('message 1');
env.debugLog('message 2');
env.expect(1).toBe(2);
endTime = new Date().getTime();
});
env.it('passes', function() {
env.trace('message that should not be reported');
env.debugLog('message that should not be reported');
});
env.execute(null, function() {
@@ -3373,7 +3373,7 @@ describe('Env integration', function() {
duration = reporter.specDone.calls.argsFor(0)[0].duration;
expect(reporter.specDone.calls.argsFor(0)[0]).toEqual(
jasmine.objectContaining({
trace: [
debugLogs: [
{
timestamp: numberInRange(0, duration),
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();
});
});
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']);
env.describe('a suite', function() {
env.beforeAll(function() {
env.trace('a message');
env.debugLog('a message');
});
env.it('a spec', function() {});
@@ -3408,7 +3408,7 @@ describe('Env integration', function() {
failedExpectations: [
jasmine.objectContaining({
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,
status: 'failed',
description: 'a failing spec',
@@ -1522,7 +1522,7 @@ describe('HtmlReporter', function() {
stack: 'a stack trace'
}
],
trace: [
debugLogs: [
{ timestamp: 123, message: 'msg 1' },
{ timestamp: 456, message: 'msg 1' }
]
@@ -1544,8 +1544,8 @@ describe('HtmlReporter', function() {
reporter.suiteDone(passingSuiteResult);
reporter.suiteDone(failingSuiteResult);
reporter.suiteDone(passingSuiteResult);
reporter.specStarted(failingSpecResultWithTrace);
reporter.specDone(failingSpecResultWithTrace);
reporter.specStarted(failingSpecResultWithDebugLogs);
reporter.specDone(failingSpecResultWithDebugLogs);
reporter.jasmineDone({});
});
@@ -1602,11 +1602,11 @@ describe('HtmlReporter', function() {
var specFailure = container.querySelectorAll(
'.jasmine-spec-detail.jasmine-failed'
)[2],
trace = specFailure.querySelector('.jasmine-trace table'),
debugLogs = specFailure.querySelector('.jasmine-debug-log table'),
rows;
expect(trace).toBeTruthy();
rows = trace.querySelectorAll('tbody tr');
expect(debugLogs).toBeTruthy();
rows = debugLogs.querySelectorAll('tbody tr');
expect(rows.length).toEqual(2);
});

View File

@@ -1190,14 +1190,14 @@ getJasmineRequireObj().Env = function(j$) {
currentSuite().setSuiteProperty(key, value);
};
this.trace = function(msg) {
this.debugLog = function(msg) {
var maybeSpec = currentRunnable();
if (!maybeSpec || !maybeSpec.trace) {
throw new Error("'trace' was called when there was no current spec");
if (!maybeSpec || !maybeSpec.debugLog) {
throw new Error("'debugLog' was called when there was no current spec");
}
maybeSpec.trace(msg);
maybeSpec.debugLog(msg);
};
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 {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 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
*/
this.result = {
@@ -84,7 +84,7 @@ getJasmineRequireObj().Spec = function(j$) {
pendingReason: '',
duration: null,
properties: null,
trace: null
debugLogs: null
};
}
@@ -133,7 +133,7 @@ getJasmineRequireObj().Spec = function(j$) {
self.result.duration = self.timer.elapsed();
if (self.result.status !== 'failed') {
self.result.trace = null;
self.result.debugLogs = null;
}
self.resultCallback(self.result, done);
@@ -184,21 +184,6 @@ getJasmineRequireObj().Spec = function(j$) {
};
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 = {
id: this.id,
description: this.description,
@@ -209,7 +194,7 @@ getJasmineRequireObj().Spec = function(j$) {
pendingReason: this.excludeMessage,
duration: null,
properties: null,
trace: null
debugLogs: null
};
this.markedPending = this.markedExcluding;
};
@@ -308,18 +293,21 @@ getJasmineRequireObj().Spec = function(j$) {
);
};
Spec.prototype.trace = function(msg) {
if (!this.result.trace) {
this.result.trace = [];
Spec.prototype.debugLog = function(msg) {
if (!this.result.debugLogs) {
this.result.debugLogs = [];
}
/**
* @typedef TraceEntry
* @property {String} message - The message that was passed to {@link jasmine.trace}.
* @typedef DebugLogEntry
* @property {String} message - The message that was passed to {@link jasmine.debugLog}.
* @property {number} timestamp - The time when the entry was added, in
* 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) {

View File

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

View File

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

View File

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