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

@hackney/mtfh-cypress

v1.2.1

Published

Cypress helpers fpr LBH Modern Tools for Housing

Downloads

20

Readme

@hackney/mtfh-cypress

This package is intended to be used in conjuction with a live environment that uses import-maps to resolve micro-frontends. It will stub an import-map with the url defined in the env. This allows us to test a local MFE against an environment without deploying, while having access to the entire environment.

Lifecycle:

  1. Before All hook visits the baseURL as an authenticated hackney user to intercept configuration (feature toggles) and store as a fixture.
  2. Do a request to ${DEV_URL}/import-map.json and store the output.
  3. Before Each hook will intercept all import-map.json requests and determine which import-map to stub with the DEV_URL payload.

Installation

yarn add @hackney/mtfh-cli
yarn add dotenv cypress -D

Usage

This library provides both a configuration plugin as well as a collection of hooks and commands. Plugins run in the node context within cypress and commands run in the browser, so we have to wire them up separately.

Plugin

In cypress/plugins/index.js

const { configPlugin } = require("@hackney/mtfh-cypress/plugin");

module.exports = (on, config) => {
  let mtfhConfig = configPlugin(on, config);
  return mtfhConfig;
};

Create a .env file in the root of your project.

CYPRESS_ENVIRONMENT=development
CYPRESS_BASE_URL=https://manage-my-home-development.hackney.gov.uk
CYPRESS_AUTH_TOKEN=token

You'll want to configure these variables in your circle ci pipeline to match your environment.

In cypress.json

{
  "env": {
    "DEV_URL": "http://localhost:9000",
  }
}

Hooks & Commands

In cypress/support/index.js

import "@hackney/mtfh-cypress";

This will import the @testing-library/cypress commands to mirror the FE unit testing approaches we use.

Commands added:

// Visit a url with authenticated credentials
cy.authVisit("/", options);
// Visit a url as a guest (unauthenticated)
cy.guestVisit("/", options);
// Get the value of a feature toggle
cy.hasToggle("MMH.CreateTenure").then((bool) => {});
// Skip test on ENVIRONMENT env
cy.skipOnEnv("development");
// Skip test on Feature Toggle
cy.skipOnToggle("MMH.CreateTenure", true);

To skip a collection of tests encapsulate the tests in a describe

describe('Collection of tests', () => {
  before(() => {
    cy.skipOnToggle('MMH.CreateTenure', true);
  })

  it('creates a tenure', () => {
    ...
  })
})

Audits

We provide commands for testing performance as well as accessibility.

// Equalvalent of testing for mobile
cy.lighthouse({
  seo: 0,
  "best-practices": 100,
  accessibility: 100,
  performance: 80,
});

// Runs lighthouse with the desktop config
cy.lighthouseDesktop({
  seo: 0,
  "best-practices": 100,
  accessibility: 100,
  performance: 80,
});

// Runs accessibility testing, using pa11y
cy.pa11y({ actions: ["wait for element h1 to be added"] });

NB: It's important to note that Lighthouse's performance metrics can't really be taken as an indication of the actual report. This plugin is intended to run a local version of the micro-frontend so we can test against it before deploying. Ie. we will be testing against an app that isn't served by our architecture. You can however use it as a quality gate to ensure new changes don't reduce the scores. We recommend manual performance testing in live environments to get real world values.

Additions

This library comes with the following preconfigured:

  • @testing-libray/cypress
  • cypress-audit
  • cypress-terminal-report

Configuration

The config plugin will override a few cypress.json defaults that align to the requirements more closely.

Such as:

{
  "retries": {
    "runMode": 2,
    "openMode": 0,
  },
  "chromeWebSecurity": false,
  "defaultCommandTimeout": 10000,
}