DavidWells / analytics-e2e-testing

WIP analytics testing via Cypress

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WIP Analytics testing

Test scaffold for analytic plugins.

Goals

  1. Verify that plugins load the analytics provider library
  2. Verify that .page calls map and call to the underlying window global
  3. Verify that .track calls map and call to the underlying window global
  4. Verify that .identify calls map and call to the underlying window global

Example

For example, the @analytics/google-analytics plugin should load google analytics and track a page view

import Analytics from 'analytics'
import googleAnalytics from '@analytics/google-analytics'

/* initialize analytics */
const analytics = Analytics({
  app: 'analytics-demo',
  plugins: [
    // πŸ‘‡ this should load google analytics onto the page
    googleAnalytics({
      trackingId: 'UA-126647663-3'
    })
  ]
})

// πŸ‘‡ this fire a page view to google analytics
analytics.page()

Overview

  • This repo is structured similar to how other "Monorepos" work.
  • Each example project has it's own Cypress configuration, tests, backend and frontend assets.
  • Each of these example projects share a single "root" Cypress that is installed in the root node_modules folder.
  • This structure looks different from normal projects, but its the easiest way to manage multiple projects without installing Cypress independently for each one.

Installation

## install all dependencies
npm install

Opening Cypress GUI

cd ./examples/testing-dom__drag-drop
# start local server
npm start &
# and open Cypress GUI
npm run cypress:open

Running from the CLI

Same as running Cypress GUI but with cypress run command (and any CLI arguments)

cd ./examples/testing-dom__drag-drop
# start local server
npm start &
# run Cypress tests headlessly
npm run cypress:run

### runs all example projects in specific browser
### similar to cypress run --browser <name>
npm run cypress:run -- --browser chrome

### sends test results, videos, screenshots
### to Cypress dashboard
npm run cypress:run -- --record

Development

See Development.md

Notes

Might need to expose internals https://stackoverflow.com/questions/42508142/sinon-basic-use-with-internal-functions https://stackoverflow.com/questions/52332152/how-to-mock-an-inner-function-in-sinon https://stackoverflow.com/questions/34575750/how-to-stub-exported-function-in-es6

About

WIP analytics testing via Cypress


Languages

Language:JavaScript 100.0%