test(markdown-it-plugins): replace jest with vitest

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2025-04-26 11:30:37 +02:00
parent 97219ef497
commit 62ad4da0e7
No known key found for this signature in database
GPG key ID: FE1CD209E3EA5E85
10 changed files with 162 additions and 67 deletions

View file

@ -13,13 +13,8 @@ module.exports = {
}, },
"plugins": [ "plugins": [
"@typescript-eslint", "@typescript-eslint",
"jest",
"prettier" "prettier"
], ],
"env": {
"jest": true,
"jest/globals": true
},
"extends": [ "extends": [
"eslint:recommended", "eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/eslint-recommended",
@ -30,11 +25,6 @@ module.exports = {
"rules": { "rules": {
"prettier/prettier": ["error", "prettier/prettier": ["error",
require('./.prettierrc.json') require('./.prettierrc.json')
], ]
"jest/no-disabled-tests": "warn",
"jest/no-focused-tests": "error",
"jest/no-identical-title": "error",
"jest/prefer-to-have-length": "warn",
"jest/valid-expect": "error"
} }
} }

View file

@ -1,26 +0,0 @@
{
"testRegex" : "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"testPathIgnorePatterns" : [
"/dist/"
],
"moduleFileExtensions" : [
"ts",
"tsx",
"js"
],
"extensionsToTreatAsEsm" : [
".ts"
],
"moduleNameMapper" : {
"^(\\.{1,2}/.*)\\.js$" : "$1"
},
"transform" : {
"^.+\\.tsx?$" : [
"ts-jest",
{
"tsconfig" : "tsconfig.test.json",
"useESM" : true
}
]
}
}

View file

@ -1,3 +0,0 @@
SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
SPDX-License-Identifier: CC0-1.0

View file

@ -86,8 +86,8 @@
], ],
"scripts": { "scripts": {
"build": "./build.sh", "build": "./build.sh",
"test": "jest", "test": "vitest",
"test:ci": "jest --ci", "test:ci": "vitest --run",
"prepublish": "rm -rf dist && yarn lint && yarn build && yarn test", "prepublish": "rm -rf dist && yarn lint && yarn build && yarn test",
"lint": "eslint src --ext .ts", "lint": "eslint src --ext .ts",
"lint:fix": "eslint --fix --ext .ts src" "lint:fix": "eslint --fix --ext .ts src"
@ -108,19 +108,16 @@
"html-entities": "2.5.2" "html-entities": "2.5.2"
}, },
"devDependencies": { "devDependencies": {
"@jest/types": "29.6.3",
"@types/markdown-it": "13.0.8", "@types/markdown-it": "13.0.8",
"@typescript-eslint/eslint-plugin": "8.14.0", "@typescript-eslint/eslint-plugin": "8.14.0",
"@typescript-eslint/parser": "8.14.0", "@typescript-eslint/parser": "8.14.0",
"eslint": "8.57.1", "eslint": "8.57.1",
"eslint-config-prettier": "9.1.0", "eslint-config-prettier": "9.1.0",
"eslint-plugin-jest": "28.9.0",
"eslint-plugin-prettier": "5.2.3", "eslint-plugin-prettier": "5.2.3",
"jest": "29.7.0",
"markdown-it": "13.0.2", "markdown-it": "13.0.2",
"prettier": "3.3.3", "prettier": "3.3.3",
"ts-jest": "29.2.5", "typescript": "5.6.3",
"typescript": "5.6.3" "vitest": "3.1.2"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View file

@ -7,7 +7,7 @@
import MarkdownIt from 'markdown-it/lib' import MarkdownIt from 'markdown-it/lib'
import { imageSize } from './index.js' import { imageSize } from './index.js'
import { describe, expect, it } from '@jest/globals' import { describe, expect, it } from 'vitest'
describe('markdown-it-imsize', function () { describe('markdown-it-imsize', function () {
const md = new MarkdownIt({ const md = new MarkdownIt({

View file

@ -1,9 +1,65 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
/*
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) exports[`markdown-it-task-lists > renders bullet correctly 1`] = `
* "<ul class="contains-task-list">
* SPDX-License-Identifier: MIT <li class="task-list-item "><input class="task-list-item-checkbox" type="checkbox" disabled="" id="task-item-1" />unchecked item 1</li>
*/ <li class="task-list-item "><input class="task-list-item-checkbox" type="checkbox" disabled="" id="task-item-2" />unchecked item 2</li>
<li class="task-list-item "><input class="task-list-item-checkbox" type="checkbox" disabled="" id="task-item-3" />unchecked item 3</li>
<li class="task-list-item "><input class="task-list-item-checkbox" type="checkbox" checked="" disabled="" id="task-item-4" />checked item 4</li>
</ul>
"
`;
exports[`markdown-it-task-lists > renders dirty correctly 1`] = `
"<ul class="contains-task-list">
<li class="task-list-item "><input class="task-list-item-checkbox" type="checkbox" disabled="" id="task-item-1" />unchecked todo item 1</li>
<li>[ ]</li>
<li>[ ] not a todo item 2</li>
<li>[ x] not a todo item 3</li>
<li>[x ] not a todo item 4</li>
<li>[ x ] not a todo item 5</li>
<li class="task-list-item "><input class="task-list-item-checkbox" type="checkbox" checked="" disabled="" id="task-item-7" />todo item 6</li>
</ul>
"
`;
exports[`markdown-it-task-lists > renders mixedNested correctly 1`] = `
"<h1>Test 1</h1>
<ol>
<li>foo
<ul class="contains-task-list">
<li class="task-list-item "><input class="task-list-item-checkbox" type="checkbox" disabled="" id="task-item-4" />nested unchecked item 1</li>
<li>not a todo item 2</li>
<li>not a todo item 3</li>
<li class="task-list-item "><input class="task-list-item-checkbox" type="checkbox" checked="" disabled="" id="task-item-7" />nested checked item 4</li>
</ul>
</li>
<li>bar</li>
<li>spam</li>
</ol>
<h1>Test 2</h1>
<ul>
<li>foo
<ul class="contains-task-list">
<li class="task-list-item "><input class="task-list-item-checkbox" type="checkbox" disabled="" id="task-item-14" />nested unchecked item 1</li>
<li class="task-list-item "><input class="task-list-item-checkbox" type="checkbox" disabled="" id="task-item-15" />nested unchecked item 2</li>
<li class="task-list-item "><input class="task-list-item-checkbox" type="checkbox" checked="" disabled="" id="task-item-16" />nested checked item 3</li>
<li class="task-list-item "><input class="task-list-item-checkbox" type="checkbox" checked="" disabled="" id="task-item-17" />nested checked item 4</li>
</ul>
</li>
</ul>
"
`;
exports[`markdown-it-task-lists > renders ordered correctly 1`] = `
"<ol class="contains-task-list">
<li class="task-list-item "><input class="task-list-item-checkbox" type="checkbox" checked="" disabled="" id="task-item-1" />checked ordered 1</li>
<li class="task-list-item "><input class="task-list-item-checkbox" type="checkbox" disabled="" id="task-item-2" />unchecked ordered 2</li>
<li class="task-list-item "><input class="task-list-item-checkbox" type="checkbox" checked="" disabled="" id="task-item-3" />checked ordered 3</li>
<li class="task-list-item "><input class="task-list-item-checkbox" type="checkbox" disabled="" id="task-item-4" />unchecked ordered 4</li>
</ol>
"
`;
exports[`markdown-it-task-lists renders bullet correctly 1`] = ` exports[`markdown-it-task-lists renders bullet correctly 1`] = `
"<ul class="contains-task-list"> "<ul class="contains-task-list">

View file

@ -6,7 +6,7 @@
import MarkdownIt from 'markdown-it/lib' import MarkdownIt from 'markdown-it/lib'
import { taskLists } from './index.js' import { taskLists } from './index.js'
import { describe, expect, it } from '@jest/globals' import { describe, expect, it } from 'vitest'
describe('markdown-it-task-lists', () => { describe('markdown-it-task-lists', () => {
it('renders bullet correctly', () => { it('renders bullet correctly', () => {

View file

@ -1,9 +1,93 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
/*
* SPDX-FileCopyrightText: Original: (c) 2018 Fabio Zendhi Nagao / Modifications: (c) 2022 The HedgeDoc developers (see AUTHORS file) exports[`toc > ignores the levels in the placeholder if not sorted 1`] = `
* "<nav class="table-of-contents"><ol><li><a href="#head-1">Head 1</a><ol><li><a href="#head-2">Head 2</a><ol><li><a href="#head-3">Head 3</a><ol><li><a href="#head-4">Head 4</a></li></ol></li></ol></li></ol></li></ol></nav><h1>Head 1</h1>
* SPDX-License-Identifier: MIT <h2>Head 2</h2>
*/ <h3>Head 3</h3>
<h4>Head 4</h4>
"
`;
exports[`toc > renders a toc with a level number array 1`] = `
"<nav class="table-of-contents"><ol><li><a href="#head-2">Head 2</a><ol><li><a href="#head-4">Head 4</a></li></ol></li></ol></nav><h1>Head 1</h1>
<h2>Head 2</h2>
<h3>Head 3</h3>
<h4>Head 4</h4>
"
`;
exports[`toc > renders a toc with a single level number 1`] = `
"<nav class="table-of-contents"><ol><li><a href="#head-2">Head 2</a><ol><li><a href="#head-3">Head 3</a></li></ol></li></ol></nav><h1>Head 1</h1>
<h2>Head 2</h2>
<h3>Head 3</h3>
"
`;
exports[`toc > renders a toc with custom allowed token types 1`] = `
"<nav class="table-of-contents"><ol><li><a href="#text"> text</a></li><li><a href="#head-2">Head 2</a></li></ol></nav><h1><code>Head 1</code> text</h1>
<h1>Head 2</h1>
"
`;
exports[`toc > renders a toc with custom classes 1`] = `
"<nav id="containerId" class="containerClass"><ol class="listClass"><li class="itemClass"><a class="linkClass" href="#head-1">Head 1</a><ol class="listClass"><li class="itemClass"><a class="linkClass" href="#heading-2">Heading 2</a><ol class="listClass"><li class="itemClass"><a class="linkClass" href="#heading-3">Heading 3</a></li></ol></li></ol></li></ol></nav><h1>Head 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
"
`;
exports[`toc > renders a toc with custom format function 1`] = `
"<nav class="table-of-contents"><ol><li><a href="#head-1">HEAD 1</a><ol><li><a href="#heading-2">HEADING 2</a><ol><li><a href="#heading-3">HEADING 3</a></li></ol></li></ol></li></ol></nav><h1>Head 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
"
`;
exports[`toc > renders a toc with custom slugify 1`] = `
"<nav class="table-of-contents"><ol><li><a href="#slug-Head 1-0">Head 1</a><ol><li><a href="#slug-Heading 2-0">Heading 2</a><ol><li><a href="#slug-Heading 3-0">Heading 3</a></li></ol></li></ol></li></ol></nav><h1>Head 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
"
`;
exports[`toc > renders a toc with custom unique slug start index 1`] = `
"<nav class="table-of-contents"><ol><li><a href="#head-1-10">Head 1</a><ol><li><a href="#heading-2-10">Heading 2</a><ol><li><a href="#heading-3-10">Heading 3</a></li></ol></li></ol></li></ol></nav><h1>Head 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
"
`;
exports[`toc > renders a toc with default settings 1`] = `
"<nav class="table-of-contents"><ol><li><a href="#head-1">Head 1</a><ol><li><a href="#heading-2">Heading 2</a><ol><li><a href="#heading-3">Heading 3</a></li></ol></li></ol></li><li><a href="#head-1-1">Head 1</a></li><li><a href="#head-1-2">Head 1</a></li><li><a href="#head-1-3">Head 1</a></li></ol></nav><h1>Head 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h1>Head 1</h1>
<h1>Head 1</h1>
<h1>Head 1</h1>
"
`;
exports[`toc > renders a toc with levels in the placeholder 1`] = `
"<nav class="table-of-contents"><ol><li><a href="#head-2">Head 2</a><ol><li><a href="#head-3">Head 3</a><ol></ol></li></ol></li></ol></nav><h1>Head 1</h1>
<h2>Head 2</h2>
<h3>Head 3</h3>
<h4>Head 4</h4>
"
`;
exports[`toc > renders a toc with ordered list 1`] = `
"<nav class="table-of-contents"><ol><li><a href="#head-1">Head 1</a><ol><li><a href="#heading-2">Heading 2</a><ol><li><a href="#heading-3">Heading 3</a></li></ol></li></ol></li></ol></nav><h1>Head 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
"
`;
exports[`toc > renders a toc with unordered list 1`] = `
"<nav class="table-of-contents"><ul><li><a href="#head-1">Head 1</a><ul><li><a href="#heading-2">Heading 2</a><ul><li><a href="#heading-3">Heading 3</a></li></ul></li></ul></li></ul></nav><h1>Head 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
"
`;
exports[`toc ignores the levels in the placeholder if not sorted 1`] = ` exports[`toc ignores the levels in the placeholder if not sorted 1`] = `
"<nav class="table-of-contents"><ol><li><a href="#head-1">Head 1</a><ol><li><a href="#head-2">Head 2</a><ol><li><a href="#head-3">Head 3</a><ol><li><a href="#head-4">Head 4</a></li></ol></li></ol></li></ol></li></ol></nav><h1>Head 1</h1> "<nav class="table-of-contents"><ol><li><a href="#head-1">Head 1</a><ol><li><a href="#head-2">Head 2</a><ol><li><a href="#head-3">Head 3</a><ol><li><a href="#head-4">Head 4</a></li></ol></li></ol></li></ol></li></ol></nav><h1>Head 1</h1>

View file

@ -6,7 +6,7 @@
import MarkdownIt from 'markdown-it/lib' import MarkdownIt from 'markdown-it/lib'
import { toc } from './plugin.js' import { toc } from './plugin.js'
import { describe, expect, it, jest } from '@jest/globals' import { describe, expect, it, vitest } from 'vitest'
describe('toc', () => { describe('toc', () => {
const simpleContent = ` const simpleContent = `
@ -143,7 +143,7 @@ describe('toc', () => {
}) })
it('renders a toc and executes the callback', () => { it('renders a toc and executes the callback', () => {
const callback = jest.fn() const callback = vitest.fn()
const markdownIt = new MarkdownIt().use(toc, { callback }) const markdownIt = new MarkdownIt().use(toc, { callback })
markdownIt.render(simpleContent) markdownIt.render(simpleContent)
expect(callback).toBeCalledWith({ expect(callback).toBeCalledWith({

View file

@ -3020,21 +3020,18 @@ __metadata:
version: 0.0.0-use.local version: 0.0.0-use.local
resolution: "@hedgedoc/markdown-it-plugins@workspace:markdown-it-plugins" resolution: "@hedgedoc/markdown-it-plugins@workspace:markdown-it-plugins"
dependencies: dependencies:
"@jest/types": "npm:29.6.3"
"@mrdrogdrog/optional": "npm:1.2.1" "@mrdrogdrog/optional": "npm:1.2.1"
"@types/markdown-it": "npm:13.0.8" "@types/markdown-it": "npm:13.0.8"
"@typescript-eslint/eslint-plugin": "npm:8.14.0" "@typescript-eslint/eslint-plugin": "npm:8.14.0"
"@typescript-eslint/parser": "npm:8.14.0" "@typescript-eslint/parser": "npm:8.14.0"
eslint: "npm:8.57.1" eslint: "npm:8.57.1"
eslint-config-prettier: "npm:9.1.0" eslint-config-prettier: "npm:9.1.0"
eslint-plugin-jest: "npm:28.9.0"
eslint-plugin-prettier: "npm:5.2.3" eslint-plugin-prettier: "npm:5.2.3"
html-entities: "npm:2.5.2" html-entities: "npm:2.5.2"
jest: "npm:29.7.0"
markdown-it: "npm:13.0.2" markdown-it: "npm:13.0.2"
prettier: "npm:3.3.3" prettier: "npm:3.3.3"
ts-jest: "npm:29.2.5"
typescript: "npm:5.6.3" typescript: "npm:5.6.3"
vitest: "npm:3.1.2"
peerDependencies: peerDependencies:
markdown-it: ">=12" markdown-it: ">=12"
languageName: unknown languageName: unknown