[data-reveal]{opacity:1!important;transform:none!important}
AntelopeJS DMS
DocumentationTesting

Testing

Test a frontend module outside the generated workspace, with the layer aliases, the module-route test server, and verify-source in CI.

A frontend module's code usually runs inside the generated workspace, which supplies its aliases and its server. Three tools bring the same pieces to the module's own test suite and CI.

Resolve the layer aliases outside the workspace

Inside the generated workspace, every layer a module ships under layers/<name>/ answers to #<name>. A unit test that runs the module's Vue sources outside the workspace has nothing that supplies #dms-core or #dms-ui. To supply them in Vitest, pass frontendLayerAliases to resolve.alias:

vitest.config.ts ts
import { resolve } from "node:path";
import { frontendLayerAliases } from "@antelopejs/dms-frontend/common";
import { defineConfig } from "vitest/config";

export default defineConfig({
  resolve: {
    alias: frontendLayerAliases(
      resolve(__dirname, "node_modules/@antelopejs/dms/frontend-vue"),
    ),
  },
});

frontendLayerAliases reads a module root on disk and needs no backend, manifest or generated workspace. For a tsconfig, use frontendLayerTypePaths, which returns the same layers in the shape of paths. Both are built on resolveFrontendLayers.

To overlay several modules, pass their roots in increasing precedence. When two modules expose a layer with the same name, the last root wins, which is the order the loader materializes them in.

Call the module routes over HTTP

serveModuleRoutes, from @antelopejs/dms-frontend/templates/vue/server/module-testing.mjs, serves the default export of a module's dms.server.ts on a local port. It uses the same router, event and cookie jar as the frontend server, and reads DMS_API_BASE_URL and DMS_SESSION_SECRET from the environment. A test calls the routes over HTTP and checks their answers, cookies included.

Verify the module in CI

Run ajs dms verify-source in the module's CI next to its unit tests. It builds and type-checks the module against the running loader release and the DMS core layer the project installs, renders the DMS e-mail templates, and checks the bundles, all without a backend.

If the CI type check needs the generated types of a running backend, use ajs dms prepare --strict.