chore: #3 add basic tests#20
Conversation
✅ Deploy Preview for legendary-starlight-75451b ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
|
||
| function setUpEleventy(pluginOptions = {}) { | ||
| return new Eleventy('demo', 'test/output', { | ||
| configPath: null, |
There was a problem hiding this comment.
This prevents the project's root eleventy config file from overriding the test configs.
| config: function (eleventyConfig) { | ||
| eleventyConfig.addPlugin(wccPlugin, { | ||
| definitions: [ | ||
| new URL('../demo/components/greeting.js', import.meta.url) |
There was a problem hiding this comment.
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.mdI 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'There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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: