Skip to content

Commit

Permalink
various cleanup: remove commented console logs, add more detailed com…
Browse files Browse the repository at this point in the history
…ments
  • Loading branch information
cacieprins committed Dec 20, 2024
1 parent 0300676 commit 4e090de
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 72 deletions.
6 changes: 5 additions & 1 deletion cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3112,7 +3112,11 @@ declare namespace Cypress {
* @default null
*/
experimentalSkipDomainInjection: string[] | null
// TODO: document
/**
* Enables setting document.domain to the superdomain on code injection. This option is
* disabled by default. Enabling this option allows for navigating between subdomains in
* the same test without the use of cy.origin().
*/
injectDocumentDomain: boolean
/**
* Enables AST-based JS/HTML rewriting. This may fix issues caused by the existing regex-based JS/HTML replacement algorithm.
Expand Down
2 changes: 1 addition & 1 deletion npm/vite-dev-server/src/plugins/cypress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const Cypress = (
},
configureServer: async (server: ViteDevServer) => {
server.middlewares.use(`${base}index.html`, async (req, res) => {
let transformedIndexHtml = await server.transformIndexHtml(base, '')
const transformedIndexHtml = await server.transformIndexHtml(base, '')

return res.end(transformedIndexHtml)
})
Expand Down
7 changes: 2 additions & 5 deletions packages/config/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,12 @@ describe('config/src/index', () => {

describe('.validateNeedToRestartOnChange', () => {
it('returns the need to restart if given key has changed', () => {
let result = configUtil.validateNeedToRestartOnChange({ blockHosts: [] }, { blockHosts: ['https://example.com'] })

expect(result).to.eql({
expect(configUtil.validateNeedToRestartOnChange({ blockHosts: [] }, { blockHosts: ['https://example.com'] })).to.eql({
server: true,
browser: false,
})

result = configUtil.validateNeedToRestartOnChange({ injectDocumentDomain: true }, {})
expect(result).to.eql({
expect(configUtil.validateNeedToRestartOnChange({ injectDocumentDomain: true }, {})).to.eql({
server: true,
browser: false,
})
Expand Down
1 change: 0 additions & 1 deletion packages/driver/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export default defineConfig({
configFile: '../../mocha-reporter-config.json',
},
e2e: {
excludeSpecPattern: 'cypress/**/with-inject-document-domain/**/*.cy.{js,ts}',
experimentalOriginDependencies: true,
experimentalModifyObstructiveThirdPartyCode: true,
setupNodeEvents: (on, config) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ describe('Cookie Behavior', { browser: '!webkit' }, () => {
describe('misc', () => {
describe('domains', () => {
// NOTE: tested in ./with-inject-document-domain/cookie_behavior
it.skip('attaches subdomain and TLD cookies when making subdomain requests', () => {
it('attaches subdomain and TLD cookies when making subdomain requests', () => {
cy.intercept(`${scheme}://app.foobar.com:${crossOriginPort}/test-request`, (req) => {
expect(req['headers']['cookie']).to.equal('foo=bar; bar=baz')

Expand Down
4 changes: 2 additions & 2 deletions packages/driver/cypress/e2e/e2e/privileged_commands.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ describe('privileged commands', () => {
}

strategies.forEach((strategy) => {
describe(`strategy: ${strategy}`, () => {
commands.forEach((command) => {
commands.forEach((command) => {
describe(`strategy: ${strategy}`, () => {
describe(`command: ${command}`, () => {
it('fails in html script', (done) => {
cy.on('fail', (err) => {
Expand Down
1 change: 0 additions & 1 deletion packages/driver/src/cy/commands/sessions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ export default function (Commands, Cypress, cy) {

const userInvocationStack = $errUtils.getUserInvocationStack(err, Cypress.state)

//console.log('enhancingStack from session', { err, userInvocationStack })
err = $errUtils.enhanceStack({
err,
userInvocationStack,
Expand Down
1 change: 0 additions & 1 deletion packages/driver/src/cypress/cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@ export class $Cy extends EventEmitter2 implements ITimeouts, IStability, IAssert

const userInvocationStack = $errUtils.getUserInvocationStack(err, this.state)

//console.log('enhancing stack', { errStack: err.stack, userInvocationStack })
err = $errUtils.enhanceStack({
err,
userInvocationStack,
Expand Down
5 changes: 0 additions & 5 deletions packages/driver/src/cypress/error_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,17 +431,12 @@ const createUncaughtException = ({ frameType, handlerType, state, err }) => {
// but the stack points to cypress internals. here we replace the internal
// cypress stack with the invocation stack, which points to the user's code
const stackAndCodeFrameIndex = (err, userInvocationStack): StackAndCodeFrameIndex => {
//console.log('stackAndCodeFrameIndex', { isCypressErr: isCypressErr(err), isChai: isChaiValidationErr(err) })
if (!userInvocationStack) return { stack: err.stack }

if (isCypressErr(err) || isChaiValidationErr(err)) {
//console.log('splicing userInvocationStack')

return $stackUtils.stackWithUserInvocationStackSpliced(err, userInvocationStack)
}

//console.log('returning new stack from userInvocationStack')

return { stack: $stackUtils.replacedStack(err, userInvocationStack) || '' }
}

Expand Down
7 changes: 4 additions & 3 deletions packages/driver/src/cypress/stack_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ const hasCrossFrameStacks = (specWindow) => {
return topStack === specStack
}

const stackWithContentAppended = (err, stack: string = '') => {
const stackWithContentAppended = (err, stack: string | undefined) => {
const usableStack = stack ?? ''
const appendToStack = err.appendToStack

if (!appendToStack || !appendToStack.content) return stack
if (!appendToStack || !appendToStack.content) return usableStack

delete err.appendToStack

Expand All @@ -43,7 +44,7 @@ const stackWithContentAppended = (err, stack: string = '') => {
const normalizedContent = normalizeStackIndentation(appendToStack.content)
const content = $utils.indent(normalizedContent, 2)

return `${stack}\n\n${appendToStack.title}:\n${content}`
return `${usableStack}\n\n${appendToStack.title}:\n${content}`
}

const stackWithLinesRemoved = (stack, cb) => {
Expand Down
50 changes: 24 additions & 26 deletions packages/network/lib/document-domain-injection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,30 @@ import type { ParsedHostWithProtocolAndHost } from './types'

const debug = Debug('cypress:network:document-domain-injection')

export abstract class DocumentDomainInjection {
public static InjectionBehavior (config: { injectDocumentDomain?: boolean, testingType?: 'e2e' | 'component'}): DocumentDomainInjection {
debug('Determining injection behavior for config values: %o', {
injectDocumentDomain: config.injectDocumentDomain,
testingType: config.testingType,
})

if (config.injectDocumentDomain && config.testingType !== 'component') {
debug('Returning document domain injection behavior')

return new DocumentDomainBehavior()
}

debug('Returning origin behavior - no document domain injection')

return new OriginBehavior()
}

public abstract getOrigin (url: string): string
public abstract getHostname (url: string): string
public abstract urlsMatch (frameUrl: string | ParsedHostWithProtocolAndHost, topUrl: string | ParsedHostWithProtocolAndHost): boolean
public abstract shouldInjectDocumentDomain (url: string | undefined): boolean
}

export class DocumentDomainBehavior implements DocumentDomainInjection {
public getOrigin (url: string) {
return getSuperDomainOrigin(url)
Expand Down Expand Up @@ -59,29 +83,3 @@ export class OriginBehavior implements DocumentDomainInjection {
return false
}
}

export abstract class DocumentDomainInjection {
public static InjectionBehavior (config: { injectDocumentDomain?: boolean, testingType?: 'e2e' | 'component'}): DocumentDomainInjection {
debug('Determining injection behavior for config values: %o', {
injectDocumentDomain: config.injectDocumentDomain,
testingType: config.testingType,
})

debug('called from', new Error().stack)

if (config.injectDocumentDomain && config.testingType !== 'component') {
debug('Returning document domain injection behavior')

return new DocumentDomainBehavior()
}

debug('Returning origin behavior - no document domain injection')

return new OriginBehavior()
}

public abstract getOrigin (url: string): string
public abstract getHostname (url: string): string
public abstract urlsMatch (frameUrl: string | ParsedHostWithProtocolAndHost, topUrl: string | ParsedHostWithProtocolAndHost): boolean
public abstract shouldInjectDocumentDomain (url: string | undefined): boolean
}
4 changes: 0 additions & 4 deletions packages/proxy/lib/http/util/rewriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import * as astRewriter from './ast-rewriter'
import * as regexRewriter from './regex-rewriter'
import type { CypressWantsInjection } from '../../types'
import type { SerializableAutomationCookie } from '@packages/server/lib/util/cookies'
import Debug from 'debug'

const debug = Debug('cypress:proxy:http:rewriter')

export type SecurityOpts = {
isNotJavascript?: boolean
Expand Down Expand Up @@ -35,7 +32,6 @@ function getRewriter (useAstSourceRewriting: boolean) {
}

function getHtmlToInject (opts: InjectionOpts & SecurityOpts) {
debug('getting html to inject from opts %O', opts)
const {
cspNonce,
domainName,
Expand Down
2 changes: 1 addition & 1 deletion packages/proxy/test/unit/http/response-middleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2127,7 +2127,7 @@ describe('http/response-middleware', function () {
htmlStub.restore()
})

;[true].forEach((injectDocumentDomain) => {
;[true, false].forEach((injectDocumentDomain) => {
describe(`when injectDocumentDomain is ${injectDocumentDomain}`, () => {
const config = {
modifyObstructiveCode: true,
Expand Down
9 changes: 0 additions & 9 deletions packages/server/lib/privileged-commands/privileged-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@
)
})

//console.log('hasSpecFrameStackLines? ', err.stack, stackLines, filteredLines, filteredLines.length)

return filteredLines.length > 0
}

Expand All @@ -82,8 +80,6 @@
return isInCallback(err) && hasValidCallbackContext
}

//console.log('hasCallbackInsideEval', isInCallback(err), stringIncludes.call(err.stack, '> eval line'))

return isInCallback(err) && stringIncludes.call(err.stack, '> eval line')
}

Expand All @@ -99,8 +95,6 @@
return stringIncludes.call(err.stack, script)
})

//console.log('hasStackLinesFromSpecOrSupportFile?', scripts, filteredLines)

return filteredLines.length > 0
}

Expand Down Expand Up @@ -129,10 +123,7 @@
return hasSpecBridgeInvocation(err)
}

//console.log('should check special case?', { browserFamily, documentDomainContext }, browserFamily && documentDomainContext)
if (browserFamily === 'chromium' && documentDomainContext) {
//console.log('checking special case', browserFamily, documentDomainContext, browserFamily && documentDomainContext)

return hasStackLinesFromSpecOrSupportFile(err) || hasSpecFrameStackLines(err)
}

Expand Down
2 changes: 0 additions & 2 deletions packages/server/lib/remote_states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ interface RemoteStatesServerPorts {
* }
*/
export class RemoteStates {
// Cypress.RemoteState was coming from the namespace declared in @packages/net-stubbing, somehow
// now it's defined (for a second time) in `./remote_states_abs.ts
private remoteStates: Map<string, RemoteState> = new Map()
private primaryOriginKey: string = ''
private currentOriginKey: string = ''
Expand Down
10 changes: 1 addition & 9 deletions packages/server/lib/server-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import la from 'lazy-ass'
import httpsProxy from '@packages/https-proxy'
import { getRoutesForRequest, netStubbingState, NetStubbingState } from '@packages/net-stubbing'
import { agent, clientCertificates, cors, httpUtils, uri, concatStream, DocumentDomainInjection } from '@packages/network'
import type { Policy } from '@packages/network/lib/cors'
import { NetworkProxy, BrowserPreRequest } from '@packages/proxy'
import type { SocketCt } from './socket-ct'
import * as errors from './errors'
Expand Down Expand Up @@ -159,10 +158,8 @@ export class ServerBase<TSocket extends SocketE2E | SocketCt> {
protected _eventBus: EventEmitter
protected _remoteStates: RemoteStates
private getCurrentBrowser: undefined | (() => Browser)
private _originPolicy: Policy = 'same-origin'
private _urlResolver: Bluebird<Record<string, any>> | null = null
private testingType?: TestingType
private _config: Cfg
private _documentDomainInjection: DocumentDomainInjection

constructor (config: Cfg) {
Expand All @@ -176,8 +173,6 @@ export class ServerBase<TSocket extends SocketE2E | SocketCt> {
this._fileServer = null

this._documentDomainInjection = DocumentDomainInjection.InjectionBehavior(config)
// TODO: maybe dont need to keep this around anymore
this._config = config

const remoteStatePorts = () => {
return {
Expand Down Expand Up @@ -248,13 +243,10 @@ export class ServerBase<TSocket extends SocketE2E | SocketCt> {
onWarning: unknown,
): Bluebird<[number, WarningErr?]> {
return new Bluebird((resolve, reject) => {
const { port, fileServerFolder, socketIoRoute, baseUrl, injectDocumentDomain } = config
const { port, fileServerFolder, socketIoRoute, baseUrl } = config

this._server = this._createHttpServer(app)

debug('inject document domain?', injectDocumentDomain)
this._originPolicy = injectDocumentDomain ? 'same-super-domain-origin' : 'same-origin'

const onError = (err) => {
// if the server bombs before starting
// and the err no is EADDRINUSE
Expand Down

0 comments on commit 4e090de

Please sign in to comment.