Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:cypress-io/cypress into bugfix/c…
Browse files Browse the repository at this point in the history
…ross-origin-snapshots
  • Loading branch information
AtofStryker committed Nov 7, 2022
2 parents 6fcb661 + 12f9e8a commit 6f61da3
Show file tree
Hide file tree
Showing 188 changed files with 3,944 additions and 2,522 deletions.
10 changes: 5 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mainBuildFilters: &mainBuildFilters
branches:
only:
- develop
- 'feature/v8-snapshots'
- 'release/11.0.0'

# usually we don't build Mac app - it takes a long time
# but sometimes we want to really confirm we are doing the right thing
Expand All @@ -36,7 +36,7 @@ macWorkflowFilters: &darwin-workflow-filters
when:
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ 'feature/v8-snapshots', << pipeline.git.branch >> ]
- equal: [ 'release/11.0.0', << pipeline.git.branch >> ]
- matches:
pattern: "-release$"
value: << pipeline.git.branch >>
Expand All @@ -45,7 +45,7 @@ linuxArm64WorkflowFilters: &linux-arm64-workflow-filters
when:
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ 'feature/v8-snapshots', << pipeline.git.branch >> ]
- equal: [ 'release/11.0.0', << pipeline.git.branch >> ]
- matches:
pattern: "-release$"
value: << pipeline.git.branch >>
Expand All @@ -63,7 +63,7 @@ windowsWorkflowFilters: &windows-workflow-filters
when:
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ 'feature/v8-snapshots', << pipeline.git.branch >> ]
- equal: [ 'release/11.0.0', << pipeline.git.branch >> ]
- matches:
pattern: "-release$"
value: << pipeline.git.branch >>
Expand Down Expand Up @@ -130,7 +130,7 @@ commands:
- run:
name: Check current branch to persist artifacts
command: |
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "feature/v8-snapshots" ]]; then
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/11.0.0" ]]; then
echo "Not uploading artifacts or posting install comment for this branch."
circleci-agent step halt
fi
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ cli/visual-snapshots
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# Fleet
.fleet/

# User-specific stuff
.idea
.idea/**/workspace.xml
Expand Down
16 changes: 15 additions & 1 deletion cli/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,21 @@ module.exports = {
args = process.argv
}

const { CYPRESS_INTERNAL_ENV } = process.env
const { CYPRESS_INTERNAL_ENV, CYPRESS_DOWNLOAD_USE_CA } = process.env

if (process.env.CYPRESS_DOWNLOAD_USE_CA) {
let msg = `
${logSymbols.warning} Warning: It looks like you're setting CYPRESS_DOWNLOAD_USE_CA=${CYPRESS_DOWNLOAD_USE_CA}
The environment variable "CYPRESS_DOWNLOAD_USE_CA" is no longer required to be set.
You can safely unset this environment variable.
`

logger.log()
logger.warn(stripIndent(msg))
logger.log()
}

