A great use case for secco is to copy over changes from your package to a test site used for End-to-End testing. This way you can verify that your published and built package works consistently.
In this guide you’ll learn which secco CLI options to use and how to set up your CI workflow.
Prerequisites
Let’s say you have the following setup:
Directorydist
index.js
Directorye2e-tests
Directorykitchen-sink/
…
Directoryscripts
e2e-test.sh
Directorysrc
index.ts
package.json
Your source file lives inside src and is compiled to the dist folder. You created one of many test sites for End-to-End testing purposes inside e2e-tests.
Now, inside your CI you want to copy e2e-tests/kitchen-sink to a temporary folder to isolate it. Afterwards your latest changes from dist are copied to that temporary folder through installation.
Scripts
For the purpose of this guide a couple of script were chosen to explain the necessary steps. You can use any tool you like though, for example execa’s scripts interface.
Generally speaking, you’ll want to run the script like so:
Figure out the absolute path to your source and set the SECCO_SOURCE_PATH environment variable
Create a temporary folder (e.g. inside the system’s tmp folder)
Install the secco CLI through npm install -g secco@latest
Copy the contents of your test site into the temporary folder
Navigate into the new temporary folder
Run secco --force-verdaccio --scan-once inside your e2e test site
Create a new file, e.g. called install-site-in-isolation.mjs:
This script won’t run your tests yet, you’d need to add the functionality to the script or use the exported environment variable FULL_TMP_FOLDER for later steps (GitHub Actions).
CI workflows
CircleCI
You could run the bash script inside CircleCI like so:
GitHub Actions
You could use the zx script inside GitHub actions like so:
You’ll probably want to adapt the workflow to use matrix so that you can run multiple tests (if you have more than one).