diff --git a/README.md b/README.md
index e5aa2e3..04aed54 100755
--- a/README.md
+++ b/README.md
@@ -353,6 +353,7 @@ directory. You should add `it.only` to the test case you are working on to speed
## Release Notes
- Add theoretical fix for nested output processor causing file to be rewritten with on after run logging pass. [issue](https://github.com/archfz/cypress-terminal-report/issues/185)
+- Add extra logging for `assert` of the expected and the actual object. [issue](https://github.com/archfz/cypress-terminal-report/issues/184)
#### 5.1.1
diff --git a/src/collector/LogCollectCypressCommand.js b/src/collector/LogCollectCypressCommand.js
index d950a5a..8c50105 100644
--- a/src/collector/LogCollectCypressCommand.js
+++ b/src/collector/LogCollectCypressCommand.js
@@ -15,9 +15,20 @@ module.exports = class LogCollectCypressCommand {
!['xhr', 'log', 'request'].includes(options.name) &&
!(options.name === 'task' && options.message.match(/ctrLogMessages/));
+ const formatLogMessage = (options) => {
+ let message = options.name + '\t' + options.message;
+
+ if (options.expected && options.actual) {
+ message += '\nActual: \t' + JSON.stringify(options.actual);
+ message += '\nExpected: \t' + JSON.stringify(options.expected);
+ }
+
+ return message;
+ };
+
Cypress.on('log:added', (options) => {
if (isOfInterest(options)) {
- const log = options.name + '\t' + options.message;
+ const log = formatLogMessage(options);
const severity = options.state === 'failed' ? CONSTANTS.SEVERITY.ERROR : '';
this.collectorState.addLog([LOG_TYPE.CYPRESS_COMMAND, log, severity], options.id);
}
@@ -25,7 +36,7 @@ module.exports = class LogCollectCypressCommand {
Cypress.on('log:changed', (options) => {
if (isOfInterest(options)) {
- const log = options.name + '\t' + options.message;
+ const log = formatLogMessage(options);
const severity = options.state === 'failed' ? CONSTANTS.SEVERITY.ERROR : CONSTANTS.SEVERITY.SUCCESS;
this.collectorState.updateLog(log, severity, options.id);
}
diff --git a/test/cypress/integration/expects.spec.js b/test/cypress/integration/expects.spec.js
new file mode 100644
index 0000000..c468850
--- /dev/null
+++ b/test/cypress/integration/expects.spec.js
@@ -0,0 +1,12 @@
+///
+// remove no check once Cypress.sinon is typed
+// https://github.com/cypress-io/cypress/issues/6720
+
+context('Expects', () => {
+ it('expects', () => {
+ // https://on.cypress.io/spy
+ cy.visit('https://example.cypress.io/commands/spies-stubs-clocks')
+
+ expect([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]).to.eq([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
+ })
+})
diff --git a/test/cypress/integration/lateCommandUpdate.spec.js b/test/cypress/integration/lateCommandUpdate.spec.js
index 5619609..98b7ce9 100755
--- a/test/cypress/integration/lateCommandUpdate.spec.js
+++ b/test/cypress/integration/lateCommandUpdate.spec.js
@@ -19,6 +19,6 @@ describe("Late command update.", () => {
});
});
- cy.get('.breaking-get', {timeout: 1});
+ cy.get('.breaking-get', {timeout: 5});
});
});
diff --git a/test/output/out.spec.always.json b/test/output/out.spec.always.json
index b426ae0..43e173e 100644
--- a/test/output/out.spec.always.json
+++ b/test/output/out.spec.always.json
@@ -39,7 +39,7 @@
{
"type": "cy:command",
"severity": "success",
- "message": "assert\texpected **200** to equal **200**"
+ "message": "assert\texpected **200** to equal **200**\nActual: \t200\nExpected: \t200"
},
{
"type": "cy:intercept",
@@ -129,7 +129,7 @@
{
"type": "cons:error",
"severity": "error",
- "message": "Error: This is an error message with stack.\n at Context.eval (https://example.cypress.io/__cypress/tests?p=cypress/integration/happyFlow.spec.js:135:43)"
+ "message": "Error: This is an error message with stack.\n at Context.eval (https://example.cypress.io/__cypress/tests?p=cypress/integration/happyFlow.spec.js:140:43)"
},
{
"type": "cy:command",
diff --git a/test/output/out.spec.always.txt b/test/output/out.spec.always.txt
index 6750fad..40cd8e8 100644
--- a/test/output/out.spec.always.txt
+++ b/test/output/out.spec.always.txt
@@ -10,6 +10,8 @@ cypress/integration/happyFlow.spec.js:
cy:command (K): wait @getComment
cy:command (K): its .response.statusCode
cy:command (K): assert expected **200** to equal **200**
+ Actual: 200
+ Expected: 200
cy:intercept (K): Method: POST
Matcher: "/comments"
cy:command (K): get .network-post
@@ -41,7 +43,7 @@ cypress/integration/happyFlow.spec.js:
cons:error (X): This is an error message
cy:command (K): window
cons:error (X): Error: This is an error message with stack.
- at Context.eval (https://example.cypress.io/__cypress/tests?p=cypress/integration/happyFlow.spec.js:135:43)
+ at Context.eval (https://example.cypress.io/__cypress/tests?p=cypress/integration/happyFlow.spec.js:140:43)
cy:command (K): window
cons:log (K): This should console.log appear.
cy:command (K): window
diff --git a/test/output/out.spec.onFail.json b/test/output/out.spec.onFail.json
index 873a001..65c12f8 100644
--- a/test/output/out.spec.onFail.json
+++ b/test/output/out.spec.onFail.json
@@ -39,7 +39,7 @@
{
"type": "cy:command",
"severity": "success",
- "message": "assert\texpected **200** to equal **200**"
+ "message": "assert\texpected **200** to equal **200**\nActual: \t200\nExpected: \t200"
},
{
"type": "cy:intercept",
@@ -129,7 +129,7 @@
{
"type": "cons:error",
"severity": "error",
- "message": "Error: This is an error message with stack.\n at Context.eval (https://example.cypress.io/__cypress/tests?p=cypress/integration/happyFlow.spec.js:135:43)"
+ "message": "Error: This is an error message with stack.\n at Context.eval (https://example.cypress.io/__cypress/tests?p=cypress/integration/happyFlow.spec.js:140:43)"
},
{
"type": "cy:command",
diff --git a/test/output/out.spec.onFail.txt b/test/output/out.spec.onFail.txt
index 6240f0d..fe2e49b 100644
--- a/test/output/out.spec.onFail.txt
+++ b/test/output/out.spec.onFail.txt
@@ -10,6 +10,8 @@ cypress/integration/happyFlow.spec.js:
cy:command (K): wait @getComment
cy:command (K): its .response.statusCode
cy:command (K): assert expected **200** to equal **200**
+ Actual: 200
+ Expected: 200
cy:intercept (K): Method: POST
Matcher: "/comments"
cy:command (K): get .network-post
@@ -41,7 +43,7 @@ cypress/integration/happyFlow.spec.js:
cons:error (X): This is an error message
cy:command (K): window
cons:error (X): Error: This is an error message with stack.
- at Context.eval (https://example.cypress.io/__cypress/tests?p=cypress/integration/happyFlow.spec.js:135:43)
+ at Context.eval (https://example.cypress.io/__cypress/tests?p=cypress/integration/happyFlow.spec.js:140:43)
cy:command (K): window
cons:log (K): This should console.log appear.
cy:command (K): window
diff --git a/test/output_nested_cucumber_spec/json/cucumber/Happy.json b/test/output_nested_cucumber_spec/json/cucumber/Happy.json
index 041ca67..7a3add5 100644
--- a/test/output_nested_cucumber_spec/json/cucumber/Happy.json
+++ b/test/output_nested_cucumber_spec/json/cucumber/Happy.json
@@ -14,7 +14,7 @@
{
"type": "cy:command",
"severity": "success",
- "message": "assert\texpected **0** to be below **2**"
+ "message": "assert\texpected **0** to be below **2**\nActual: \t0\nExpected: \t2"
},
{
"type": "cy:command",
@@ -76,7 +76,7 @@
{
"type": "cy:command",
"severity": "success",
- "message": "assert\texpected **1** to be below **2**"
+ "message": "assert\texpected **1** to be below **2**\nActual: \t1\nExpected: \t2"
},
{
"type": "cy:command",
@@ -130,4 +130,4 @@
}
]
}
-}
\ No newline at end of file
+}
diff --git a/test/output_nested_spec/json/callsSuiteInAnotherFile.spec.json b/test/output_nested_spec/json/callsSuiteInAnotherFile.spec.json
index 40118eb..b9399e4 100644
--- a/test/output_nested_spec/json/callsSuiteInAnotherFile.spec.json
+++ b/test/output_nested_spec/json/callsSuiteInAnotherFile.spec.json
@@ -4,15 +4,15 @@
{
"type": "cy:command",
"severity": "error",
- "message": "assert\texpected **1** to equal **2**"
+ "message": "assert\texpected **1** to equal **2**\nActual: \t1\nExpected: \t2"
}
],
"Calls function in another file that creates a sub-suite. -> sub-suite in different file -> subsuite test 2": [
{
"type": "cy:command",
"severity": "error",
- "message": "assert\texpected **1** to equal **2**"
+ "message": "assert\texpected **1** to equal **2**\nActual: \t1\nExpected: \t2"
}
]
}
-}
\ No newline at end of file
+}
diff --git a/test/output_nested_spec/json/happyFlow.spec.json b/test/output_nested_spec/json/happyFlow.spec.json
index c045885..e07a202 100644
--- a/test/output_nested_spec/json/happyFlow.spec.json
+++ b/test/output_nested_spec/json/happyFlow.spec.json
@@ -39,7 +39,7 @@
{
"type": "cy:command",
"severity": "success",
- "message": "assert\texpected **200** to equal **200**"
+ "message": "assert\texpected **200** to equal **200**\nActual: \t200\nExpected: \t200"
},
{
"type": "cy:intercept",
@@ -129,7 +129,7 @@
{
"type": "cons:error",
"severity": "error",
- "message": "Error: This is an error message with stack.\n at Context.eval (https://example.cypress.io/__cypress/tests?p=cypress/integration/happyFlow.spec.js:135:43)"
+ "message": "Error: This is an error message with stack.\n at Context.eval (https://example.cypress.io/__cypress/tests?p=cypress/integration/happyFlow.spec.js:140:43)"
},
{
"type": "cy:command",
@@ -213,4 +213,4 @@
}
]
}
-}
\ No newline at end of file
+}
diff --git a/test/output_nested_spec/txt/callsSuiteInAnotherFile.spec.txt b/test/output_nested_spec/txt/callsSuiteInAnotherFile.spec.txt
index 3b8ab94..8e03fd2 100644
--- a/test/output_nested_spec/txt/callsSuiteInAnotherFile.spec.txt
+++ b/test/output_nested_spec/txt/callsSuiteInAnotherFile.spec.txt
@@ -1,7 +1,11 @@
cypress/integration/callsSuiteInAnotherFile.spec.js:
Calls function in another file that creates a sub-suite. -> the test 2
cy:command (X): assert expected **1** to equal **2**
+ Actual: 1
+ Expected: 2
Calls function in another file that creates a sub-suite. -> sub-suite in different file -> subsuite test 2
cy:command (X): assert expected **1** to equal **2**
+ Actual: 1
+ Expected: 2
diff --git a/test/output_nested_spec/txt/happyFlow.spec.txt b/test/output_nested_spec/txt/happyFlow.spec.txt
index d62b439..225f183 100644
--- a/test/output_nested_spec/txt/happyFlow.spec.txt
+++ b/test/output_nested_spec/txt/happyFlow.spec.txt
@@ -10,6 +10,8 @@ cypress/integration/happyFlow.spec.js:
cy:command (K): wait @getComment
cy:command (K): its .response.statusCode
cy:command (K): assert expected **200** to equal **200**
+ Actual: 200
+ Expected: 200
cy:intercept (K): Method: POST
Matcher: "/comments"
cy:command (K): get .network-post
@@ -41,7 +43,7 @@ cypress/integration/happyFlow.spec.js:
cons:error (X): This is an error message
cy:command (K): window
cons:error (X): Error: This is an error message with stack.
- at Context.eval (https://example.cypress.io/__cypress/tests?p=cypress/integration/happyFlow.spec.js:135:43)
+ at Context.eval (https://example.cypress.io/__cypress/tests?p=cypress/integration/happyFlow.spec.js:140:43)
cy:command (K): window
cons:log (K): This should console.log appear.
cy:command (K): window
diff --git a/test/specs/commandsLogging.spec.js b/test/specs/commandsLogging.spec.js
index 2a2dcec..1aaaff1 100755
--- a/test/specs/commandsLogging.spec.js
+++ b/test/specs/commandsLogging.spec.js
@@ -191,8 +191,21 @@ describe('Commands logging.', () => {
const cleanStdout = clean(stdout, true);
expect(cleanStdout).to.contain(
`cy:command ${ICONS.success} assert\texpected **** to have text **something else**
+ Actual: \t"something else"
+ Expected: \t"something else"
cy:command ${ICONS.error} get\tbreaking`,
);
});
}).timeout(60000);
+
+ it('Should log expected and actual for assert command.', async () => {
+ await runTest(commandBase([], ['expects.spec.js']), (error, stdout, stderr) => {
+ const cleanStdout = clean(stdout, true);
+ expect(cleanStdout).to.contain(
+ `cy:command ${ICONS.error} assert\texpected **[ Array(12) ]** to equal **[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]**
+ Actual: \t[1,2,3,4,5,6,7,8,9,10,11,12]
+ Expected: \t[1,2,3,4,5,6,7,8,9,10]`,
+ );
+ });
+ }).timeout(60000);
});
diff --git a/test/specs/misc.spec.js b/test/specs/misc.spec.js
index 16b1656..98156da 100755
--- a/test/specs/misc.spec.js
+++ b/test/specs/misc.spec.js
@@ -46,7 +46,8 @@ describe('Misc.', () => {
});
}).timeout(60000);
- it('Should filter and process late update logs correctly.', async () => {
+ it('Should filter and process late update logs correctly.', async function() {
+ this.retries(2);
await runTest(commandBase(['filterKeepOnlyWarningAndError=1,processAllLogs=1'], ['lateCommandUpdate.spec.js']), (error, stdout, stderr) => {
expect(stdout).to.contain(`cy:command ${ICONS.error} | get\t.breaking-get`);
expect(stdout).to.contain(`cy:xhr ${ICONS.warning} | STUBBED PUT https://example.cypress.io/comments/10
diff --git a/test/specs/otherPluginIntegration.spec.js b/test/specs/otherPluginIntegration.spec.js
index aa8909f..4686ddb 100755
--- a/test/specs/otherPluginIntegration.spec.js
+++ b/test/specs/otherPluginIntegration.spec.js
@@ -60,6 +60,8 @@ describe('Other plugin integrations.', () => {
cy:command (K): get\t[href="https://on.cypress.io/request"]
cy:command (K): first
cy:command (K): assert\texpected **** to have text **something else**
+ Actual: \t"something else"
+ Expected: \t"something else"
cy:command (X): get\tbreaking`);
});
}).timeout(90000);