npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@commercetools-frontend/cypress-environments

v0.1.5

Published

Cypress package to setup environment configuration using dotenv files

Downloads

3,754

Readme

@commercetools-frontend/cypress-environments

This package allows to load environment variables into a Cypress environment from dotenv files.

Installation

$ npm install --save @commercetools-frontend/cypress-environments

Usage

Inside of your cypress.config.js import the package as follows:

const {
  getConfigurationForEnvironment,
} = require('@commercetools-frontend/cypress-environments');

Then inside your e2e.setupNodeEvents in Cypress v10.x load the configuration by calling await getConfigurationForEnvironment(environment).

This will return an object with the merged configuration based on the requested environment.

Adding a configuration file

This module uses cosmiconfig to load a configuration file named cypress-environments. As a result it supports many formats such as cypress-environments.config.cjs or cypress-environments.rc.json depending on your preference.

Within the configuration file an array environments property should be defined containing a set of environments with name, secrets and config globs.

The contents of the configuration file could look like:

const projectKeys = {
  gcpEu: 'ctp_production_gcp_europe-west1_v1',
};

module.exports = {
  environments: [
    {
      name: projectKeys.gcpEu,
      secrets: `cypress/config/${projectKeys.gcpEu}/.env.secrets*`,
      config: `cypress/config/${projectKeys.gcpEu}/.env.config*`,
    },
  ],
};

From here the documentation assumes the above format and naming for further examples.

Adding environment configurations

The package expects configurations for environments to be stored in cypress/config/<environment_name>. For example this structure:

cypress/config
├── ctp_production_gcp_europe-west1_v1
|──── .env.config
|──── .env.secrets.ci (Decrypred from `*.enc`)
|──── .env.config.local.template
|──── .env.secrets.local.template
├── ctp_production_aws_eu-central-1_v1
└── vw_production_aws_eu-central-1_v1

Would load the values from .env.config anytime the environment is ctp_production_gcp_europe-west1_v1. Additionally on CI (when CI=true) it would load the .env.secrets.ci file, otherwise it would attempt to load values from .env.config.local and .env.secrets.local (assuming they have been properly configured - see *.template files for reference).

Given multiple files can be loaded some values can be overwritten by a subsequently loaded file. First the .env.config file will be loaded. After the secrets from .env.secrets and then .env.secrets.ci or .env.secrets.local respectively. Any file loaded later can overwrite values of a file loaded before.

Provided configuration values

The module provides default values for ctp_production_aws_eu-central-1_v1, ctp_production_gcp_europe-west1_v1, ctp_production_gcp_us-central1_v1 and ctp_production_gcp_australia-southeast1_v1. These values will be loaded first before any custom configuration. These default configurations contain the API_URL, MC_API_URL, MC_URL and AUTH_URL for the given environment.

Troubleshooting

Configuration does not load as expected

Inspect the logs of the module to inspect which files match the globs. This output could be:

ℹ️  'CI' environment variables are defined. Assuming operating from a CI system.
ℹ️  Found 1 secret file(s) and 1 config file(s) matching the defined globs.
✅ Found and loading environment variables from: 'cypress/config/ctp-gcp-production-eu/.env.config'
ℹ️  No environment variables at: 'cypress/config/ctp-gcp-production-eu/.env.config.ci'. If needed create it or duplicate the template file.
✅ Found and loading environment variables from: 'cypress/config/ctp-gcp-production-eu/.env.secrets.ci'
✅ Found and loading environment variables from: '/Users/<username>/merchant-center-frontend/packages-cypress/environments/src/config/.env.ctp-gcp-production-eu.config'

Verify that the files are loaded as expected and make sure they exist.

Secrets are not loaded

Make sure the secrets are decrypted on CI from the *.enc or locally a *.template file for the secrets has been duplicated and filled.

Local configuration and secrets are loaded on CI

Ensure that the CI environment variable is set. Most CI providers set it by default but you can also pass it to the command when running Cypress.