Skip to main content

End-to-end tests

Playwright drives the deck in the CDK, so a spec asserts what a salesperson would see. Two things are tested this way:

  • Decks covers a slide, a section or a template on the stage.
  • Fieldsets covers the form a deck's fieldsets hook builds.

Both use the setup below.

Setup​

Install @livepreso/cdk​

npm install --save-dev @livepreso/cdk
package.json
{
"scripts": {
"cdk": "livepreso-cdk dev .",
"dev": "livepreso-deck serve --config ./webpack.dev.config.js --env development",
"prod": "livepreso-deck build --config ./webpack.prod.config.js --env production",
"test:e2e": "playwright test"
}
}
npm run cdk
warning

A test drives a deck the CDK is serving from dist, so build the deck before running one. The config below can start the CDK for you; without it, start the CDK yourself and leave it running.

Install @playwright/test​

npm install --save-dev @playwright/test
// playwright.config.mjs
import { defineConfig } from "@playwright/test";
import { buildDeckConfig } from "@livepreso/content-testing/playwright/config";

export default defineConfig(
await buildDeckConfig({
testMatch: "**/*.e2e.mjs",
}),
);
warning

Name your specs .e2e.mjs. This package is ES modules, and a deck without "type": "module" in its package.json loads a .js spec as CommonJS, which cannot import it:

Cannot use import statement outside a module

A deck that sets "type": "module" can use .e2e.js.

buildDeckConfig connects the tests to a CDK and sets the viewport, and takes everything else you pass straight through.

Where the deck installed @livepreso/cdk, it starts a CDK on a free port for the run, so the tests never drive the CDK you have open while you work. Where the deck installed none, it points the tests at the CDK already serving the deck, found from the deck's package name. Write your own webServer and it leaves that alone.

The viewport is the dimensions in the deck's project file, so slides render at the size they were built for. Set a viewport under use to render at another size.

testMatch is the glob that selects spec files; here, any file ending .e2e.mjs. Specs can live next to the slide they test, or together in one folder.

Running against a CDK you already have open​

Set CDK_URL and the tests use that CDK and start none:

CDK_URL=http://localhost:9720 npm run test:e2e

A CDK that has already served the deck answers faster than one starting from cold, so a local run against the CDK you keep open finishes in a fraction of the time. Leave CDK_URL unset in CI, where each run starts its own.

Usage​

A spec takes test and expect from this package, along with the modes:

import { expect, modes, test } from "@livepreso/content-testing/playwright";

test.describe, test.step and the other playwright APIs work unchanged. A deck that adds fixtures calls test.extend on this test.

warning

Import test and expect from @livepreso/content-testing/playwright. Only these provide the deck and fieldsets fixtures and the toBeRefused matcher, so a spec importing from @playwright/test has none of them.

page is the playwright page the deck renders in. Take it alongside deck to use page.keyboard, page.mouse or any other page-level API:

test("should close the picker on escape", async ({ deck, page }) => {
await deck.setMode(modes.presomanager.editing);
await deck.openTarget("pricing/delivery");

await page.keyboard.press("Escape");
});

page is blank until the spec opens a target or the form, so use it after the first deck or fieldsets call.