Cypress How to store global constants in a file that can be used across all spec files?

Use the cypress.json file that is in your project root like this:

{
    "env": {
        "your_var": "your_value"
    }
}

https://docs.cypress.io/guides/references/configuration.html

Once you set some env variables, you can reference them from your specs like this: Cypress.env('your_var');


The following link might help with an easy way to set and get from env variables. https://docs.cypress.io/api/cypress-api/env.html#Syntax

describe('My First Test', function() {
  it('it set value to global variable', function() {
    Cypress.env('some_variable', "hello")
  })
  it('it get value to global variable', function() {
    expect(Cypress.env('some_variable')).to.equal('hello')
  })
})

Global variables - sounds like fixtures.

See writefile - JSON - Write response data to a fixture file

cy.request('https://jsonplaceholder.typicode.com/users').then((response) => {
  cy.writeFile('cypress/fixtures/users.json', response.body)
})

// our fixture file is now generated and can be used
cy.fixture('users').then((users) => {
  expect(users[0].name).to.exist
})

Care to share why you want to do so?
Sounds like it may be interesting.