Eleventy is hands-down my favourite static site generator. I also make plugins for it! So after a while of brute forcing my Eleventy testing, I thought an easier solution should exist. Hopefully this is that!
- Build using multiple Eleventy versions & configurations for your tests (called scenarios) seperately. Returns the file contents per scenario output for easy access during testing.
- Compatible with any test framework or method.
- Automatic installation of latest/specific Eleventy version (if not found locally).
- Aside from the Eleventy versions used to test, this package itself has zero dependencies when installing.
Want to see how it is in action? For the dogfooding fans, you can see this library in action in this library's tests!
- Install the plugin
npm install --save-dev eleventy-test yarn add -D eleventy-test
- Create
${projectRoot}/tests/scenarios/
- Create a subdirectory for each scenario you wish to set up. The directory name should start with the exact (1.0.2) or major (1) version. The format should be one of the following:
${projectRoot}/tests/scenarios/${eleventyVersion}--${label}/
${projectRoot}/tests/scenarios/${eleventyVersion}/
- Add an Eleventy configuration file to the scenario
- Use the buildScenarios function and its output as needed
import { buildScenarios } from "eleventy-test"; import test from "ava"; const resultsAsDict = await buildScenarios({ projectRoot: cwd(), returnArray: false, enableDebug: false }); test("Check if index.html is consistent across builds", async t => { t.deepEqual( await results["3--example"].getFileContent("/index.html"), await results["3.0.0--identical-example"].getFileContent("/index.html")); });
And that's it! eleventy-test will handle installing the right versons and reading (and caching) the file contents back to you.
Note: you might want to add
eleventy-test-out/
to your .gitignore file!
This require Node.js & yarn to be installed.
git clone https://github.com/Denperidge/eleventy-test
cd eleventy-test
yarn install
yarn watch # Watch for changes
yarn build # Build
yarn start # Run built js as module (see bottom of index.ts require.main === module)
yarn test # Run the tests from tests/test.mjs
This project is licensed under the MIT License.