Skip to main content

Idanwo Opin si Opin

Testing the integrity of React components by publishing in a private registry

E2E and Verdaccio

Some projects organize packages in multi-packages repositories or monorepos. E2E testing is a topic that usually is only relevant for User Interfaces, but from a Node.js perspective, publishing packages also need to be tested.

Iru ọna yẹn ti jẹ eyi to soro gidi gan lati ni aṣeyọri pẹlu riro iwọnyi:

  • Populate canary packages on public services seems not to be a good idea
  • Some self-hosted OSS registries are too heavy
  • Offline environments (private networks)

Verdaccio jẹ ibi iforukọsilẹ fifuyẹ pẹlu iṣeto-odo ti o ni ibamu didanmọran pẹlu eyikeyi E2E + CI ilana iṣẹ.

Implementation

Ko ti si ọta fadaka kankan, imuṣiṣẹ kọọkan dabi pe o jẹ pato fun iṣẹ akanṣe kọọkan, o le ṣayẹwo diẹ ninu wọn ni okun atẹle yii tẹ ibi.

Apẹẹrẹ nipa lilo Bash

Eyi ni apẹẹrẹ to rọrun julọ nipa lilo Verdaccio ninu iwe afọwọkọ bash kan (ti o jẹ fifajade lati create-react-app).

#!/bin/sh

set -e

local_registry="http://0.0.0.0:4873"

# start local registry
tmp_registry_log=`mktemp`
sh -c "mkdir -p $HOME/.config/verdaccio"
sh -c "cp --verbose /config.yaml $HOME/.config/verdaccio/config.yaml"
sh -c "nohup verdaccio --config $HOME/.config/verdaccio/config.yaml &>$tmp_registry_log &"
# wait for `verdaccio` to boot
grep -q 'http address' <(tail -f $tmp_registry_log)
# login so we can publish packages
sh -c "npm-auth-to-token -u test -p test -e test@test.com -r $local_registry"
# Run nmp command
sh -c "npm --registry $local_registry publish"

Who is using it for E2E?