Skip to content

Instantly share code, notes, and snippets.

View NicholasBoll's full-sized avatar

Nicholas Boll NicholasBoll

  • Workday
  • Boulder, CO
View GitHub Profile
interface AliasFn<Subject> {
(): Cypress.Chainable<Subject>
alias: string
}
declare namespace Cypress {
interface Chainable<Subject> {
createAlias(): AliasFn<Subject>
getAliases<T1, T2, T3, T4>(values: [AliasFn<T1>, AliasFn<T2>, AliasFn<T3>, AliasFn<T4>]): Chainable<[T1, T2, T3, T4]>

Best Practices for Writing tests

A test isn't given much though until it fails. Anybody should be able to look at a test and understand what and why it failed. Tests should be written for the failure case. Cypress creates an outline in the GUI to help us understand setup and what a test does. Well written tests help us understand what failed. Screenshots and video help us understand how it failed.

Before continuing, read Best Practices from the Cypress documentation first.

Each test must be runnable in complete isolation

A way to decrease test suite run time is to increase the amount of tests being run at the same time. Sharding (or splitting or work) typically happens at the file level, so at minimum a test file should not rely on any state from a previous test file.

@NicholasBoll
NicholasBoll / addContext.js
Created December 16, 2018 08:34
Cypress mochawesome report. All files go into `cypress` directory
const addContext = (report, screenshots, videoUrl) => {
const getTests = t => t.tests
const getSuites = t => t.suites
const addSuiteContext = (suite, previousTitles = []) => {
const titles = suite.title ? previousTitles.concat(suite.title) : previousTitles
getTests(suite).forEach(test => {
test.timedOut = false // for some reason this is dropped
const context = [
{
@NicholasBoll
NicholasBoll / alarms.ts
Last active December 27, 2019 18:11
Cypress helper function using jQuery
export const getByName = (name: string) => function getAlarmByName($container: JQuery): JQuery {
return $container.find(`.alarm-card:contains("${name}")`)
}
@NicholasBoll
NicholasBoll / support.js
Last active November 8, 2023 15:50
Cypress assertion to compare colors
const compareColor = (color, property) => (targetElement) => {
const tempElement = document.createElement('div');
tempElement.style.color = color;
tempElement.style.display = 'none'; // make sure it doesn't actually render
document.body.appendChild(tempElement); // append so that `getComputedStyle` actually works
const tempColor = getComputedStyle(tempElement).color;
const targetColor = getComputedStyle(targetElement[0])[property];
document.body.removeChild(tempElement); // remove it because we're done with it
@NicholasBoll
NicholasBoll / machine.js
Created August 13, 2020 05:30
Generated by XState Viz: https://xstate.js.org/viz
const tooltipMachine = Machine({
id: "tooltip",
initial: "closed",
states: {
closing: { on: { CLOSE: "closed", OPEN: "opened" } },
closed: { on: { OPEN: "opened" } },
opened: { on: { CLOSING: "closing", CLOSE: "closed" } }
}
});
@NicholasBoll
NicholasBoll / machine.js
Last active September 17, 2020 21:41
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@NicholasBoll
NicholasBoll / session-2.md
Last active April 29, 2021 18:20
Session 2 notes

Session 2

fetch latest:

git fetch --all
@NicholasBoll
NicholasBoll / session-3.md
Last active June 30, 2021 06:16
Session 3

Session 3

Today we'll be covering creating compound components using models, behaviors, and utility functions in Canvas Kit that make composability easier. Please refer to the Create Compound Component docs for reference later.

Get the latest changes:

git fetch --all
@NicholasBoll
NicholasBoll / Major Release.md
Last active November 9, 2022 16:10
Canvas Kit Major Release

Canvas Kit releases major changes every 6 months. Releases are done by a maintainer. The process is similar to minor releases, except the addition of the support branch. All branches have to be forward merged. Check out all of the following to make sure there are no commits listed:

If there are any commits listed, run the forward merge for the branch that isn't merged forward (support, master, or prerelease/minor). It is safe to run this job even if there are no changes since the job will recognize no change and bail.

We'll be using the terms previous major, current major, and next major in the context of versions before the release process is complete. For example, if support is pointing to v4, `ma