Skip to content

Update Cypress tests and configuration #24

@kklamberty

Description

@kklamberty

The current Cypress configuration utilizes a plugins file, but that approach has been deprecated (or, removed: https://docs.cypress.io/app/references/migration-guide#Plugins-File-Removed)

The way that we have been referring to the plugins file has also been utilizing a require import, which is (apparently) discouraged. This code snippet includes a change to include a baseUrl, which should help prevent additional/unnecessary reloads when watching e2e tests (I didn't notice any improvements in times for running tests headless).

import { defineConfig } from 'cypress';

export default defineConfig({
  e2e: {
    setupNodeEvents: (on, config) => {
      config.baseUrl = 'http://localhost:4200';
      // eslint-disable-next-line @typescript-eslint/no-require-imports
      require('./cypress/plugins/index.ts').default(on, config);
    },
  },
});

Initially, I tried moving things from index.ts into the config file, but in that case I received warnings that process was not defined. The process environment variables for mongo don't seem to be used when I'm running things locally, so I'm unsure that aspect is adding value in the code. There was a suggestion for bringing in something in node that would help with process, and after I made that change I didn't notice an immediate change... but I did notice it was fixed later... so not totally sure if that means it worked but needed to be refreshed somehow, or maybe something else? I do not know in what case we would ever use that mongoHost and mongoDb in the mongoUri rather than just using 'localhost' and 'dev'.

/* eslint-disable @typescript-eslint/naming-convention */
import {seedAll} from '@floogulinc/cypress-mongo-seeder';

const mongoHost = process.env.MONGO_ADDR || 'localhost';
const mongoDb = process.env.MONGO_DB || 'dev';

const mongoUri = `mongodb://${mongoHost}/${mongoDb}`;
const dbSeedDir = '../database/seed';

const pluginConfig: Cypress.PluginConfig = (on, _config) => {
  // `on` is used to hook into various events Cypress emits
  // `_config` is the resolved Cypress config
  on('task', {
    'seed:database': (drop = true) => seedAll(mongoUri, dbSeedDir, drop),
  });

};

export default pluginConfig;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions