Skip to content

chore: #3 add basic tests#20

Merged
KaiPrince merged 8 commits into
masterfrom
kprince/add-basic-tests
Jan 1, 2026
Merged

chore: #3 add basic tests#20
KaiPrince merged 8 commits into
masterfrom
kprince/add-basic-tests

Conversation

@KaiPrince
Copy link
Copy Markdown
Contributor

Summary

Adds some basic tests, and resolves the issue mentioned in #3 (comment).

Context

This is a follow-up to #16 .

Resolves #3.

Changes

Added test helpers to set up fixtures.

Added the following test cases:

  1. check the header
  2. check the component
  3. check the strip p tags option can be disabled

@netlify
Copy link
Copy Markdown

netlify Bot commented Dec 31, 2025

Deploy Preview for legendary-starlight-75451b ready!

Name Link
🔨 Latest commit 52a1e52
🔍 Latest deploy log https://app.netlify.com/projects/legendary-starlight-75451b/deploys/6955c84498c0800008c5c467
😎 Deploy Preview https://deploy-preview-20--legendary-starlight-75451b.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment thread test/plugin.test.js

function setUpEleventy(pluginOptions = {}) {
return new Eleventy('demo', 'test/output', {
configPath: null,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prevents the project's root eleventy config file from overriding the test configs.

Comment thread test/plugin.test.js Outdated
config: function (eleventyConfig) {
eleventyConfig.addPlugin(wccPlugin, {
definitions: [
new URL('../demo/components/greeting.js', import.meta.url)
Copy link
Copy Markdown
Member

@thescientist13 thescientist13 Dec 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still like to try and keep code under test separate from any demos or anything. Is there any way we can create a fixtures/ directory in the test folder for just what we need for test cases? It could just be copied from demo/ for now

test/
  fixtures/
    components/
      greeting.js
    index.md

I did try playing around with it but as soon as I added those files (and changed nothing about the test cases) I immediately got this error running the tests

➜  eleventy-plugin-wcc git:(kprince/add-basic-tests) ✗ npm run test

> eleventy-plugin-wcc@0.2.0 test
> node --test

file:///Users/owenbuckley/Workspace/project-evergreen/eleventy-plugin-wcc/test/fixtures/components/greeting.js:1
const template = document.createElement('template');
                 ^

ReferenceError: document is not defined
    at file:///Users/owenbuckley/Workspace/project-evergreen/eleventy-plugin-wcc/test/fixtures/components/greeting.js:1:18
    at ModuleJob.run (node:internal/modules/esm/module_job:343:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:647:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)

Node.js v22.18.0
✖ test/fixtures/components/greeting.js (37.016916ms)
▶ WCC plugin
  ▶ Default options
    ✔ prints the header (0.31225ms)
    ✔ prints the greeting component (0.051541ms)
    ✔ removes wrapping p tags (0.091333ms)
  ✔ Default options (95.555584ms)
  ▶ trimParagraphTagsInMd: false
    ✔ leaves wrapping p tags (10.53925ms)
  ✔ trimParagraphTagsInMd: false (10.685917ms)
✔ WCC plugin (106.431125ms)
▶ stripWrappingParagraphs
  ✔ removes wrapping p tags (2.236208ms)
  ✔ removes wrapping p tags (inner content) (0.409458ms)
  ✔ removes wrapping p tags (inner content, newlines) (0.289792ms)
  ✔ removes wrapping p tags (whitespace) (0.2195ms)
  ✔ does not remove wrapping p tags if it includes other content (0.508292ms)
  ✔ removes wrapping p tags (multiple) (0.748083ms)
✔ stripWrappingParagraphs (4.913292ms)
ℹ tests 11
ℹ suites 4
ℹ pass 10
ℹ fail 1
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 430.952542

✖ failing tests:

test at test/fixtures/components/greeting.js:1:1
✖ test/fixtures/components/greeting.js (37.016916ms)
  'test failed'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sure, can do. I chose not to do the full e2e approach with gallinago mostly because I thought it would be more performant if we don't have to wait for everything to write to disk. But let me know if you want it that way like we have in Greenwood.

Copy link
Copy Markdown
Member

@thescientist13 thescientist13 Dec 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be with or without gallinago, I think the main thing is just making sure each test case is self-contained (at least from the demo code), so we can easily test multiple combinations of configs / code / layouts / etc (like we do in Greenwood), and then it's clearer what each test setup each does and needs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it's erroring because node test runner tries to import all the files in the test folder. And when it imports the component it's not running in a browser/document context.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, makes sense. Dedicate fixtures folder looks good. Only recommendation would be to rename to test-fixture, I generally prefer hyphens to underscores for file name seperators.

@thescientist13 thescientist13 changed the title chore: Add basic tests chore: #3 Add basic tests Dec 31, 2025
@thescientist13 thescientist13 changed the title chore: #3 Add basic tests chore: #3 add basic tests Jan 1, 2026
@KaiPrince KaiPrince merged commit 669f108 into master Jan 1, 2026
8 checks passed
@KaiPrince KaiPrince deleted the kprince/add-basic-tests branch January 1, 2026 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add basic test cases

2 participants