diff --git a/packages/cypress/src/builders/cypress/cypress.impl.spec.ts b/packages/cypress/src/builders/cypress/cypress.impl.spec.ts index f32123d7e5..e4d3cfb8db 100644 --- a/packages/cypress/src/builders/cypress/cypress.impl.spec.ts +++ b/packages/cypress/src/builders/cypress/cypress.impl.spec.ts @@ -312,6 +312,28 @@ describe('Cypress builder', () => { done(); }); + it('should call `Cypress.run` with provided environment variables through additional properties', async (done) => { + cypressBuilderRunner( + { + ...cypressBuilderOptions, + '--': ['--env.x=x', '--env.y', 'y'], + }, + mockedBuilderContext + ) + .toPromise() + .then(() => { + expect(cypressRun).toHaveBeenCalledWith( + jasmine.objectContaining({ + env: jasmine.objectContaining({ x: 'x', y: 'y' }), + }) + ); + expect(cypressOpen).not.toHaveBeenCalled(); + done(); + }); + + fakeEventEmitter.emit('exit', 0); // Passing tsc command + }); + test('when devServerTarget AND baseUrl options are both present, baseUrl should take precidence', async (done) => { const options: CypressBuilderOptions = { ...cypressBuilderOptions, diff --git a/packages/cypress/src/builders/cypress/cypress.impl.ts b/packages/cypress/src/builders/cypress/cypress.impl.ts index ee3e7df7eb..16ca923a28 100644 --- a/packages/cypress/src/builders/cypress/cypress.impl.ts +++ b/packages/cypress/src/builders/cypress/cypress.impl.ts @@ -14,6 +14,7 @@ import { readJsonFile } from '@nrwl/workspace'; import { legacyCompile } from './legacy'; import { stripIndents } from '@angular-devkit/core/src/utils/literals'; import { installedCypressVersion } from '../../utils/cypress-version'; +import * as yargsParser from 'yargs-parser'; const Cypress = require('cypress'); // @NOTE: Importing via ES6 messes the whole test dependencies. @@ -54,6 +55,14 @@ export function cypressBuilderRunner( options: CypressBuilderOptions, context: BuilderContext ): Observable { + // Special handling of extra options coming through Angular CLI + if (options['--']) { + const { _, ...overrides } = yargsParser(options['--'] as string[], { + configuration: { 'camel-case-expansion': false }, + }); + options = { ...options, ...overrides }; + } + const legacy = isLegacy(options, context); if (legacy) { showLegacyWarning(context); diff --git a/packages/cypress/src/builders/cypress/schema.json b/packages/cypress/src/builders/cypress/schema.json index 387bd9ba69..338b818ce5 100644 --- a/packages/cypress/src/builders/cypress/schema.json +++ b/packages/cypress/src/builders/cypress/schema.json @@ -86,6 +86,6 @@ "description": "The reporter options used. Supported options depend on the reporter." } }, - "additionalProperties": false, + "additionalProperties": true, "required": ["cypressConfig", "tsConfig"] }