From b7d5adbe4ea1553b60686d359e92d1e491d29510 Mon Sep 17 00:00:00 2001
From: Kai Prince <34746763+KaiPrince@users.noreply.github.com>
Date: Sun, 28 Dec 2025 12:32:51 -0500
Subject: [PATCH 1/8] chore: Add basic tests
Create plugin.test.js
---
test/plugin.test.js | 38 ++++++++++++++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)
diff --git a/test/plugin.test.js b/test/plugin.test.js
index 8ca668f..9ded682 100644
--- a/test/plugin.test.js
+++ b/test/plugin.test.js
@@ -1,9 +1,44 @@
import Eleventy from '@11ty/eleventy';
import { wccPlugin } from '../src/index.js';
import assert from 'node:assert/strict';
-import { describe, it } from 'node:test';
+import { describe, it, before } from 'node:test';
describe('WCC plugin', () => {
+ let indexMdFile;
+
+ before(async () => {
+ const elev = new Eleventy('demo', 'test/output', {
+ config: function (eleventyConfig) {
+ eleventyConfig.addPlugin(wccPlugin.configFunction);
+ }
+ });
+
+ await elev.init();
+ const elevOutput = await elev.toJSON();
+
+ indexMdFile = elevOutput.find(
+ (file) => file.inputPath === './demo/index.md'
+ );
+ assert.ok(indexMdFile, 'Precondition failed: demo/index.md not found');
+ });
+
+ it('prints the header', () => {
+ const expected = '
11ty + WCC Demo
';
+
+ assert.ok(indexMdFile.content.includes(expected), 'Header not found');
+ });
+
+ it('prints the greeting component', () => {
+ const contentNormalized = indexMdFile.content.replaceAll(/\s+/g, ' ').trim();
+ const expected =
+ ' Hello from the greeting component!
';
+
+ assert.ok(
+ contentNormalized.includes(expected),
+ 'x-greeting component not found'
+ );
+ });
+
it('removes wrapping p tags', async () => {
const elev = new Eleventy('demo', 'test/output', {
config: function (eleventyConfig) {
@@ -12,7 +47,6 @@ describe('WCC plugin', () => {
});
await elev.init();
-
const elevOutput = await elev.toJSON();
const result = elevOutput[0].content;
From a6ae91c9725e35ff7599b767e2217ef57405ddcb Mon Sep 17 00:00:00 2001
From: Kai Prince <34746763+KaiPrince@users.noreply.github.com>
Date: Tue, 30 Dec 2025 19:36:20 -0800
Subject: [PATCH 2/8] Add test setup functions
---
test/plugin.test.js | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/test/plugin.test.js b/test/plugin.test.js
index 9ded682..347f3c7 100644
--- a/test/plugin.test.js
+++ b/test/plugin.test.js
@@ -54,3 +54,31 @@ describe('WCC plugin', () => {
assert.doesNotMatch(result, regexp);
});
});
+
+function setUpEleventy(pluginOptions = {}) {
+ return new Eleventy('demo', 'test/output', {
+ config: function (eleventyConfig) {
+ eleventyConfig.addPlugin(wccPlugin, {
+ definitions: [
+ new URL('../demo/components/greeting.js', import.meta.url)
+ ],
+ ...pluginOptions
+ });
+ }
+ });
+}
+
+async function setUpTemplates(eleventy = null) {
+ eleventy ??= setUpEleventy();
+
+ await eleventy.init();
+ const elevOutput = await eleventy.toJSON();
+
+ const indexMdFile = elevOutput.find(
+ (template) => template.inputPath === './demo/index.md'
+ );
+ assert.ok(indexMdFile, 'Precondition failed: demo/index.md not found');
+
+ return { indexMdFile };
+}
+
From 9a4a3d99a6c467158d28a7735242519fde968615 Mon Sep 17 00:00:00 2001
From: Kai Prince <34746763+KaiPrince@users.noreply.github.com>
Date: Tue, 30 Dec 2025 19:37:35 -0800
Subject: [PATCH 3/8] Use setup helpers
---
test/plugin.test.js | 15 ++-------------
1 file changed, 2 insertions(+), 13 deletions(-)
diff --git a/test/plugin.test.js b/test/plugin.test.js
index 347f3c7..8cb8d59 100644
--- a/test/plugin.test.js
+++ b/test/plugin.test.js
@@ -7,19 +7,8 @@ describe('WCC plugin', () => {
let indexMdFile;
before(async () => {
- const elev = new Eleventy('demo', 'test/output', {
- config: function (eleventyConfig) {
- eleventyConfig.addPlugin(wccPlugin.configFunction);
- }
- });
-
- await elev.init();
- const elevOutput = await elev.toJSON();
-
- indexMdFile = elevOutput.find(
- (file) => file.inputPath === './demo/index.md'
- );
- assert.ok(indexMdFile, 'Precondition failed: demo/index.md not found');
+ const templates = await setUpTemplates();
+ ({ indexMdFile } = templates);
});
it('prints the header', () => {
From 92b447e3d1e004656352eb4c785ada8d20fa0ab4 Mon Sep 17 00:00:00 2001
From: Kai Prince <34746763+KaiPrince@users.noreply.github.com>
Date: Tue, 30 Dec 2025 19:39:32 -0800
Subject: [PATCH 4/8] Add Default options test group
---
test/plugin.test.js | 53 ++++++++++++++++++++-------------------------
1 file changed, 24 insertions(+), 29 deletions(-)
diff --git a/test/plugin.test.js b/test/plugin.test.js
index 8cb8d59..7fefac0 100644
--- a/test/plugin.test.js
+++ b/test/plugin.test.js
@@ -4,43 +4,38 @@ import assert from 'node:assert/strict';
import { describe, it, before } from 'node:test';
describe('WCC plugin', () => {
- let indexMdFile;
+ describe('Default options', () => {
+ let indexMdFile;
- before(async () => {
- const templates = await setUpTemplates();
- ({ indexMdFile } = templates);
- });
-
- it('prints the header', () => {
- const expected = '11ty + WCC Demo
';
+ before(async () => {
+ const templates = await setUpTemplates();
+ ({ indexMdFile } = templates);
+ });
- assert.ok(indexMdFile.content.includes(expected), 'Header not found');
- });
+ it('prints the header', () => {
+ const expected = '11ty + WCC Demo
';
- it('prints the greeting component', () => {
- const contentNormalized = indexMdFile.content.replaceAll(/\s+/g, ' ').trim();
- const expected =
- ' Hello from the greeting component!
';
+ assert.ok(indexMdFile.content.includes(expected), 'Header not found');
+ });
- assert.ok(
- contentNormalized.includes(expected),
- 'x-greeting component not found'
- );
- });
+ it('prints the greeting component', () => {
+ const contentNormalized = indexMdFile.content
+ .replaceAll(/\s+/g, ' ')
+ .trim();
+ const expected =
+ ' Hello from the greeting component!
';
- it('removes wrapping p tags', async () => {
- const elev = new Eleventy('demo', 'test/output', {
- config: function (eleventyConfig) {
- eleventyConfig.addPlugin(wccPlugin.configFunction);
- }
+ assert.ok(
+ contentNormalized.includes(expected),
+ 'x-greeting component not found'
+ );
});
- await elev.init();
- const elevOutput = await elev.toJSON();
- const result = elevOutput[0].content;
+ it('removes wrapping p tags', () => {
+ const regexp = new RegExp('(.|\\s)*
');
- const regexp = new RegExp('(.|\\s)*
');
- assert.doesNotMatch(result, regexp);
+ assert.doesNotMatch(indexMdFile.content, regexp);
+ });
});
});
From f9b7aa197cac58fadf88a30764bda9a5bbceea64 Mon Sep 17 00:00:00 2001
From: Kai Prince <34746763+KaiPrince@users.noreply.github.com>
Date: Tue, 30 Dec 2025 19:40:40 -0800
Subject: [PATCH 5/8] Add test for trimParagraphTagsInMd: false
---
test/plugin.test.js | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/test/plugin.test.js b/test/plugin.test.js
index 7fefac0..2d93295 100644
--- a/test/plugin.test.js
+++ b/test/plugin.test.js
@@ -37,6 +37,16 @@ describe('WCC plugin', () => {
assert.doesNotMatch(indexMdFile.content, regexp);
});
});
+
+ describe('trimParagraphTagsInMd: false', () => {
+ it('leaves wrapping p tags', async () => {
+ const eleventy = setUpEleventy({ trimParagraphTagsInMd: false });
+ const { indexMdFile } = await setUpTemplates(eleventy);
+ const regexp = new RegExp('(.|\\s)*
');
+
+ assert.match(indexMdFile.content, regexp);
+ });
+ });
});
function setUpEleventy(pluginOptions = {}) {
From 76ca78579d45518ff513d25da0a7a5d35b44b055 Mon Sep 17 00:00:00 2001
From: Kai Prince <34746763+KaiPrince@users.noreply.github.com>
Date: Tue, 30 Dec 2025 19:40:52 -0800
Subject: [PATCH 6/8] Override config path in tests
---
test/plugin.test.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/test/plugin.test.js b/test/plugin.test.js
index 2d93295..3433120 100644
--- a/test/plugin.test.js
+++ b/test/plugin.test.js
@@ -51,6 +51,7 @@ describe('WCC plugin', () => {
function setUpEleventy(pluginOptions = {}) {
return new Eleventy('demo', 'test/output', {
+ configPath: null,
config: function (eleventyConfig) {
eleventyConfig.addPlugin(wccPlugin, {
definitions: [
From c2936f8851b9984ad8cc635050c7e5604d10af24 Mon Sep 17 00:00:00 2001
From: Kai Prince <34746763+KaiPrince@users.noreply.github.com>
Date: Wed, 31 Dec 2025 16:24:44 -0800
Subject: [PATCH 7/8] duplicate demo to test_fixtures folder
---
test/plugin.test.js | 7 ++++---
test_fixtures/components/greeting.js | 18 ++++++++++++++++++
test_fixtures/index.md | 3 +++
3 files changed, 25 insertions(+), 3 deletions(-)
create mode 100644 test_fixtures/components/greeting.js
create mode 100644 test_fixtures/index.md
diff --git a/test/plugin.test.js b/test/plugin.test.js
index 3433120..d7775c9 100644
--- a/test/plugin.test.js
+++ b/test/plugin.test.js
@@ -50,12 +50,12 @@ describe('WCC plugin', () => {
});
function setUpEleventy(pluginOptions = {}) {
- return new Eleventy('demo', 'test/output', {
+ return new Eleventy('test_fixtures', 'test/output', {
configPath: null,
config: function (eleventyConfig) {
eleventyConfig.addPlugin(wccPlugin, {
definitions: [
- new URL('../demo/components/greeting.js', import.meta.url)
+ new URL('../test_fixtures/components/greeting.js', import.meta.url)
],
...pluginOptions
});
@@ -70,8 +70,9 @@ async function setUpTemplates(eleventy = null) {
const elevOutput = await eleventy.toJSON();
const indexMdFile = elevOutput.find(
- (template) => template.inputPath === './demo/index.md'
+ (template) => template.inputPath === './test_fixtures/index.md'
);
+
assert.ok(indexMdFile, 'Precondition failed: demo/index.md not found');
return { indexMdFile };
diff --git a/test_fixtures/components/greeting.js b/test_fixtures/components/greeting.js
new file mode 100644
index 0000000..785b94b
--- /dev/null
+++ b/test_fixtures/components/greeting.js
@@ -0,0 +1,18 @@
+const template = document.createElement('template');
+
+template.innerHTML = `
+ Hello from the greeting component!
+`;
+
+export default class GreetingComponent extends HTMLElement {
+ constructor() {
+ super();
+ this.attachShadow({ mode: 'open' });
+ }
+
+ async connectedCallback() {
+ this.shadowRoot.appendChild(template.content.cloneNode(true));
+ }
+}
+
+customElements.define('x-greeting', GreetingComponent);
\ No newline at end of file
diff --git a/test_fixtures/index.md b/test_fixtures/index.md
new file mode 100644
index 0000000..274e12f
--- /dev/null
+++ b/test_fixtures/index.md
@@ -0,0 +1,3 @@
+## 11ty + WCC Demo
+
+
\ No newline at end of file
From 52a1e527fc92afd14db551cf6b4233ebf2691444 Mon Sep 17 00:00:00 2001
From: Kai Prince <34746763+KaiPrince@users.noreply.github.com>
Date: Wed, 31 Dec 2025 17:05:04 -0800
Subject: [PATCH 8/8] rename folder to test-fixtures
---
{test_fixtures => test-fixtures}/components/greeting.js | 0
{test_fixtures => test-fixtures}/index.md | 0
test/plugin.test.js | 6 +++---
3 files changed, 3 insertions(+), 3 deletions(-)
rename {test_fixtures => test-fixtures}/components/greeting.js (100%)
rename {test_fixtures => test-fixtures}/index.md (100%)
diff --git a/test_fixtures/components/greeting.js b/test-fixtures/components/greeting.js
similarity index 100%
rename from test_fixtures/components/greeting.js
rename to test-fixtures/components/greeting.js
diff --git a/test_fixtures/index.md b/test-fixtures/index.md
similarity index 100%
rename from test_fixtures/index.md
rename to test-fixtures/index.md
diff --git a/test/plugin.test.js b/test/plugin.test.js
index d7775c9..9feb844 100644
--- a/test/plugin.test.js
+++ b/test/plugin.test.js
@@ -50,12 +50,12 @@ describe('WCC plugin', () => {
});
function setUpEleventy(pluginOptions = {}) {
- return new Eleventy('test_fixtures', 'test/output', {
+ return new Eleventy('test-fixtures', 'test/output', {
configPath: null,
config: function (eleventyConfig) {
eleventyConfig.addPlugin(wccPlugin, {
definitions: [
- new URL('../test_fixtures/components/greeting.js', import.meta.url)
+ new URL('../test-fixtures/components/greeting.js', import.meta.url)
],
...pluginOptions
});
@@ -70,7 +70,7 @@ async function setUpTemplates(eleventy = null) {
const elevOutput = await eleventy.toJSON();
const indexMdFile = elevOutput.find(
- (template) => template.inputPath === './test_fixtures/index.md'
+ (template) => template.inputPath === './test-fixtures/index.md'
);
assert.ok(indexMdFile, 'Precondition failed: demo/index.md not found');