End to End тестирование
Testing the integrity of React components by publishing in a private registry
The final stage of a react component is when it is being published and distributed. How can I ensure my packages won’t crash in production? This talk will help you to test your React components by publishing them to a private registry and running End-to-End tests against them.
End to End and Verdaccio
Некоторые проекты организуют свой код, разделяя его на много пакетов, другие используют монорепо. End to End 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.
Используя этот подход, вы можете столкнуться со следующими трудностями:
- 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 - это "легкий" репозиторий, который аже не нужно конфигурировать, который прекрасно подходит для E2E + CI.
Implementation
"Серебрянной пули" нет, и, похоже, реализация для каждого проекта - особенная; вы можете посмотреть на примеры в этом обсуждении.
Examples in Open Source
The following projects have examples using Verdaccio in Open Source
Bash Examples
- Babel.js (+35k ⭐️)
- Docusaurus (+31k ⭐️)
- create-react-app (+73.5k ⭐️)
- Uppy (+21k ⭐️)
- ethereum/web3.js (+8k ⭐️)
- adobe react-spectrum (+6k ⭐️)
- Mozilla Neutrino (+3k ⭐️)
This is the most simple example using Verdaccio in a bash script (extracted from 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"
Примеры
Programmatically Examples
Verdaccio module
Via CLI:
- Aurelia Framework (+12k ⭐️)
- Netlify CLI (+1k ⭐️)
- Embark (+3k ⭐️)
- Microsoft Beachball
Node.js child_process
examples
- Angular CLI (+25k ⭐️)
- bit (+6k ⭐️)
- pnpm (+6k ⭐️)
- aws-sdk cli v3 (+1k ⭐️)
- angular-eslint (+1k ⭐️)