Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
jest-hugo
allows you to test your Hugo theme.
Tests are written in a tests directory in files having the .md extension. Jest is used for testing. The Jest watch mode is also supported (no need for Hugo in watch mode).
Add jest-hugo
and jest
packages to your theme repo: npm install --save jest jest-hugo
tests
subdirectory with .md
files under it<test dir>/.output
and is auto-cleaned before each rundemo
subdirectory.Write each test case enclosed in a <test name="test name">
tag where name
can be any descriptive name representing the test. Example:
<test name="should render successfully">
{{% myshortcode %}}
...
{{% /myshortcode %}}
</test>
When running the tests, a Jest __snapshots__
subdirectory will be created at the same level as your test file.
This project allows asserting errors from errorf
. For that, use the expect
keyword the following way:
<test name="should throw an error when invalid type is provided">
{{< expect error="Invalid type!" >}}
{{% myshortcode type="invalid" %}}
...
{{% /myshortcode %}}
</test>
When running the tests, ERROR YYYY/MM/DD HH:MM:SS shortcodes\myshortcode.md: Invalid type! will be expected to be found in the Hugo output.
npm run jest
jest -u
jest --watchAll
which will rerun tests whenever there is an update.You can provide your own Hugo config by creating a jest-hugo.config.json
file at the root of your project.
Variable | Description | Default |
---|---|---|
JEST_HUGO_TEST_DIR | Name of the test directory | "tests" |
JEST_HUGO_EXECUTABLE | Name of the Hugo command | "hugo" |
JEST_HUGO_DEBUG | Output additional logs | false |
npm install
or yarn install
demo
subdirectorynpm install
or yarn install
npm run jest
or yarn jest
The demo was tested with Hugo v0.62.0 and the latest version.
unsafe: true
for the Goldmark renderer. See: markup.goldmark.renderer
.callout.md
for example.warnf
template func introduced with Hugo v0.62.0. For that reason, versions of Hugo before 0.62.0 aren't supported anymore.errorf
with the exact same string. This means a single test file can't output multiple times the same error, and test cases expecting an exact same error message must be defined in their own .md file (see demo/tests/shortcodes
subdirectory) (see also: #20).Feel free to give feedback.
FAQs
Test your hugo theme including shortcodes using Jest
The npm package jest-hugo receives a total of 21 weekly downloads. As such, jest-hugo popularity was classified as not popular.
We found that jest-hugo demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.