Skip to content

Warn when writing to 'read only' properties of config #6407

@jennifer-shehane

Description

@jennifer-shehane

Current behavior:

Currently only some of the config values are writable at certain points of a run and it is not clear which are and which aren't. The value simply is not read where necessary if it is not writable.

Honestly, I can't even list out which are readable and writable and when because this has never been documented. I could only guess or dig through code.

Cypress.config()

We briefly noted this in the Cypress.config() doc, but it is sadly lacking a full explanation of which are writable and which are not and when. Previous issue for this: #3422

Some confusion:

The other point of confusion is that it appears to be writable, when it's not at all! For example, the below will log the newly set value for userAgent, but it actually takes no effect on the actual userAgent set.

it('sets userAgent?', function () {
  console.log(Cypress.config('userAgent'))
  Cypress.config('userAgent', 'foo')

  // logs foo but does absolutely nothing!
  console.log(Cypress.config('userAgent'))
})

The test below passes, but Cypress does not indeed change the location of the screenshotsFolder, nor does it throw an error telling you that the screenshotsFolder was not set.

it('screenshots folder not settable', () => {
  Cypress.config('screenshotsFolder', 'cypress/screenshots/desktop')
  expect(Cypress.config('screenshotsFolder')).to.eq('cypress/screenshots/desktop')
  cy.screenshot('homepage_desktop')
})
Cypress.config('chromeWebSecurity', true); // Setting up security stuff ON

describe('Load graphql stuff Test', () => {
    it('should visit dashboard', () => {
        cy.visit(`stuff/${stuffId}/stuff/requests?status=0`);
        cy.get('[data-testid="empty-state"]').should('exist');
    });
});

Actual saved screenshot location

screen shot 2019-02-11 at 11 52 28 am

Plugins Configuration API

Furthermore, we are expanding upon the use of the config object from within the plugins/index.js https://on.cypress.io/configuration-api - where some of this config is not writable and will not be writable at the time of run as part of #5941

This will have config values that are not writable at time that the plugin is read in like configFile and projectRoot.

Desired behavior:

  • We should throw when setting these 'non-writable' config values using Cypress.config
  • We should throw/warn? when setting 'non-writable' config values within the Plugins Configuration API.

Related issues

Versions

4.0.1

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions