8.9 KiB
Testing
Building docs
This may be useful during testing. Build through npm run build-docs
.
To start a server and open already built docs, use npm run open-docs
(or
npm run open-docs-no-start
if you already have a start
process
running in another terminal tab).
Or to build and open the docs, use npm run build-and-open-docs
(or
npm run build-and-open-docs-no-start
if you already have a start
process
running in another terminal tab).
Scripts for running after dependency changes
- Copying files. Some
devDependencies
are incorporated into the svgedit repository (and npm package) so that Github or npm hosting services can run (without needing to take the much heavier step of bundling all ofnode_modules
).npm run copy
- Checking licenses - If updating a dependency or devDependency,
the project's aggregate license information might change. To get
this information updated, run:
npm run license-badges
(Which runs the following commands)npm run license-badge
(Only build the license badge containing info on this project's license(s) and those of anydependencies
, and thedevDependencies
which are being bundled into the repository/npm package.)npm run license-badge-dev
(Only build the license badge for this project'sdevDependencies
. This is probably not of great concern unless a project is restrictive in terms of usage--i.e., if a dependency is not what is typically considered "open" source.)
(Note that the test and coverage badges are generated automatically during testing to ensure they are up to date, so you should not need to call those scripts directly.)
Miscellaneous scripts
npm run compress-images
- Compressing images is not part of other preparation routines, as it is time-consuming and should not need to be done frequently.npm run remark
- For linting Markdown. Not of high enough priority currently to put into an automated routine.npm run eslint
andnpm run eslint-fix
- For linting (or fixing) linting errors. The non-fix version will be run automatically during testing.npm run prep
- Run duringnpm test
but may be useful to runnpm run prep
as needed if normally testing throughnpm run test-only
which doesn't do the preparation. Composed of:npm run prep-no-core-rollup
npm run eslint
(see above)npm run build-html
- Copies ESM HTML pages, replacing references to ESM scripts to compiled/rolled up scripts.npm run build-by-config
- Runs the Rollup routines for compiling just the ESM-based config files (since the user config files are responsible for importing svgedit, one must compile these to get a non-ESM build, but with the advantage of avoiding globals and extra script tags).
npm run rollup
- Runs the rollup routine for compiling the ESM-based svgedit source files.
Opening SVG editor from command line
It can be helpful to experiment with an editor by opening it from the command line, even when automated tests already exist for a type of editor.
- Opening the ESM editor with only the default extensions:
npm run open
ORnpm run open-no-start
if you already have astart
process running in another terminal tab.
- Opening the ESM editor with all extensions (no automated tests currently):
npm run open-all-ext
ORnpm run open-all-ext-no-start
if you already have astart
process running in another terminal tab.
- Opening an embedded (ESM) editor (no automated tests currently) (Note
that there is currently no build process for creating a non-ESM
embedded editor).
npm run open-embedded
(This runs the normalstart
and alsostart-allow-origin
for running a separate server on a different origin (a different port) so the embedded API can be tested across origins.) ORnpm run open-embedded-no-start
if you already have astart
process running in another terminal tab.
- Opening an editor which is already pre-compiled (rolled up) and safe
for older non-ESM browsers (or for better performance in ESM browsers
as well, due to its use of fewer HTTP requests). This is the version
most likely to be used in production environments. However, this is
less convenient during normal debugging, as it requires that the
lengthier
prep
script be run first (these scripts do not do so for you in case you are directly working on the compiled files, though this is not recommended).npm run open-compiled
ORnpm run open-compiled-no-start
if you already have astart
process running in another terminal tab.
Reading/Opening test coverage reports
For testing coverage reports (see "Testing"), you can open the HTML-based
reports that are generated during the testing process (or when running
npm run instrument
directly) from the command line into your
browser by the following commands:
- Reading reports from the command line
npm run report
(with some line numbers but not all lines as with the HTML report) ORnpm run report-summary
(no line numbers--only a summary)
- Opening HTML-based test coverage report (indicating coverage status
for all lines)
npm run open-cov
ORnpm run open-cov-no-start
if you already have astart
process running in another terminal tab.
Testing and coverage
For ensuring tests are passing and checking coverage.
You will most likely just need to use one of these three top-level
routines along with npm run test-only
, but the other components are explained
here for reference. The most useful for regular development testing will probably
be npm run open-tests
.
Note that you can configure Cypress through its environmental variables.
We recommend this approach
of adding to your own cypress.env.json
at project root. You can set
your own configuration options.
Of particular interest may be setting "video": false
if you wish to speed
up the tests and are not concerned with being able to check this after
running the headless tests (or during the running of headed tests in the
case of open-tests
/cypress:open
).
npm test
. Headless testing comprised of:npm run instrument
- You can call this alone if you don't actually wish to test but wish to get the files instrumented. Should normally not be needed alone.npm run test-no-cov
- You can run this alone if you have already runnpm run instrument
upon making changes. Should normally not be run alone.npm run prep
(see above)npm run test-only
- This may be useful if you've instrumented and run preparation steps after any code modifications, but just need to re-run tests (e.g., if one did not complete them for some reason). Also should be useful if tests are only against the ESM builds (as is currently the case), and you therefore don't needprep
(and you are not concerned at the moment with accurate coverage, so you can skipinstrument
). This script includes a separatereport
step or otherwise the tests will not show the results visibly on the command line. See alsotest-no-cov-no-core-rollup
.npm run test-only-no-report
- Should not be needed alone.npm start
- Starts the servernpm run cypress:run
- Runs Cypress tests (cypress run
).cypress:run
is made of subroutines which also merge Mocha results (since Cypress produces separate files) and updates the testing and coverage badges.
npm run report
(see above)
npm run test-no-core-rollup
- This applies the same headless testing steps asnpm test
minus the time-consumingnpm run rollup
. This script may be useful if you are only modifying config files but not svgedit core.instrument
(see above)npm run test-no-cov-no-core-rollup
. As withtest-no-cov
but nonpm run rollup
routine (part ofprep
).
open-tests
instrument
(see above)cypress:open
- Useful withoutinstrument
if you are not concerned at the moment with coverage. Note that the hot-reloading does not currently reinstrument even if you ran throughopen-tests
.npm start
cypress:open-no-start
. Runscypress open
, the headed mode. Useful for testing single files with hot reloading.