☕️ Classic, reliable, trusted test framework for Node.js and the browser
Exposing filename in JSON, doc, and json-stream reporters (#4219)
Daniel01139c965c910e54
diff --git a/lib/reporters/doc.js b/lib/reporters/doc.jsindex 5a6af8fb..fd6b4693 100644--- a/lib/reporters/doc.js+++ b/lib/reporters/doc.js@@ -62,6 +62,7 @@ function Doc(runner, options) {runner.on(EVENT_TEST_PASS, function(test) {Base.consoleLog('%s <dt>%s</dt>', indent(), utils.escape(test.title));+ Base.consoleLog('%s <dt>%s</dt>', indent(), utils.escape(test.file));var code = utils.escape(utils.clean(test.body));Base.consoleLog('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);});@@ -72,6 +73,11 @@ function Doc(runner, options) {indent(),utils.escape(test.title));+ Base.consoleLog(+ '%s <dt class="error">%s</dt>',+ indent(),+ utils.escape(test.file)+ );var code = utils.escape(utils.clean(test.body));Base.consoleLog('%s <dd class="error"><pre><code>%s</code></pre></dd>',diff --git a/lib/reporters/json-stream.js b/lib/reporters/json-stream.jsindex 27282987..8caa8adf 100644--- a/lib/reporters/json-stream.js+++ b/lib/reporters/json-stream.js@@ -82,6 +82,7 @@ function clean(test) {return {title: test.title,fullTitle: test.fullTitle(),+ file: test.file,duration: test.duration,currentRetry: test.currentRetry()};diff --git a/lib/reporters/json.js b/lib/reporters/json.jsindex 12b6289c..a46776ba 100644--- a/lib/reporters/json.js+++ b/lib/reporters/json.js@@ -87,6 +87,7 @@ function clean(test) {return {title: test.title,fullTitle: test.fullTitle(),+ file: test.file,duration: test.duration,currentRetry: test.currentRetry(),err: cleanCycles(err)diff --git a/test/reporters/doc.spec.js b/test/reporters/doc.spec.jsindex fb2703f8..ce84a5a1 100644--- a/test/reporters/doc.spec.js+++ b/test/reporters/doc.spec.js@@ -134,9 +134,11 @@ describe('Doc reporter', function() {describe("on 'pass' event", function() {var expectedTitle = 'some tite';+ var expectedFile = 'testFile.spec.js';var expectedBody = 'some body';var test = {title: expectedTitle,+ file: expectedFile,body: expectedBody,slow: function() {return '';@@ -148,6 +150,7 @@ describe('Doc reporter', function() {var stdout = runReporter(this, runner, options);var expectedArray = [' <dt>' + expectedTitle + '</dt>\n',+ ' <dt>' + expectedFile + '</dt>\n',' <dd><pre><code>' + expectedBody + '</code></pre></dd>\n'];expect(stdout, 'to equal', expectedArray);@@ -155,18 +158,23 @@ describe('Doc reporter', function() {it('should escape title and body where necessary', function() {var unescapedTitle = '<div>' + expectedTitle + '</div>';+ var unescapedFile = '<div>' + expectedFile + '</div>';var unescapedBody = '<div>' + expectedBody + '</div>';test.title = unescapedTitle;+ test.file = unescapedFile;test.body = unescapedBody;var expectedEscapedTitle ='<div>' + expectedTitle + '</div>';+ var expectedEscapedFile =+ '<div>' + expectedFile + '</div>';var expectedEscapedBody ='<div>' + expectedBody + '</div>';runner = createMockRunner('pass', EVENT_TEST_PASS, null, null, test);var stdout = runReporter(this, runner, options);var expectedArray = [' <dt>' + expectedEscapedTitle + '</dt>\n',+ ' <dt>' + expectedEscapedFile + '</dt>\n',' <dd><pre><code>' + expectedEscapedBody + '</code></pre></dd>\n'];expect(stdout, 'to equal', expectedArray);@@ -175,10 +183,12 @@ describe('Doc reporter', function() {describe("on 'fail' event", function() {var expectedTitle = 'some tite';+ var expectedFile = 'testFile.spec.js';var expectedBody = 'some body';var expectedError = 'some error';var test = {title: expectedTitle,+ file: expectedFile,body: expectedBody,slow: function() {return '';@@ -197,6 +207,7 @@ describe('Doc reporter', function() {var stdout = runReporter(this, runner, options);var expectedArray = [' <dt class="error">' + expectedTitle + '</dt>\n',+ ' <dt class="error">' + expectedFile + '</dt>\n',' <dd class="error"><pre><code>' +expectedBody +'</code></pre></dd>\n',@@ -207,13 +218,17 @@ describe('Doc reporter', function() {it('should escape title, body, and error where necessary', function() {var unescapedTitle = '<div>' + expectedTitle + '</div>';+ var unescapedFile = '<div>' + expectedFile + '</div>';var unescapedBody = '<div>' + expectedBody + '</div>';var unescapedError = '<div>' + expectedError + '</div>';test.title = unescapedTitle;+ test.file = unescapedFile;test.body = unescapedBody;var expectedEscapedTitle ='<div>' + expectedTitle + '</div>';+ var expectedEscapedFile =+ '<div>' + expectedFile + '</div>';var expectedEscapedBody ='<div>' + expectedBody + '</div>';var expectedEscapedError =@@ -229,6 +244,7 @@ describe('Doc reporter', function() {var stdout = runReporter(this, runner, options);var expectedArray = [' <dt class="error">' + expectedEscapedTitle + '</dt>\n',+ ' <dt class="error">' + expectedEscapedFile + '</dt>\n',' <dd class="error"><pre><code>' +expectedEscapedBody +'</code></pre></dd>\n',diff --git a/test/reporters/helpers.js b/test/reporters/helpers.jsindex 45c4d916..f712e19e 100644--- a/test/reporters/helpers.js+++ b/test/reporters/helpers.js@@ -163,6 +163,7 @@ function createElements(argObj) {function makeExpectedTest(expectedTitle,expectedFullTitle,+ expectedFile,expectedDuration,currentRetry,expectedBody@@ -172,6 +173,7 @@ function makeExpectedTest(fullTitle: function() {return expectedFullTitle;},+ file: expectedFile,duration: expectedDuration,currentRetry: function() {return currentRetry;diff --git a/test/reporters/json-stream.spec.js b/test/reporters/json-stream.spec.jsindex de83f861..613b9279 100644--- a/test/reporters/json-stream.spec.js+++ b/test/reporters/json-stream.spec.js@@ -20,11 +20,13 @@ describe('JSON Stream reporter', function() {var runReporter = makeRunReporter(JSONStream);var expectedTitle = 'some title';var expectedFullTitle = 'full title';+ var expectedFile = 'someTest.spec.js';var expectedDuration = 1000;var currentRetry = 1;var expectedTest = makeExpectedTest(expectedTitle,expectedFullTitle,+ expectedFile,expectedDuration,currentRetry);@@ -70,6 +72,8 @@ describe('JSON Stream reporter', function() {dQuote(expectedTitle) +',"fullTitle":' +dQuote(expectedFullTitle) ++ ',"file":' ++ dQuote(expectedFile) +',"duration":' +expectedDuration +',"currentRetry":' +@@ -101,6 +105,8 @@ describe('JSON Stream reporter', function() {dQuote(expectedTitle) +',"fullTitle":' +dQuote(expectedFullTitle) ++ ',"file":' ++ dQuote(expectedFile) +',"duration":' +expectedDuration +',"currentRetry":' +@@ -135,6 +141,8 @@ describe('JSON Stream reporter', function() {dQuote(expectedTitle) +',"fullTitle":' +dQuote(expectedFullTitle) ++ ',"file":' ++ dQuote(expectedFile) +',"duration":' +expectedDuration +',"currentRetry":' +diff --git a/test/reporters/json.spec.js b/test/reporters/json.spec.jsindex f6299dd1..9aa7e7a2 100644--- a/test/reporters/json.spec.js+++ b/test/reporters/json.spec.js@@ -11,6 +11,7 @@ describe('JSON reporter', function() {var suite;var runner;var testTitle = 'json test 1';+ var testFile = 'someTest.spec.js';var noop = function() {};beforeEach(function() {@@ -36,11 +37,12 @@ describe('JSON reporter', function() {it('should have 1 test failure', function(done) {var error = {message: 'oh shit'};- suite.addTest(- new Test(testTitle, function(done) {- done(new Error(error.message));- })- );+ var test = new Test(testTitle, function(done) {+ done(new Error(error.message));+ });++ test.file = testFile;+ suite.addTest(test);runner.run(function(failureCount) {sandbox.restore();@@ -49,6 +51,7 @@ describe('JSON reporter', function() {failures: [{title: testTitle,+ file: testFile,err: {message: error.message}@@ -62,7 +65,9 @@ describe('JSON reporter', function() {});it('should have 1 test pending', function(done) {- suite.addTest(new Test(testTitle));+ var test = new Test(testTitle);+ test.file = testFile;+ suite.addTest(test);runner.run(function(failureCount) {sandbox.restore();@@ -70,7 +75,8 @@ describe('JSON reporter', function() {testResults: {pending: [{- title: testTitle+ title: testTitle,+ file: testFile}]}@@ -88,11 +94,12 @@ describe('JSON reporter', function() {}var error = new CircleError();- suite.addTest(- new Test(testTitle, function(done) {- throw error;- })- );+ var test = new Test(testTitle, function(done) {+ throw error;+ });++ test.file = testFile;+ suite.addTest(test);runner.run(function(failureCount) {sandbox.restore();@@ -101,6 +108,7 @@ describe('JSON reporter', function() {failures: [{title: testTitle,+ file: testFile,err: {message: error.message}