From 40fac8b6a27bc40d6e14eadba640d0429886411a Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Thu, 2 Dec 2021 14:46:56 -0800 Subject: [PATCH] Renamed the trace feature to debugLog[s] "trace" was ambiguous and could easily be understood to have something to do with stack traces. --- lib/jasmine-core/jasmine-html.js | 14 ++++----- lib/jasmine-core/jasmine.css | 6 ++-- lib/jasmine-core/jasmine.js | 54 +++++++++++++------------------- spec/core/SpecSpec.js | 26 ++++++++------- spec/core/baseSpec.js | 12 ++++--- spec/core/integration/EnvSpec.js | 18 +++++------ spec/html/HtmlReporterSpec.js | 14 ++++----- src/core/Env.js | 8 ++--- src/core/Spec.js | 38 ++++++++-------------- src/core/base.js | 8 ++--- src/html/HtmlReporter.js | 14 ++++----- src/html/_HTMLReporter.scss | 2 +- 12 files changed, 97 insertions(+), 117 deletions(-) diff --git a/lib/jasmine-core/jasmine-html.js b/lib/jasmine-core/jasmine-html.js index 8e4917b7..4b1454b5 100644 --- a/lib/jasmine-core/jasmine-html.js +++ b/lib/jasmine-core/jasmine-html.js @@ -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', diff --git a/lib/jasmine-core/jasmine.css b/lib/jasmine-core/jasmine.css index 9c70317f..70ab3592 100644 --- a/lib/jasmine-core/jasmine.css +++ b/lib/jasmine-core/jasmine.css @@ -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; } \ No newline at end of file diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 0452e26a..b6301afd 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -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) { diff --git a/spec/core/SpecSpec.js b/spec/core/SpecSpec.js index 6abb1f9e..9efebbdf 100644 --- a/spec/core/SpecSpec.js +++ b/spec/core/SpecSpec.js @@ -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 ); diff --git a/spec/core/baseSpec.js b/spec/core/baseSpec.js index 9cd94bd7..703a4f50 100644 --- a/spec/core/baseSpec.js +++ b/spec/core/baseSpec.js @@ -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' + ); }); }); }); diff --git a/spec/core/integration/EnvSpec.js b/spec/core/integration/EnvSpec.js index e800f184..c46adbee 100644 --- a/spec/core/integration/EnvSpec.js +++ b/spec/core/integration/EnvSpec.js @@ -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" ) }) ] diff --git a/spec/html/HtmlReporterSpec.js b/spec/html/HtmlReporterSpec.js index 32350f81..d31a3a35 100644 --- a/spec/html/HtmlReporterSpec.js +++ b/spec/html/HtmlReporterSpec.js @@ -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); }); diff --git a/src/core/Env.js b/src/core/Env.js index b5be2ed0..7de139b3 100644 --- a/src/core/Env.js +++ b/src/core/Env.js @@ -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) { diff --git a/src/core/Spec.js b/src/core/Spec.js index e0a86dd8..f9a774a8 100644 --- a/src/core/Spec.js +++ b/src/core/Spec.js @@ -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) { diff --git a/src/core/base.js b/src/core/base.js index c0a13503..2e953541 100644 --- a/src/core/base.js +++ b/src/core/base.js @@ -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); }; }; diff --git a/src/html/HtmlReporter.js b/src/html/HtmlReporter.js index 7a3afc41..840bbcf3 100644 --- a/src/html/HtmlReporter.js +++ b/src/html/HtmlReporter.js @@ -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', diff --git a/src/html/_HTMLReporter.scss b/src/html/_HTMLReporter.scss index bd8537c4..712f6fbb 100644 --- a/src/html/_HTMLReporter.scss +++ b/src/html/_HTMLReporter.scss @@ -414,7 +414,7 @@ body { padding: 5px; } - .jasmine-trace { + .jasmine-debug-log { margin: 5px 0 0 0; padding: 5px; color: $light-text-color;