automerge/automerge-js/e2e
Alex Good dbf438f7cb
Track whether a transaction is observed in types
With the `OpObserver` moving to the transaction rather than being passed
in to the `Transaction::commit` method we have needed to add a way to
get the observer back out of the transaction (via
`Transaction::observer` and `AutoCommit::observer`). This `Observer`
type is then used to handle patch generation logic. However, there are
cases where we might not want an `OpObserver` and in these cases we can
execute various things fast - so we need to have something like an
`Option<OpObserver>`. In order to track the presence or otherwise of the
observer at the type level introduce
`automerge::transaction::observation`, which is a type level `Option`.
This allows us to efficiently choose the right code paths whilst
maintaining correct types for `Transaction::observer` and
`AutoCommit::observer`
2022-10-06 22:38:37 +01:00
..
.gitignore Add an e2e testing tool for the JS packaging 2022-10-04 17:23:37 +01:00
index.ts Add an e2e testing tool for the JS packaging 2022-10-04 17:23:37 +01:00
package.json Add an e2e testing tool for the JS packaging 2022-10-04 17:23:37 +01:00
README.md Add an e2e testing tool for the JS packaging 2022-10-04 17:23:37 +01:00
tsconfig.json Add an e2e testing tool for the JS packaging 2022-10-04 17:23:37 +01:00
verdaccio.yaml Track whether a transaction is observed in types 2022-10-06 22:38:37 +01:00
yarn.lock Add an e2e testing tool for the JS packaging 2022-10-04 17:23:37 +01:00

#End to end testing for javascript packaging

The network of packages and bundlers we rely on to get the automerge package working is a little complex. We have the automerge-wasm package, which the automerge package depends upon, which means that anyone who depends on automerge needs to either a) be using node or b) use a bundler in order to load the underlying WASM module which is packaged in automerge-wasm.

The various bundlers involved are complicated and capricious and so we need an easy way of testing that everything is in fact working as expected. To do this we run a custom NPM registry (namely Verdaccio) and build the automerge-wasm and automerge packages and publish them to this registry. Once we have this registry running we are able to build the example projects which depend on these packages and check that everything works as expected.

Usage

First, install everything:

yarn install

Build automerge-js

This builds the automerge-wasm package and then runs yarn build in the automerge-js project with the --registry set to the verdaccio registry. The end result is that you can run yarn test in the resulting automerge-js directory in order to run tests against the current automerge-wasm.

yarn e2e buildjs

Build examples

This either builds or the examples in automerge-js/examples or just a subset of them. Once this is complete you can run the relevant scripts (e.g. vite dev for the Vite example) to check everything works.

yarn e2e buildexamples

Or, to just build the webpack example

yarn e2e buildexamples -e webpack

Run Registry

If you're experimenting with a project which is not in the examples folder you'll need a running registry. run-registry builds and publishes automerge-js and automerge-wasm and then runs the registry at localhost:4873.

yarn e2e run-registry

You can now run yarn install --registry http://localhost:4873 to experiment with the built packages.

Using the dev build of automerge-wasm

All the commands above take a -p flag which can be either release or debug. The debug builds with additional debug symbols which makes errors less cryptic.