@webship-js/astro-steps
v2.0.0
Published
webship-js test project for testing an Astro site's main pages.
Readme
Astro-steps
A webship-js test project for Astro
sites: custom step definitions for a site's generator metadata, navigation
menu, and link health, combined with webship-js's own built-in steps in
BDD-style Cucumber .feature files.
Installation
To reuse these steps in your own webship-js project:
npm install --save-dev webship-js @webship-js/astro-stepsAdd both step-definition paths to your project's cucumber.js:
module.exports = {
default: {
require: [
'node_modules/webship-js/tests/step-definitions/**/*.js', // webship-js core steps
'node_modules/@webship-js/astro-steps/tests/step-definitions/astro.steps.js', // this plugin
'tests/step-definitions/**/*.js', // your own custom steps, if any
],
paths: ['tests/features/**/*.feature'],
worldParameters: {
launchUrl: process.env.LAUNCH_URL || 'https://your-astro-site.example',
},
},
};What's in this repo
| Path | What it is |
| ------------------------------ | ----------------------------------------------------------------- |
| tests/step-definitions/ | Custom Astro step definitions (astro.steps.js) |
| tests/features/ | Feature files testing the demo site's main pages |
| demo/ | A minimal Astro site used as the test fixture |
| .github/workflows/ | CI: builds the demo site with DDEV and runs the test suite |
Quick start
npm install
npx playwright install chromium
cd demo && npm install && npm run dev # serves http://localhost:4321
cd ..
LAUNCH_URL=http://localhost:4321 npm testSet worldParameters.launchUrl in cucumber.js (or the LAUNCH_URL
environment variable) to point the suite at any Astro site — the demo
site or a real deployment.
Writing feature files
Combine webship-js's built-in steps with the custom Astro steps in
tests/step-definitions/astro.steps.js:
Feature: Home page
Scenario: Home page is generated by Astro and has working navigation
Given I am on the homepage
Then the page should be generated by Astro
And I should see a navigation menu with the following links:
| text | path |
| Home | / |
| About | /about |
And all navigation links should resolve successfullyThe custom steps are:
| Step | Type |
| --- | --- |
| I should( not) see the Astro generator meta tag / the page should( not) be generated by Astro | Then |
| the page should( not) be generated by Astro version "<prefix>" | Then |
| the page title should( not) end with "<suffix>" | Then |
| I should( not) see a navigation menu with the following links: (table with text and optional path) | Then |
| all navigation links should resolve successfully | Then |
Every Then step takes should or should not, every pronoun step takes I,
we or no pronoun, and every failure is a friendly message with a hint (no
assertion stack). Each assertion polls its condition for the
minWaitTime.page budget (at least 10 s) instead of reading the page once.
The reference features assert the demo site's own titles, copy and paths
("Astro Steps Demo", /blog/hello-world/, ...); swap them for your site's
content when you copy a feature.
See tests/features/README.md for the full
list of feature files, and tests/step-definitions/astro.steps.js
for the custom step definitions themselves (five Gherkin examples each).
npm run test:examples checks that every example matches its own step (and
no webship-js core step) and that every feature step is defined exactly
once; CI runs it before the suite.
See CONTRIBUTING.md for git identity and branching rules.