if (!util.isValidCypressInternalEnvValue(CYPRESS_INTERNAL_ENV)) {
debug('invalid CYPRESS_INTERNAL_ENV value', CYPRESS_INTERNAL_ENV)
Expand Down
10 changes: 3 additions & 7 deletions cli/lib/tasks/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,16 @@ const getBaseUrl = () => {

const getCA = () => {
return new Promise((resolve) => {
if (!util.getEnv('CYPRESS_DOWNLOAD_USE_CA')) {
resolve()
}

if (process.env.npm_config_ca) {
resolve(process.env.npm_config_ca)
} else if (process.env.npm_config_cafile) {
if (process.env.npm_config_cafile) {
fs.readFile(process.env.npm_config_cafile, 'utf8')
.then((cafileContent) => {
resolve(cafileContent)
})
.catch(() => {
resolve()
})
} else if (process.env.npm_config_ca) {
resolve(process.env.npm_config_ca)
} else {
resolve()
}
Expand Down
5 changes: 1 addition & 4 deletions cli/test/lib/tasks/download_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ describe('lib/tasks/download', function () {
// prevent ambient environment masking of environment variables referenced in this test

;([
'CYPRESS_DOWNLOAD_USE_CA', 'NO_PROXY', 'http_proxy',
'NO_PROXY', 'http_proxy',
'https_proxy', 'npm_config_ca', 'npm_config_cafile',
'npm_config_https_proxy', 'npm_config_proxy',
]).forEach((e) => {
Expand Down Expand Up @@ -683,7 +683,6 @@ describe('lib/tasks/download', function () {
})

it('returns CA from npm_config_ca', () => {
process.env.CYPRESS_DOWNLOAD_USE_CA = 'true'
process.env.npm_config_ca = 'foo'

return download.getCA().then((ca) => {
Expand All @@ -692,7 +691,6 @@ describe('lib/tasks/download', function () {
})

it('returns CA from npm_config_cafile', () => {
process.env.CYPRESS_DOWNLOAD_USE_CA = 'true'
process.env.npm_config_cafile = 'test/fixture/cafile.pem'

return download.getCA().then((ca) => {
Expand All @@ -701,7 +699,6 @@ describe('lib/tasks/download', function () {
})

it('returns undefined if failed reading npm_config_cafile', () => {
process.env.CYPRESS_DOWNLOAD_USE_CA = 'true'
process.env.npm_config_cafile = 'test/fixture/not-exists.pem'

return download.getCA().then((ca) => {
Expand Down
13 changes: 13 additions & 0 deletions npm/angular/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# [@cypress/angular-v2.0.0](https://github.com/cypress-io/cypress/compare/@cypress/angular-v1.1.2...@cypress/angular-v2.0.0) (2022-11-07)


### Bug Fixes

* possibility to override global services in Angular component tests ([#24394](https://github.com/cypress-io/cypress/issues/24394)) ([54d2853](https://github.com/cypress-io/cypress/commit/54d285321723450920e0f1d50374c4bd0590e72a))
* remove last mounted component upon subsequent mount calls ([#24470](https://github.com/cypress-io/cypress/issues/24470)) ([f39eb1c](https://github.com/cypress-io/cypress/commit/f39eb1c19e0923bda7ae263168fc6448da942d54))


### BREAKING CHANGES

* remove last mounted component upon subsequent mount calls of mount

# [@cypress/angular-v1.1.2](https://github.com/cypress-io/cypress/compare/@cypress/angular-v1.1.1...@cypress/angular-v1.1.2) (2022-10-11)


Expand Down
112 changes: 66 additions & 46 deletions npm/angular/src/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ window.Mocha['__zone_patch__'] = false
import 'zone.js/testing'

import { CommonModule } from '@angular/common'
import { Component, ErrorHandler, EventEmitter, Injectable, SimpleChange, SimpleChanges, Type } from '@angular/core'
import { Component, ErrorHandler, EventEmitter, Injectable, SimpleChange, SimpleChanges, Type, OnChanges } from '@angular/core'
import {
ComponentFixture,
getTestBed,
Expand Down Expand Up @@ -72,6 +72,23 @@ export interface MountConfig<T> extends TestModuleMetadata {
componentProperties?: Partial<{ [P in keyof T]: T[P] }>
}

let activeFixture: ComponentFixture<any> | null = null

function cleanup () {
// Not public, we need to call this to remove the last component from the DOM
try {
(getTestBed() as any).tearDownTestingModule()
} catch (e) {
const notSupportedError = new Error(`Failed to teardown component. The version of Angular you are using may not be officially supported.`)

;(notSupportedError as any).docsUrl = 'https://on.cypress.io/component-framework-configuration'
throw notSupportedError
}

getTestBed().resetTestingModule()
activeFixture = null
}

/**
* Type that the `mount` function returns
* @type MountResponse<T>
Expand Down Expand Up @@ -163,22 +180,12 @@ function initTestBed<T> (
component: Type<T> | string,
config: MountConfig<T>,
): Type<T> {
const { providers, ...configRest } = config

const componentFixture = createComponentFixture(component) as Type<T>

getTestBed().configureTestingModule({
...bootstrapModule(componentFixture, configRest),
...bootstrapModule(componentFixture, config),
})

if (providers != null) {
getTestBed().overrideComponent(componentFixture, {
add: {
providers,
},
})
}

return componentFixture
}

Expand Down Expand Up @@ -219,6 +226,8 @@ function setupFixture<T> (
): ComponentFixture<T> {
const fixture = getTestBed().createComponent(component)

setupComponent(config, fixture)

fixture.whenStable().then(() => {
fixture.autoDetectChanges(config.autoDetectChanges ?? true)
})
Expand All @@ -233,17 +242,18 @@ function setupFixture<T> (
* @param {ComponentFixture<T>} fixture Fixture for debugging and testing a component.
* @returns {T} Component being mounted
*/
function setupComponent<T extends { ngOnChanges? (changes: SimpleChanges): void }> (
function setupComponent<T> (
config: MountConfig<T>,
fixture: ComponentFixture<T>): T {
let component: T = fixture.componentInstance
fixture: ComponentFixture<T>,
): void {
let component = fixture.componentInstance as unknown as { [key: string]: any } & Partial<OnChanges>

if (config?.componentProperties) {
component = Object.assign(component, config.componentProperties)
}

if (config.autoSpyOutputs) {
Object.keys(component).forEach((key: string, index: number, keys: string[]) => {
Object.keys(component).forEach((key) => {
const property = component[key]

if (property instanceof EventEmitter) {
Expand All @@ -262,56 +272,61 @@ function setupComponent<T extends { ngOnChanges? (changes: SimpleChanges): void
acc[key] = new SimpleChange(null, value, true)

return acc
}, {})
}, {} as {[key: string]: SimpleChange})

if (Object.keys(componentProperties).length > 0) {
component.ngOnChanges(simpleChanges)
}
}

return component
}

/**
* Mounts an Angular component inside Cypress browser
*
* @param {Type<T> | string} component Angular component being mounted or its template
* @param {MountConfig<T>} config configuration used to configure the TestBed
* @param component Angular component being mounted or its template
* @param config configuration used to configure the TestBed
* @example
* import { HelloWorldComponent } from 'hello-world/hello-world.component'
* import { mount } from '@cypress/angular'
* import { StepperComponent } from './stepper.component'
* import { MyService } from 'services/my.service'
* import { SharedModule } from 'shared/shared.module';
* import { mount } from '@cypress/angular'
* it('can mount', () => {
* mount(HelloWorldComponent, {
* providers: [MyService],
* imports: [SharedModule]
* })
* cy.get('h1').contains('Hello World')
* it('mounts', () => {
* mount(StepperComponent, {
* providers: [MyService],
* imports: [SharedModule]
* })
* cy.get('[data-cy=increment]').click()
* cy.get('[data-cy=counter]').should('have.text', '1')
* })
*
* or
* // or
*
* it('can mount with template', () => {
* mount('<app-hello-world></app-hello-world>', {
* declarations: [HelloWorldComponent],
* providers: [MyService],
* imports: [SharedModule]
* })
* it('mounts with template', () => {
* mount('<app-stepper></app-stepper>', {
* declarations: [StepperComponent],
* })
* })
* @returns Cypress.Chainable<MountResponse<T>>
*
* @see {@link https://on.cypress.io/mounting-angular} for more details.
*
* @returns A component and component fixture
*/
export function mount<T> (
component: Type<T> | string,
config: MountConfig<T> = { },
): Cypress.Chainable<MountResponse<T>> {
// Remove last mounted component if cy.mount is called more than once in a test
if (activeFixture) {
cleanup()
}

const componentFixture = initTestBed(component, config)
const fixture = setupFixture(componentFixture, config)
const componentInstance = setupComponent(config, fixture)

activeFixture = setupFixture(componentFixture, config)

const mountResponse: MountResponse<T> = {
fixture,
component: componentInstance,
fixture: activeFixture,
component: activeFixture.componentInstance,
}

const logMessage = typeof component === 'string' ? 'Component' : componentFixture.name
Expand All @@ -330,6 +345,15 @@ export function mount<T> (
*
* @param {string} alias name you want to use for your cy.spy() alias
* @returns EventEmitter<T>
* @example
* import { StepperComponent } from './stepper.component'
* import { mount, createOutputSpy } from '@cypress/angular'
*
* it('Has spy', () => {
* mount(StepperComponent, { change: createOutputSpy('changeSpy') })
* cy.get('[data-cy=increment]').click()
* cy.get('@changeSpy').should('have.been.called')
* })
*/
export const createOutputSpy = <T>(alias: string) => {
const emitter = new EventEmitter<T>()
Expand All @@ -348,8 +372,4 @@ getTestBed().initTestEnvironment(
},
)

setupHooks(() => {
// Not public, we need to call this to remove the last component from the DOM
getTestBed()['tearDownTestingModule']()
getTestBed().resetTestingModule()
})
setupHooks(cleanup)
6 changes: 3 additions & 3 deletions npm/angular/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
"allowJs": true,
"declaration": true,
"outDir": "dist",
"strict": false,
"noImplicitAny": false,
"strict": true,
"baseUrl": "./",
"types": [
"cypress"
],
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"moduleResolution": "node"
"moduleResolution": "node",
"noPropertyAccessFromIndexSignature": true,
},
"include": ["src/**/*.*"],
"exclude": ["src/**/*-spec.*"]
Expand Down
14 changes: 14 additions & 0 deletions npm/mount-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# [@cypress/mount-utils-v3.0.0](https://github.com/cypress-io/cypress/compare/@cypress/mount-utils-v2.1.0...@cypress/mount-utils-v3.0.0) (2022-11-07)


### Bug Fixes

* remove dependence on @cypress/<dep> types ([#24415](https://github.com/cypress-io/cypress/issues/24415)) ([58e0ab9](https://github.com/cypress-io/cypress/commit/58e0ab91604618ea6f75932622f7e66e419270e6))
* remove last mounted component upon subsequent mount calls ([#24470](https://github.com/cypress-io/cypress/issues/24470)) ([f39eb1c](https://github.com/cypress-io/cypress/commit/f39eb1c19e0923bda7ae263168fc6448da942d54))
* remove some CT functions and props ([#24419](https://github.com/cypress-io/cypress/issues/24419)) ([294985f](https://github.com/cypress-io/cypress/commit/294985f8b3e0fa00ed66d25f88c8814603766074))


### BREAKING CHANGES

* remove last mounted component upon subsequent mount calls of mount

# [@cypress/mount-utils-v2.1.0](https://github.com/cypress-io/cypress/compare/@cypress/mount-utils-v2.0.1...@cypress/mount-utils-v2.1.0) (2022-08-30)


Expand Down
Loading

0 comments on commit 6f61da3

Please sign in to comment.