The project has a fairly extensive automated test suite using vitest.
However, browser testing is still required because the runtime environment is
fundamentally different. In particular, the library interacts with browser APIs
such as WebSerial, which cannot be fully simulated in the Node test
environment.
For this reason, a set of simple browser examples is provided in the
examples/ directory. These can be used to test the library directly
against real hardware in a real browser environment.
All example pages load modbus-webserial dynamically via an
import map that can be overridden through a query parameter.
Because of this mechanism, the library source can be changed simply by adding a query parameter:
?src=<url>
Example:
http://localhost:3000/simple-test/?src=https://unpkg.com/modbus-webserial@latest/dist/index.js
For development, a small test server is included which serves the example pages and the locally built library.
node scripts/dev-server.mjs 3000
This will:
examples/ at http://localhost:3000http://localhost:3000/dist
The server supports a convenience parameter ?local which redirects
the page to load the locally built library.
Example:
http://localhost:3000/simple-test/?local
which resolves to:
http://localhost:3000/simple-test/?src=http://localhost:3000/dist/index.js
This allows testing local changes against the example pages without modifying any example files.