chore: adding command log to protocol (#26387)

This commit is contained in:
Matt Schile
2023-04-05 08:41:40 -06:00
committed by GitHub
parent ad2981e8a6
commit c2273627fe
19 changed files with 166 additions and 129 deletions

View File

@@ -492,6 +492,7 @@ export class EventManager {
this._interceptStudio(displayProps)
this.reporterBus.emit('reporter:log:add', displayProps)
Cypress.backend('protocol:command:log:added', displayProps, new Date().toJSON())
})
Cypress.on('log:changed', (log) => {
@@ -505,6 +506,7 @@ export class EventManager {
this._interceptStudio(displayProps)
this.reporterBus.emit('reporter:log:state:changed', displayProps)
Cypress.backend('protocol:command:log:changed', displayProps, new Date().toJSON())
})
// TODO: MOVE BACK INTO useEventManager. Verify this works

View File

@@ -9,7 +9,7 @@ describe('src/cy/commands/exec', () => {
}, () => {
beforeEach(() => {
// call through normally on everything
cy.stub(Cypress, 'backend').callThrough()
cy.stub(Cypress, 'backend').log(false).callThrough()
})
it('triggers \'exec\' with the right options', () => {
@@ -188,7 +188,7 @@ describe('src/cy/commands/exec', () => {
})
it('throws when the execution errors', function (done) {
Cypress.backend.rejects(new Error('exec failed'))
Cypress.backend.withArgs('exec').rejects(new Error('exec failed'))
cy.on('fail', (err) => {
const { lastLog } = this
@@ -225,7 +225,7 @@ describe('src/cy/commands/exec', () => {
})
it('logs once on error', function (done) {
Cypress.backend.rejects(new Error('exec failed'))
Cypress.backend.withArgs('exec').rejects(new Error('exec failed'))
cy.on('fail', (err) => {
const { lastLog } = this
@@ -245,7 +245,7 @@ describe('src/cy/commands/exec', () => {
err.timedOut = true
Cypress.backend.rejects(err)
Cypress.backend.withArgs('exec').rejects(err)
cy.on('fail', (err) => {
expect(err.message).to.include('`cy.exec(\'sleep 2\')` timed out after waiting `100ms`.')

View File

@@ -10,7 +10,7 @@ const okResponse = {
describe('src/cy/commands/files', () => {
beforeEach(() => {
// call through normally on everything
cy.stub(Cypress, 'backend').callThrough()
cy.stub(Cypress, 'backend').log(false).callThrough()
})
describe('#readFile', () => {
@@ -73,7 +73,7 @@ describe('src/cy/commands/files', () => {
retries += 1
})
Cypress.backend
Cypress.backend.withArgs('read:file')
.onFirstCall()
.rejects(err)
.onSecondCall()
@@ -91,7 +91,7 @@ describe('src/cy/commands/files', () => {
retries += 1
})
Cypress.backend
Cypress.backend.withArgs('read:file')
.onFirstCall()
.resolves({
contents: 'foobarbaz',
@@ -243,7 +243,7 @@ describe('src/cy/commands/files', () => {
cy.on('fail', (err) => {
const { fileLog } = this
assertLogLength(this.logs, 3)
assertLogLength(this.logs, 2)
expect(fileLog.get('error')).to.eq(err)
expect(fileLog.get('state')).to.eq('failed')
expect(err.message).to.eq(stripIndent`\

View File

@@ -13,7 +13,7 @@ describe('src/cy/commands/fixtures', () => {
context('#fixture', () => {
beforeEach(() => {
// call through normally on everything
cy.stub(Cypress, 'backend').callThrough()
cy.stub(Cypress, 'backend').log(false).callThrough()
})
it('triggers \'fixture\' on Cypress', () => {
@@ -243,7 +243,7 @@ describe('src/cy/commands/fixtures', () => {
})
})
.then(() => {
expect(Cypress.backend).to.be.calledTwice
expect(Cypress.backend.withArgs('get:fixture')).to.be.calledTwice
})
})
@@ -261,7 +261,7 @@ describe('src/cy/commands/fixtures', () => {
})
})
.then(() => {
expect(Cypress.backend).to.be.calledOnce
expect(Cypress.backend.withArgs('get:fixture')).to.be.calledOnce
})
})
})

View File

@@ -680,7 +680,7 @@ describe('src/cy/commands/navigation', () => {
})
it('calls resolve:url with http:// when localhost', () => {
const backend = cy.spy(Cypress, 'backend')
const backend = cy.spy(Cypress, 'backend').log(false)
cy
.visit('localhost:3500/timeout')
@@ -720,7 +720,7 @@ describe('src/cy/commands/navigation', () => {
})
it('strips username + password out of the url when provided', () => {
const backend = cy.spy(Cypress, 'backend')
const backend = cy.spy(Cypress, 'backend').log(false)
cy
.visit('http://cypress:password123@localhost:3500/timeout')
@@ -730,7 +730,7 @@ describe('src/cy/commands/navigation', () => {
})
it('passes auth options', () => {
const backend = cy.spy(Cypress, 'backend')
const backend = cy.spy(Cypress, 'backend').log(false)
const auth = {
username: 'cypress',
@@ -926,7 +926,7 @@ describe('src/cy/commands/navigation', () => {
done()
}
cy.stub(Cypress, 'backend')
cy.stub(Cypress, 'backend').log(false)
.withArgs('resolve:url')
.resolves({
isOkStatusCode: true,
@@ -957,7 +957,7 @@ describe('src/cy/commands/navigation', () => {
.withArgs('http://localhost:4200/foo?bar=baz#/tests/integration/foo_spec.js')
.callsFake(fn)
cy.stub(Cypress, 'backend')
cy.stub(Cypress, 'backend').log(false)
.withArgs('resolve:url')
.resolves({
isOkStatusCode: true,
@@ -1123,7 +1123,7 @@ describe('src/cy/commands/navigation', () => {
})
it('displays file attributes as consoleProps', () => {
cy.stub(Cypress, 'backend')
cy.stub(Cypress, 'backend').log(false)
.withArgs('resolve:url')
.resolves({
isOkStatusCode: true,
@@ -1147,7 +1147,7 @@ describe('src/cy/commands/navigation', () => {
})
it('displays http attributes as consoleProps', () => {
cy.stub(Cypress, 'backend')
cy.stub(Cypress, 'backend').log(false)
.withArgs('resolve:url')
.resolves({
isOkStatusCode: true,
@@ -1170,7 +1170,7 @@ describe('src/cy/commands/navigation', () => {
})
it('displays originalUrl http attributes as consoleProps', () => {
cy.stub(Cypress, 'backend')
cy.stub(Cypress, 'backend').log(false)
.withArgs('resolve:url')
.resolves({
isOkStatusCode: true,
@@ -1194,7 +1194,7 @@ describe('src/cy/commands/navigation', () => {
})
it('indicates redirects in the message', () => {
cy.stub(Cypress, 'backend')
cy.stub(Cypress, 'backend').log(false)
.withArgs('resolve:url')
.resolves({
isOkStatusCode: true,
@@ -1281,7 +1281,7 @@ describe('src/cy/commands/navigation', () => {
})
it('sets error command state', function (done) {
cy.stub(Cypress, 'backend')
cy.stub(Cypress, 'backend').log(false)
.withArgs('resolve:url')
.rejects(new Error)
@@ -1298,7 +1298,7 @@ describe('src/cy/commands/navigation', () => {
})
it('logs once on error', function (done) {
cy.stub(Cypress, 'backend')
cy.stub(Cypress, 'backend').log(false)
.withArgs('resolve:url')
.rejects(new Error)
@@ -1338,7 +1338,7 @@ describe('src/cy/commands/navigation', () => {
})
}
cy.stub(Cypress, 'backend')
cy.stub(Cypress, 'backend').log(false)
.withArgs('resolve:url')
.callsFake(fn)
@@ -1442,7 +1442,7 @@ describe('src/cy/commands/navigation', () => {
// dont log else we create an endless loop!
const emit = cy.spy(Cypress, 'emit').log(false)
cy.stub(Cypress, 'backend')
cy.stub(Cypress, 'backend').log(false)
.withArgs('resolve:url')
.rejects(err1)
@@ -1491,7 +1491,7 @@ describe('src/cy/commands/navigation', () => {
obj.url = obj.originalUrl
cy.stub(Cypress, 'backend')
cy.stub(Cypress, 'backend').log(false)
.withArgs('resolve:url')
.resolves(obj)
@@ -1540,7 +1540,7 @@ describe('src/cy/commands/navigation', () => {
obj.url = obj.originalUrl
cy.stub(Cypress, 'backend')
cy.stub(Cypress, 'backend').log(false)
.withArgs('resolve:url')
.resolves(obj)
@@ -1590,7 +1590,7 @@ describe('src/cy/commands/navigation', () => {
obj.url = obj.originalUrl
cy.stub(Cypress, 'backend')
cy.stub(Cypress, 'backend').log(false)
.withArgs('resolve:url', 'https://google.com/foo')
.resolves(obj)
@@ -1639,7 +1639,7 @@ describe('src/cy/commands/navigation', () => {
obj.url = obj.originalUrl
cy.stub(Cypress, 'backend')
cy.stub(Cypress, 'backend').log(false)
.withArgs('resolve:url', 'https://google.com/foo')
.resolves(obj)
@@ -1733,7 +1733,7 @@ describe('src/cy/commands/navigation', () => {
obj.url = obj.originalUrl
cy.stub(Cypress, 'backend')
cy.stub(Cypress, 'backend').log(false)
.withArgs('resolve:url', 'https://google.com/foo')
.resolves(obj)

View File

@@ -1381,8 +1381,7 @@ describe('network stubbing', { retries: 15 }, function () {
// @see https://github.com/cypress-io/cypress/issues/19330
// @see https://github.com/cypress-io/cypress/issues/19344
it('load fixture as Buffer when encoding is null', function () {
// call through normally on everything
cy.spy(Cypress, 'backend')
cy.spy(Cypress, 'backend').log(false)
cy.intercept('/fixtures/media/small.mp4', {
fixture: 'media/small.mp4,null',
@@ -1390,8 +1389,7 @@ describe('network stubbing', { retries: 15 }, function () {
cy.visit('/fixtures/video.html')
.then(() => {
// @ts-ignore .getCall is a Sinon spy command
expect(Cypress.backend.getCall(0)).to.be.calledWithMatch(
expect(Cypress.backend).to.be.calledWithMatch(
'net',
'route:added',
{
@@ -1407,8 +1405,7 @@ describe('network stubbing', { retries: 15 }, function () {
})
it('load fixture with specified encoding', function () {
// call through normally on everything
cy.spy(Cypress, 'backend')
cy.spy(Cypress, 'backend').log(false)
cy.intercept('non-existing-image.png', {
headers: { 'content-type': 'image/jpeg' },
@@ -1417,8 +1414,7 @@ describe('network stubbing', { retries: 15 }, function () {
cy.visit('/fixtures/img-embed.html')
.then(() => {
// @ts-ignore .getCall is a Sinon spy command
expect(Cypress.backend.getCall(0)).to.be.calledWithMatch(
expect(Cypress.backend).to.be.calledWithMatch(
'net',
'route:added',
{

View File

@@ -9,7 +9,7 @@ describe('src/cy/commands/request', () => {
responseTimeout: RESPONSE_TIMEOUT,
}, () => {
beforeEach(() => {
cy.stub(Cypress, 'backend').callThrough()
cy.stub(Cypress, 'backend').log(false).callThrough()
})
describe('argument signature', () => {

View File

@@ -77,7 +77,7 @@ describe('cy.session', { retries: 0 }, () => {
})
it('resets rendered html origins before each run', async () => {
const backendSpy = cy.spy(Cypress, 'backend')
const backendSpy = cy.spy(Cypress, 'backend').log(false)
await Cypress.action('runner:test:before:run:async', {}, Cypress.state('runnable'))
@@ -806,7 +806,7 @@ describe('cy.session', { retries: 0 }, () => {
})
it('does not reset rendered html origins before each run', async () => {
const backendSpy = cy.spy(Cypress, 'backend')
const backendSpy = cy.spy(Cypress, 'backend').log(false)
await Cypress.action('runner:test:before:run:async', {}, Cypress.state('runnable'))

View File

@@ -6,7 +6,7 @@ describe('src/cy/commands/task', () => {
taskTimeout: 2500,
}, () => {
beforeEach(() => {
cy.stub(Cypress, 'backend').callThrough()
cy.stub(Cypress, 'backend').log(false).callThrough()
})
it('calls Cypress.backend(\'task\') with the right options', () => {
@@ -184,7 +184,7 @@ describe('src/cy/commands/task', () => {
})
it('throws when the task errors', function (done) {
Cypress.backend.rejects(new Error('task failed'))
Cypress.backend.withArgs('task').rejects(new Error('task failed'))
cy.on('fail', (err) => {
const { lastLog } = this
@@ -237,7 +237,7 @@ describe('src/cy/commands/task', () => {
})
it('logs once on error', function (done) {
Cypress.backend.rejects(new Error('task failed'))
Cypress.backend.withArgs('task').rejects(new Error('task failed'))
cy.on('fail', (err) => {
const { lastLog } = this
@@ -257,7 +257,7 @@ describe('src/cy/commands/task', () => {
err.timedOut = true
Cypress.backend.rejects(err)
Cypress.backend.withArgs('task').rejects(err)
cy.on('fail', (err) => {
expect(err.message).to.include('`cy.task(\'wait\')` timed out after waiting `100ms`.')

View File

@@ -28,7 +28,7 @@ context('cy.origin files', { browser: '!webkit' }, () => {
cy.origin('http://www.foobar.com:3500', () => {
const contents = JSON.stringify({ foo: 'bar' })
cy.stub(Cypress, 'backend').resolves({
cy.stub(Cypress, 'backend').log(false).resolves({
contents,
filePath: 'foo.json',
})
@@ -76,7 +76,7 @@ context('cy.origin files', { browser: '!webkit' }, () => {
cy.origin('http://www.foobar.com:3500', () => {
const contents = JSON.stringify({ foo: 'bar' })
cy.stub(Cypress, 'backend').resolves({
cy.stub(Cypress, 'backend').log(false).resolves({
contents,
filePath: 'foo.json',
})

View File

@@ -63,7 +63,7 @@ describe('src/cross-origin/patches', { browser: '!webkit', defaultCommandTimeout
describe('from the AUT', () => {
beforeEach(() => {
cy.intercept('/test-request').as('testRequest')
cy.stub(Cypress, 'backend').callThrough()
cy.stub(Cypress, 'backend').log(false).callThrough()
cy.visit('/fixtures/primary-origin.html')
cy.get('a[data-cy="xhr-fetch-requests"]').click()
@@ -184,7 +184,7 @@ describe('src/cross-origin/patches', { browser: '!webkit', defaultCommandTimeout
describe('from the spec bridge', () => {
beforeEach(() => {
cy.intercept('/test-request').as('testRequest')
cy.stub(Cypress, 'backend').callThrough()
cy.stub(Cypress, 'backend').log(false).callThrough()
cy.visit('/fixtures/primary-origin.html')
cy.get('a[data-cy="xhr-fetch-requests"]').click()
@@ -338,7 +338,7 @@ describe('src/cross-origin/patches', { browser: '!webkit', defaultCommandTimeout
// manually remove the spec bridge iframe to ensure Cypress.state('window') is not already set
window.top?.document.getElementById('Spec\ Bridge:\ foobar.com')?.remove()
cy.stub(Cypress, 'backend').callThrough()
cy.stub(Cypress, 'backend').log(false).callThrough()
cy.visit('/fixtures/primary-origin.html')
cy.get('a[data-cy="xhr-fetch-requests-onload"]').click()
@@ -353,7 +353,7 @@ describe('src/cross-origin/patches', { browser: '!webkit', defaultCommandTimeout
})
it('does not patch fetch in the spec window or the AUT if the AUT is on the primary', () => {
cy.stub(Cypress, 'backend').callThrough()
cy.stub(Cypress, 'backend').log(false).callThrough()
cy.visit('fixtures/xhr-fetch-requests.html')
cy.window().then((win) => {
@@ -386,7 +386,7 @@ describe('src/cross-origin/patches', { browser: '!webkit', defaultCommandTimeout
describe('from the AUT', () => {
beforeEach(() => {
cy.intercept('/test-request').as('testRequest')
cy.stub(Cypress, 'backend').callThrough()
cy.stub(Cypress, 'backend').log(false).callThrough()
cy.visit('/fixtures/primary-origin.html')
cy.get('a[data-cy="xhr-fetch-requests"]').click()
@@ -460,9 +460,9 @@ describe('src/cross-origin/patches', { browser: '!webkit', defaultCommandTimeout
describe('from the spec bridge', () => {
beforeEach(() => {
cy.intercept('/test-request').as('testRequest')
cy.stub(Cypress, 'backend').callThrough()
cy.stub(Cypress, 'backend').log(false).callThrough()
cy.origin('http://www.foobar.com:3500', () => {
cy.stub(Cypress, 'backend').callThrough()
cy.stub(Cypress, 'backend').log(false).callThrough()
})
cy.visit('/fixtures/primary-origin.html')
@@ -566,7 +566,7 @@ describe('src/cross-origin/patches', { browser: '!webkit', defaultCommandTimeout
// manually remove the spec bridge iframe to ensure Cypress.state('window') is not already set
window.top?.document.getElementById('Spec\ Bridge:\ foobar.com')?.remove()
cy.stub(Cypress, 'backend').callThrough()
cy.stub(Cypress, 'backend').log(false).callThrough()
cy.visit('/fixtures/primary-origin.html')
cy.get('a[data-cy="xhr-fetch-requests-onload"]').click()
@@ -581,7 +581,7 @@ describe('src/cross-origin/patches', { browser: '!webkit', defaultCommandTimeout
})
it('does not patch xmlHttpRequest in the spec window or the AUT if the AUT is on the primary', () => {
cy.stub(Cypress, 'backend').callThrough()
cy.stub(Cypress, 'backend').log(false).callThrough()
cy.visit('fixtures/xhr-fetch-requests.html')
cy.window().then((win) => {

View File

@@ -107,8 +107,7 @@ export default class Attempt {
addLog = (props: LogProps) => {
switch (props.instrument) {
case 'command': {
// @ts-ignore satisfied by CommandProps
if (props.sessionInfo) {
if ((props as CommandProps).sessionInfo) {
this._addSession(props as unknown as SessionProps) // add sessionInstrumentPanel details
}

View File

@@ -31,7 +31,6 @@ export interface ErrProps {
docsUrl: string | string[]
templateType: string
codeFrame: CodeFrame
isRecovered: boolean
}
export default class Err {

View File

@@ -16,9 +16,8 @@ export interface InstrumentProps {
displayName?: string
name?: string
message?: string
// agent / route / session - instrument panel log type
// parent / child / system - command log type
type?: 'agent' | 'parent' | 'child' | 'system' | 'route' | 'session'
type?: 'parent' | 'child' | 'system'
testCurrentRetry?: number
state: TestState
referencesAlias?: Alias

View File

@@ -57,8 +57,6 @@ class ProtocolManagerImpl implements ProtocolManager {
return
}
debug('connecting to browser for new spec')
await this.protocol?.connectToBrowser(cdpClient)
}
@@ -93,8 +91,6 @@ class ProtocolManagerImpl implements ProtocolManager {
return
}
debug('after spec')
this.protocol?.afterSpec()
}
@@ -103,8 +99,6 @@ class ProtocolManagerImpl implements ProtocolManager {
return
}
debug('before test %O', test)
this.protocol?.beforeTest(test)
}
@@ -113,10 +107,24 @@ class ProtocolManagerImpl implements ProtocolManager {
return
}
debug('after test %O', test)
this.protocol?.afterTest(test)
}
commandLogAdded (log: any, timestamp: string) {
if (!this.protocolEnabled()) {
return
}
this.protocol?.commandLogAdded(log, timestamp)
}
commandLogChanged (log: any, timestamp: string): void {
if (!this.protocolEnabled()) {
return
}
this.protocol?.commandLogChanged(log, timestamp)
}
}
export default ProtocolManagerImpl

View File

@@ -460,6 +460,10 @@ export class SocketBase {
return this.protocolManager?.beforeTest(args[0])
case 'protocol:test:after:run':
return this.protocolManager?.afterTest(args[0])
case 'protocol:command:log:added':
return this.protocolManager?.commandLogAdded(args[0], args[1])
case 'protocol:command:log:changed':
return this.protocolManager?.commandLogChanged(args[0], args[1])
default:
throw new Error(`You requested a backend event we cannot handle: ${eventName}`)
}

View File

@@ -9,23 +9,19 @@ const AppCaptureProtocol = class {
this.beforeSpec = this.beforeSpec.bind(this)
this.afterSpec = this.afterSpec.bind(this)
this.beforeTest = this.beforeTest.bind(this)
this.commandLogAdded = this.commandLogAdded.bind(this)
this.commandLogChanged = this.commandLogChanged.bind(this)
}
connectToBrowser ({
target,
host,
port,
}) {
connectToBrowser (cdpClient) {
return Promise.resolve()
}
addRunnables (runnables) {}
beforeSpec (spec) {}
afterSpec (spec) {}
beforeTest (test) {}
commandLogAdded (log, timestamp) {}
commandLogChanged (log, timestamp) {}
}
module.exports = {

View File

@@ -1,6 +1,7 @@
import { proxyquire } from '../../spec_helper'
import path from 'path'
import os from 'os'
import type { AppCaptureProtocolInterface, ProtocolManager as ProtocolManagerInterface } from '@packages/types'
const mockDb = sinon.stub()
const mockDatabase = sinon.stub().returns(mockDb)
@@ -10,54 +11,39 @@ const { default: ProtocolManager } = proxyquire('../lib/cloud/protocol', {
})
describe('lib/cloud/protocol', () => {
beforeEach(() => {
let protocolManager: ProtocolManagerInterface
let protocol: AppCaptureProtocolInterface
beforeEach(async () => {
process.env.CYPRESS_LOCAL_PROTOCOL_PATH = path.join(__dirname, '..', '..', 'support', 'fixtures', 'cloud', 'protocol', 'test-protocol.js')
protocolManager = new ProtocolManager()
await protocolManager.setupProtocol()
protocol = (protocolManager as any).protocol
})
afterEach(() => {
delete process.env.CYPRESS_LOCAL_PROTOCOL_PATH
})
it('should be able to setup the protocol', async () => {
const protocolManager = new ProtocolManager()
await protocolManager.setupProtocol()
const protocol = (protocolManager as any).protocol
it('should be able to setup the protocol', () => {
expect(protocolManager.protocolEnabled()).to.be.true
expect(protocol.Debug).not.to.be.undefined
expect((protocol as any).Debug).not.to.be.undefined
})
it('should be able to connect to the browser', async () => {
const protocolManager = new ProtocolManager()
await protocolManager.setupProtocol()
const protocol = (protocolManager as any).protocol
const mockCdpClient = sinon.stub()
sinon.stub(protocol, 'connectToBrowser').resolves()
await protocolManager.connectToBrowser({
target: 'target',
host: 'host',
port: 1234,
})
await protocolManager.connectToBrowser(mockCdpClient as any)
expect(protocol.connectToBrowser).to.be.calledWith({
target: 'target',
host: 'host',
port: 1234,
})
expect(protocol.connectToBrowser).to.be.calledWith(mockCdpClient)
})
it('should be able to initialize a new spec', async () => {
const protocolManager = new ProtocolManager()
await protocolManager.setupProtocol()
const protocol = (protocolManager as any).protocol
it('should be able to initialize a new spec', () => {
sinon.stub(protocol, 'beforeSpec')
protocolManager.beforeSpec({
@@ -71,13 +57,7 @@ describe('lib/cloud/protocol', () => {
})
})
it('should be able to initialize a new test', async () => {
const protocolManager = new ProtocolManager()
await protocolManager.setupProtocol()
const protocol = (protocolManager as any).protocol
it('should be able to initialize a new test', () => {
sinon.stub(protocol, 'beforeTest')
protocolManager.beforeTest({
@@ -93,13 +73,7 @@ describe('lib/cloud/protocol', () => {
})
})
it('should be able to clean up after a spec', async () => {
const protocolManager = new ProtocolManager()
await protocolManager.setupProtocol()
const protocol = (protocolManager as any).protocol
it('should be able to clean up after a spec', () => {
sinon.stub(protocol, 'afterSpec')
protocolManager.afterSpec()
@@ -107,13 +81,7 @@ describe('lib/cloud/protocol', () => {
expect(protocol.afterSpec).to.be.called
})
it('should be able to add runnables', async () => {
const protocolManager = new ProtocolManager()
await protocolManager.setupProtocol()
const protocol = (protocolManager as any).protocol
it('should be able to add runnables', () => {
sinon.stub(protocol, 'addRunnables')
const rootRunnable = {
@@ -135,4 +103,66 @@ describe('lib/cloud/protocol', () => {
expect(protocol.addRunnables).to.be.calledWith(rootRunnable)
})
it('should be able to add a command log', () => {
sinon.stub(protocol, 'commandLogAdded')
const log = {
id: 'log-https://example.cypress.io-17',
alias: 'getComment',
aliasType: 'route',
displayName: 'xhr',
event: true,
hookId: 'r4',
instrument: 'command',
message: '',
method: 'GET',
name: 'request',
renderProps: {},
state: 'pending',
testId: 'r4',
timeout: 0,
type: 'parent',
url: 'https://jsonplaceholder.cypress.io/comments/1',
wallClockStartedAt: '2023-03-30T21:58:08.456Z',
testCurrentRetry: 0,
hasSnapshot: false,
hasConsoleProps: true,
}
protocolManager.commandLogAdded(log, '2023-03-30T21:58:08.457Z')
expect(protocol.commandLogAdded).to.be.calledWith(log, '2023-03-30T21:58:08.457Z')
})
it('should be able to change a command log', () => {
sinon.stub(protocol, 'commandLogChanged')
const log = {
id: 'log-https://example.cypress.io-17',
alias: 'getComment',
aliasType: 'route',
displayName: 'xhr',
event: true,
hookId: 'r4',
instrument: 'command',
message: '',
method: 'GET',
name: 'request',
renderProps: {},
state: 'pending',
testId: 'r4',
timeout: 0,
type: 'parent',
url: 'https://jsonplaceholder.cypress.io/comments/1',
wallClockStartedAt: '2023-03-30T21:58:08.456Z',
testCurrentRetry: 0,
hasSnapshot: false,
hasConsoleProps: true,
}
protocolManager.commandLogChanged(log, '2023-03-30T21:58:08.457Z')
expect(protocol.commandLogChanged).to.be.calledWith(log, '2023-03-30T21:58:08.457Z')
})
})

View File

@@ -20,6 +20,8 @@ export interface AppCaptureProtocolInterface {
afterSpec (): void
beforeTest(test: Record<string, any>): void
afterTest(test: Record<string, any>): void
commandLogAdded (log: any, timestamp: string): void
commandLogChanged (log: any, timestamp: string): void
}
export interface ProtocolManager {
@@ -31,4 +33,6 @@ export interface ProtocolManager {
afterSpec (): void
beforeTest(test: Record<string, any>): void
afterTest(test: Record<string, any>): void
commandLogAdded (log: any, timestamp: string): void
commandLogChanged (log: any, timestamp: string): void
}