{"id":14981424,"url":"https://github.com/manixate/jest-hugo","last_synced_at":"2025-10-29T05:31:50.261Z","repository":{"id":42992588,"uuid":"199015550","full_name":"manixate/jest-hugo","owner":"manixate","description":"Run tests for your hugo content using Jest","archived":false,"fork":false,"pushed_at":"2023-03-11T13:13:58.000Z","size":593,"stargazers_count":5,"open_issues_count":4,"forks_count":1,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-09-29T05:41:16.389Z","etag":null,"topics":["hugo","jest","testing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/manixate.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-26T12:48:31.000Z","updated_at":"2023-03-06T08:32:43.000Z","dependencies_parsed_at":"2023-02-06T11:30:18.888Z","dependency_job_id":null,"html_url":"https://github.com/manixate/jest-hugo","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manixate%2Fjest-hugo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manixate%2Fjest-hugo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manixate%2Fjest-hugo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manixate%2Fjest-hugo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/manixate","download_url":"https://codeload.github.com/manixate/jest-hugo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219858321,"owners_count":16556048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hugo","jest","testing"],"created_at":"2024-09-24T14:03:33.063Z","updated_at":"2025-10-29T05:31:50.256Z","avatar_url":"https://github.com/manixate.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jest-hugo\n\n[![](https://img.shields.io/npm/v/jest-hugo.svg)](https://www.npmjs.com/package/jest-hugo)\n[![](https://img.shields.io/badge/license-MIT-yellow.svg)](https://github.com/manixate/jest-hugo/blob/master/LICENSE)\n[![](https://github.com/manixate/jest-hugo/workflows/Demo/badge.svg)](https://github.com/manixate/jest-hugo/actions/workflows/demo.yml)\n[![](https://github.com/manixate/jest-hugo/workflows/Prettier/badge.svg)](https://github.com/manixate/jest-hugo/actions/workflows/prettier.yml)\n\n## Overview\n\n`jest-hugo` allows you to test your [Hugo](https://github.com/gohugoio/hugo) theme.\n\nTests are written in a _tests_ directory in files having the _.md_ extension.\n[Jest](https://jestjs.io/) is used for testing. The Jest watch mode is also supported (no need for Hugo in watch mode).\n\n## Requirements\n\n1. Jest 24+\n2. NodeJS 8+\n3. Hugo \u003e= [v0.100.0](https://github.com/gohugoio/hugo/releases/tag/v0.100.0)\n\n## Usage\n\n### Adding Dependencies\n\nAdd `jest-hugo` and `jest` packages to your theme repo: `npm install --save jest jest-hugo`\n\n### Writing Tests\n\n#### Guidelines\n\n- Create a `tests` subdirectory with `.md` files under it\n- Each test must be written in Markdown\n- The Hugo output is generated under `\u003ctest dir\u003e/.output` and is auto-cleaned before each run\n- To exclude a Markdown file from testing, use _.ignore.md_ as file extension (instead of _.md_)\n- Usage with test reporters is also supported. For that, refer to the [`demo`](./demo) subdirectory.\n\n#### Nominal Cases ✔️\n\nWrite each test case enclosed in a `\u003ctest name=\"test name\"\u003e` tag where `name` can be any descriptive name representing the test. Example:\n\n```\n\u003ctest name=\"should render successfully\"\u003e\n  {{% myshortcode %}}\n  ...\n  {{% /myshortcode %}}\n\u003c/test\u003e\n```\n\nWhen running the tests, a Jest `__snapshots__` subdirectory will be created at the same level as your test file.\n\n#### Error Cases ❌\n\nThis project allows asserting errors from [`errorf`](https://gohugo.io/functions/errorf/). For that, use the `expect` keyword the following way:\n\n```\n\u003ctest name=\"should throw an error when invalid type is provided\"\u003e\n  {{\u003c expect error=\"Invalid type!\" \u003e}}\n  {{% myshortcode type=\"invalid\" %}}\n  ...\n  {{% /myshortcode %}}\n\u003c/test\u003e\n```\n\nWhen 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.\n\n### Running Tests\n\n1. Run tests using `npm run jest`\n2. Update Jest snapshots with `jest -u`\n3. For watch mode, use `jest --watchAll` which will rerun tests whenever there is an update.\n\n## Configuration\n\n### Hugo Configuration\n\nYou can provide your own Hugo config by creating a `jest-hugo.config.json` file at the root of your project.\n\n### Environment Variables\n\n| Variable               | Description                | Default |\n| ---------------------- | -------------------------- | ------- |\n| `JEST_HUGO_TEST_DIR`   | Name of the test directory | \"tests\" |\n| `JEST_HUGO_EXECUTABLE` | Name of the Hugo command   | \"hugo\"  |\n| `JEST_HUGO_DEBUG`      | Output additional logs     | false   |\n\n## Demo\n\n1. Checkout this repo\n2. Run `npm install` or `yarn install`\n3. Go to the `demo` subdirectory\n4. Run `npm install` or `yarn install`\n5. Run tests using `npm run jest` or `yarn jest`\n\nThe demo was tested with Hugo [v0.100.0](https://github.com/gohugoio/hugo/releases/tag/v0.100.0) and the [latest](https://github.com/gohugoio/hugo/releases/latest) version.\n\n## Known Limitations\n\n- This project requires to enable `unsafe: true` for the Goldmark renderer. See: [`markup.goldmark.renderer`](https://gohugo.io/getting-started/configuration-markup).\n- Ensure that each test file has a front matter (an empty one works too). See [`callout.md`](./demo/tests/shortcodes/callout.md?plain=1) for example.\n- One single log message is created for multiple calls to [`errorf`](https://gohugo.io/functions/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`](./demo/tests/shortcodes) subdirectory) (see also: [#20](https://github.com/manixate/jest-hugo/issues/20)).\n\nFeel free to give feedback.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanixate%2Fjest-hugo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmanixate%2Fjest-hugo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanixate%2Fjest-hugo/lists"}