Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposing filename in JSON, doc, and json-stream reporters #4219

Merged
merged 5 commits into from May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/reporters/doc.js
Expand Up @@ -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);
});
Expand All @@ -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>',
Expand Down
1 change: 1 addition & 0 deletions lib/reporters/json-stream.js
Expand Up @@ -82,6 +82,7 @@ function clean(test) {
return {
title: test.title,
fullTitle: test.fullTitle(),
file: test.file,
duration: test.duration,
currentRetry: test.currentRetry()
};
Expand Down
1 change: 1 addition & 0 deletions lib/reporters/json.js
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions test/reporters/doc.spec.js
Expand Up @@ -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 '';
Expand All @@ -148,25 +150,31 @@ 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);
});

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 =
'&#x3C;div&#x3E;' + expectedTitle + '&#x3C;/div&#x3E;';
var expectedEscapedFile =
'&#x3C;div&#x3E;' + expectedFile + '&#x3C;/div&#x3E;';
var expectedEscapedBody =
'&#x3C;div&#x3E;' + expectedBody + '&#x3C;/div&#x3E;';
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);
Expand All @@ -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 '';
Expand All @@ -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',
Expand All @@ -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 =
'&#x3C;div&#x3E;' + expectedTitle + '&#x3C;/div&#x3E;';
var expectedEscapedFile =
'&#x3C;div&#x3E;' + expectedFile + '&#x3C;/div&#x3E;';
var expectedEscapedBody =
'&#x3C;div&#x3E;' + expectedBody + '&#x3C;/div&#x3E;';
var expectedEscapedError =
Expand All @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions test/reporters/helpers.js
Expand Up @@ -163,6 +163,7 @@ function createElements(argObj) {
function makeExpectedTest(
expectedTitle,
expectedFullTitle,
expectedFile,
expectedDuration,
currentRetry,
expectedBody
Expand All @@ -172,6 +173,7 @@ function makeExpectedTest(
fullTitle: function() {
return expectedFullTitle;
},
file: expectedFile,
duration: expectedDuration,
currentRetry: function() {
return currentRetry;
Expand Down
8 changes: 8 additions & 0 deletions test/reporters/json-stream.spec.js
Expand Up @@ -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
);
Expand Down Expand Up @@ -70,6 +72,8 @@ describe('JSON Stream reporter', function() {
dQuote(expectedTitle) +
',"fullTitle":' +
dQuote(expectedFullTitle) +
',"file":' +
dQuote(expectedFile) +
',"duration":' +
expectedDuration +
',"currentRetry":' +
Expand Down Expand Up @@ -101,6 +105,8 @@ describe('JSON Stream reporter', function() {
dQuote(expectedTitle) +
',"fullTitle":' +
dQuote(expectedFullTitle) +
',"file":' +
dQuote(expectedFile) +
',"duration":' +
expectedDuration +
',"currentRetry":' +
Expand Down Expand Up @@ -135,6 +141,8 @@ describe('JSON Stream reporter', function() {
dQuote(expectedTitle) +
',"fullTitle":' +
dQuote(expectedFullTitle) +
',"file":' +
dQuote(expectedFile) +
',"duration":' +
expectedDuration +
',"currentRetry":' +
Expand Down
32 changes: 20 additions & 12 deletions test/reporters/json.spec.js
Expand Up @@ -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() {
Expand All @@ -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();
Expand All @@ -49,6 +51,7 @@ describe('JSON reporter', function() {
failures: [
{
title: testTitle,
file: testFile,
err: {
message: error.message
}
Expand All @@ -62,15 +65,18 @@ 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();
expect(runner, 'to satisfy', {
testResults: {
pending: [
{
title: testTitle
title: testTitle,
file: testFile
}
]
}
Expand All @@ -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();
Expand All @@ -101,6 +108,7 @@ describe('JSON reporter', function() {
failures: [
{
title: testTitle,
file: testFile,
err: {
message: error.message
}
Expand Down