fix(testing): handle cypress parameters when invoked through Angular CLI
When Cypress was invoked using `ng`, it was throwing errors because no additional properties were allowed. When allowed, all the extra options are passed as array in the `--` key, which is not currently handled. This commit allows additional properties and makes sure that if any adittional options are passed they are parsed and incorporated correctly. ISSUES CLOSED: #3571
This commit is contained in:
parent
875e48400d
commit
ee4b2783fe
@ -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,
|
||||
|
||||
@ -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<BuilderOutput> {
|
||||
// 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);
|
||||
|
||||
@ -86,6 +86,6 @@
|
||||
"description": "The reporter options used. Supported options depend on the reporter."
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"additionalProperties": true,
|
||||
"required": ["cypressConfig", "tsConfig"]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user