-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1363 from oasisprotocol/lw/cypress-console-log
ts-web/*: Cypress forward console logs from browser to terminal
- Loading branch information
Showing
11 changed files
with
70 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import {defineConfig} from 'cypress'; | ||
import * as outputConsoleLogs from './cypress/outputConsoleLogs'; | ||
|
||
export default defineConfig({ | ||
video: false, | ||
e2e: { | ||
supportFile: false, | ||
setupNodeEvents: outputConsoleLogs.setupNodeEvents, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** Usage: add to cypress config */ | ||
export const setupNodeEvents: Cypress.Config['setupNodeEvents'] = (on, config) => { | ||
on('task', { | ||
consoleLog(stringifiedArray) { | ||
console.log('console.log', ...JSON.parse(stringifiedArray)) | ||
return null | ||
}, | ||
consoleWarn(stringifiedArray) { | ||
console.warn('console.warn', ...JSON.parse(stringifiedArray)) | ||
return null | ||
}, | ||
consoleError(stringifiedArray) { | ||
console.error('console.error', ...JSON.parse(stringifiedArray)) | ||
return null | ||
}, | ||
}); | ||
}; | ||
|
||
/** Usage: call before a test */ | ||
export function beforeWindowLoadListener() { | ||
before(() => { | ||
Cypress.on('window:before:load', (w) => { | ||
cy.stub(w.console, 'log').callsFake((...args) => consoleTask('consoleLog', ...args)); | ||
cy.stub(w.console, 'warn').callsFake((...args) => consoleTask('consoleWarn', ...args)); | ||
cy.stub(w.console, 'error').callsFake((...args) => consoleTask('consoleError', ...args)); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Workaround: `cy.task('consoleLog', stringifiedArray)` throws because cypress command is inside cypress command. | ||
*/ | ||
function consoleTask(taskName: 'consoleLog' | 'consoleWarn' | 'consoleError', ...args: any[]) { | ||
const stringifiedArray = JSON.stringify(args, (key, value) => (typeof value === 'bigint' ? `${value}n` : value), 2); | ||
|
||
Cypress.emit( | ||
'backend:request', | ||
'task', | ||
{ task: taskName, arg: stringifiedArray }, | ||
() => {}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import {defineConfig} from 'cypress'; | ||
import * as outputConsoleLogs from './../core/cypress/outputConsoleLogs'; | ||
|
||
export default defineConfig({ | ||
video: false, | ||
e2e: { | ||
supportFile: false, | ||
setupNodeEvents: outputConsoleLogs.setupNodeEvents, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import {defineConfig} from 'cypress'; | ||
import * as outputConsoleLogs from './../core/cypress/outputConsoleLogs'; | ||
|
||
export default defineConfig({ | ||
video: false, | ||
e2e: { | ||
supportFile: false, | ||
setupNodeEvents: outputConsoleLogs.setupNodeEvents, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters