Skip to content

Commit

Permalink
test: switch to vitest (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanders11 authored Feb 2, 2025
1 parent 84bf999 commit b2e1e90
Show file tree
Hide file tree
Showing 20 changed files with 559 additions and 2,777 deletions.
13 changes: 0 additions & 13 deletions jest.config.js

This file was deleted.

1 change: 0 additions & 1 deletion jest.setup.js

This file was deleted.

12 changes: 4 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,26 @@
"prepublishOnly": "npx yarn build",
"prettier:check": "prettier --list-different \"src/**/*.{ts,tsx}\"",
"prettier:write": "prettier --write \"src/**/*.{ts,tsx}\"",
"test": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest",
"test": "vitest run",
"prepare": "husky"
},
"bin": {
"electron-docs-linter": "./dist/bin.js",
"electron-docs-parser": "./dist/bin.js"
},
"files": [
"dist",
"!dist/__tests__"
"dist"
],
"devDependencies": {
"@types/chai": "^4.3.19",
"@types/jest": "^29.5.13",
"@types/lodash.camelcase": "^4.3.9",
"@types/node": "^22.5.5",
"@types/pretty-ms": "^5.0.1",
"cross-env": "^7.0.3",
"husky": "^9.1.6",
"jest": "^30.0.0-alpha.6",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"ts-jest": "^29.2.5",
"typescript": "^5.6.2"
"typescript": "^5.6.2",
"vitest": "^3.0.4"
},
"dependencies": {
"@types/markdown-it": "^14.1.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`markdown-helpers rawTypeToTypeInformation() should allow commas in object types 1`] = `
exports[`markdown-helpers > rawTypeToTypeInformation() > should allow commas in object types 1`] = `
{
"collection": false,
"parameters": [],
Expand All @@ -12,7 +12,7 @@ exports[`markdown-helpers rawTypeToTypeInformation() should allow commas in obje
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map a Promise types correctly 1`] = `
exports[`markdown-helpers > rawTypeToTypeInformation() > should map a Promise types correctly 1`] = `
{
"collection": false,
"innerTypes": [
Expand All @@ -25,7 +25,7 @@ exports[`markdown-helpers rawTypeToTypeInformation() should map a Promise types
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map a complex Promise types correctly 1`] = `
exports[`markdown-helpers > rawTypeToTypeInformation() > should map a complex Promise types correctly 1`] = `
{
"collection": false,
"innerTypes": [
Expand All @@ -47,7 +47,7 @@ exports[`markdown-helpers rawTypeToTypeInformation() should map a complex Promis
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map a function return type + param types correctly 1`] = `
exports[`markdown-helpers > rawTypeToTypeInformation() > should map a function return type + param types correctly 1`] = `
{
"collection": false,
"parameters": [
Expand All @@ -68,7 +68,7 @@ exports[`markdown-helpers rawTypeToTypeInformation() should map a function retur
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map a function return type correctly 1`] = `
exports[`markdown-helpers > rawTypeToTypeInformation() > should map a function return type correctly 1`] = `
{
"collection": false,
"parameters": [],
Expand All @@ -80,7 +80,7 @@ exports[`markdown-helpers rawTypeToTypeInformation() should map a function retur
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map a function with complex return type + complex param types correctly 1`] = `
exports[`markdown-helpers > rawTypeToTypeInformation() > should map a function with complex return type + complex param types correctly 1`] = `
{
"collection": false,
"parameters": [
Expand Down Expand Up @@ -142,7 +142,7 @@ exports[`markdown-helpers rawTypeToTypeInformation() should map a function with
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map a nested Function types correctly 1`] = `
exports[`markdown-helpers > rawTypeToTypeInformation() > should map a nested Function types correctly 1`] = `
{
"collection": false,
"innerTypes": [
Expand All @@ -169,7 +169,7 @@ exports[`markdown-helpers rawTypeToTypeInformation() should map a nested Functio
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map a nested Promise types correctly 1`] = `
exports[`markdown-helpers > rawTypeToTypeInformation() > should map a nested Promise types correctly 1`] = `
{
"collection": false,
"innerTypes": [
Expand Down Expand Up @@ -197,7 +197,7 @@ exports[`markdown-helpers rawTypeToTypeInformation() should map a nested Promise
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map a nested complex Promise types correctly 1`] = `
exports[`markdown-helpers > rawTypeToTypeInformation() > should map a nested complex Promise types correctly 1`] = `
{
"collection": false,
"innerTypes": [
Expand Down Expand Up @@ -225,7 +225,7 @@ exports[`markdown-helpers rawTypeToTypeInformation() should map a nested complex
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map a nested complex Promise types correctly 2`] = `
exports[`markdown-helpers > rawTypeToTypeInformation() > should map a nested complex Promise types correctly 2`] = `
{
"collection": false,
"innerTypes": [
Expand Down Expand Up @@ -253,14 +253,14 @@ exports[`markdown-helpers rawTypeToTypeInformation() should map a nested complex
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map a primitive types correctly 1`] = `
exports[`markdown-helpers > rawTypeToTypeInformation() > should map a primitive types correctly 1`] = `
{
"collection": false,
"type": "Boolean",
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map a wrapped collection type correctly 1`] = `
exports[`markdown-helpers > rawTypeToTypeInformation() > should map a wrapped collection type correctly 1`] = `
{
"collection": false,
"innerTypes": [
Expand All @@ -287,24 +287,24 @@ exports[`markdown-helpers rawTypeToTypeInformation() should map a wrapped collec
}
`;

exports[`markdown-helpers rawTypeToTypeInformation() should map an unknown types correctly 1`] = `
exports[`markdown-helpers > rawTypeToTypeInformation() > should map an unknown types correctly 1`] = `
{
"collection": false,
"type": "MyType",
}
`;

exports[`markdown-helpers safelyJoinTokens snapshots should be correct for basic-paragraph 1`] = `"This is just a basic paragraph. It has multiple sentences and natural soft breaks."`;
exports[`markdown-helpers > safelyJoinTokens > snapshots > should be correct for basic-paragraph 1`] = `"This is just a basic paragraph. It has multiple sentences and natural soft breaks."`;

exports[`markdown-helpers safelyJoinTokens snapshots should be correct for blockquotes 1`] = `
exports[`markdown-helpers > safelyJoinTokens > snapshots > should be correct for blockquotes 1`] = `
"This is a paragraph
> and here is a quote
and another paragraph"
`;

exports[`markdown-helpers safelyJoinTokens snapshots should be correct for list-after-paragraph 1`] = `
exports[`markdown-helpers > safelyJoinTokens > snapshots > should be correct for list-after-paragraph 1`] = `
"This is a paragraph
* this
Expand All @@ -313,20 +313,20 @@ exports[`markdown-helpers safelyJoinTokens snapshots should be correct for list-
* list"
`;

exports[`markdown-helpers safelyJoinTokens snapshots should be correct for lists 1`] = `
exports[`markdown-helpers > safelyJoinTokens > snapshots > should be correct for lists 1`] = `
"* bar
* thing
* stuff
* my tab key does not work and I am sad"
`;

exports[`markdown-helpers safelyJoinTokens snapshots should be correct for multiple-paragraphs 1`] = `
exports[`markdown-helpers > safelyJoinTokens > snapshots > should be correct for multiple-paragraphs 1`] = `
"This is paragraph 1, it has a few sentences. Like this one, and a soft break.
And now this is a second paragraph, and it's also quite short with a soft break."
`;

exports[`markdown-helpers safelyJoinTokens snapshots should be correct for nested-list 1`] = `
exports[`markdown-helpers > safelyJoinTokens > snapshots > should be correct for nested-list 1`] = `
"* top level
* second level
* back to top
Expand All @@ -335,13 +335,13 @@ exports[`markdown-helpers safelyJoinTokens snapshots should be correct for neste
* now at third"
`;

exports[`markdown-helpers safelyJoinTokens snapshots should be correct for paragraph-fence-removal 1`] = `
exports[`markdown-helpers > safelyJoinTokens > snapshots > should be correct for paragraph-fence-removal 1`] = `
"This fence should be removed
Hey"
`;

exports[`markdown-helpers safelyJoinTokens snapshots should be correct for paragraph-with-br-tag 1`] = `
exports[`markdown-helpers > safelyJoinTokens > snapshots > should be correct for paragraph-with-br-tag 1`] = `
"Process: Main
_This class is not exported from the \`'electron'\` module. It is only available as a return value of other methods in the Electron API._
Expand All @@ -352,13 +352,13 @@ Process: Main
_This class is not exported from the \`'electron'\` module. It is only available as a return value of other methods in the Electron API._"
`;

exports[`markdown-helpers safelyJoinTokens snapshots should be correct for paragraph-with-inline-code 1`] = `"This is a \`inline code\` block that is \`code\` tagged."`;
exports[`markdown-helpers > safelyJoinTokens > snapshots > should be correct for paragraph-with-inline-code 1`] = `"This is a \`inline code\` block that is \`code\` tagged."`;

exports[`markdown-helpers safelyJoinTokens snapshots should be correct for paragraph-with-links 1`] = `"This paragraph has a bunch of stuff. Also some links Foo, these links should be stripped."`;
exports[`markdown-helpers > safelyJoinTokens > snapshots > should be correct for paragraph-with-links 1`] = `"This paragraph has a bunch of stuff. Also some links Foo, these links should be stripped."`;

exports[`markdown-helpers safelyJoinTokens snapshots should be correct for paragraph-with-text-markers 1`] = `"Heya, this is **bold** and _italic_ and *italic* and ~~struck through~~"`;
exports[`markdown-helpers > safelyJoinTokens > snapshots > should be correct for paragraph-with-text-markers 1`] = `"Heya, this is **bold** and _italic_ and *italic* and ~~struck through~~"`;

exports[`markdown-helpers safelyJoinTokens with code fence support should correctly insert the code fence 1`] = `
exports[`markdown-helpers > safelyJoinTokens > with code fence support > should correctly insert the code fence 1`] = `
"> a
\`\`\`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import MarkdownIt from 'markdown-it';
import { parseMethodBlocks } from '../block-parsers';
import { describe, expect, it } from 'vitest';

import { parseMethodBlocks } from '../src/block-parsers';

describe('block parsers', () => {
it('should parse a method', async () => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion src/__tests__/helpers.spec.ts → tests/helpers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { extendError } from '../helpers';
import { extendError } from '../src/helpers';

import chalk from 'chalk';
import { describe, expect, it } from 'vitest';

describe('extendError', () => {
it('should extend the error message with the provided prefix', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from 'fs';
import * as path from 'path';
import MarkdownIt from 'markdown-it';
import { describe, expect, it } from 'vitest';

import {
safelyJoinTokens,
Expand All @@ -14,8 +15,8 @@ import {
consumeTypedKeysList,
findProcess,
slugifyHeading,
} from '../markdown-helpers';
import { DocumentationTag } from '../ParsedDocumentation';
} from '../src/markdown-helpers';
import { DocumentationTag } from '../src/ParsedDocumentation';

const getTokens = (md: string) => {
const markdown = new MarkdownIt({ html: true });
Expand Down Expand Up @@ -46,7 +47,7 @@ describe('markdown-helpers', () => {

it('should throw an error if there is a tag not on the allowlist', () => {
expect(() => parseHeadingTags(' _Awesome_')).toThrowErrorMatchingInlineSnapshot(
`"heading tags must be from the allowlist: ["macOS","mas","Windows","Linux","Experimental","Deprecated","Readonly"]: expected [ 'macOS', 'mas', 'Windows', …(4) ] to include 'Awesome'"`,
`[AssertionError: heading tags must be from the allowlist: ["macOS","mas","Windows","Linux","Experimental","Deprecated","Readonly"]: expected [ 'macOS', 'mas', 'Windows', …(4) ] to include 'Awesome']`,
);
});
});
Expand Down Expand Up @@ -107,16 +108,16 @@ def fn():
it('should error helpfully on invalid value separators', () => {
expect(() => extractStringEnum('Can be `x` sometimes `y'))
.toThrowErrorMatchingInlineSnapshot(`
"Unexpected separator token while extracting string enum, expected a comma or "and" or "or" but found "s"
Context: \`x\` sometimes \`y
^"
`);
[Error: Unexpected separator token while extracting string enum, expected a comma or "and" or "or" but found "s"
Context: \`x\` sometimes \`y
^]
`);
});

it('should error helpfully on unterminated enum strings', () => {
expect(() => extractStringEnum('Can be `x` or `y')).toThrowErrorMatchingInlineSnapshot(`
"Unexpected early termination of token sequence while extracting string enum, did you forget to close a quote?
Context: \`x\` or \`y"
[Error: Unexpected early termination of token sequence while extracting string enum, did you forget to close a quote?
Context: \`x\` or \`y]
`);
});

Expand Down Expand Up @@ -509,7 +510,7 @@ hey lol
describe('findFirstHeading()', () => {
it('should throw if there is no heading', () => {
expect(() => findFirstHeading(getTokens('`abc`'))).toThrowErrorMatchingInlineSnapshot(
`"expected to find a heading token but couldn't: expected -1 to not equal -1"`,
`[AssertionError: expected to find a heading token but couldn't: expected -1 to not equal -1]`,
);
});

Expand All @@ -518,7 +519,7 @@ hey lol
expect(() =>
findFirstHeading(tokens.slice(0, tokens.length - 2)),
).toThrowErrorMatchingInlineSnapshot(
`"expected [ Array(1) ] to have a length at least 2 but got 1"`,
`[AssertionError: expected [ Array(1) ] to have a length at least 2 but got 1]`,
);
});

Expand Down Expand Up @@ -608,9 +609,9 @@ foo`),
`Returns \`WebContents\` | \`string\` - A WebContents instance with the given ID.`,
);
expect(() => extractReturnType(customTokens)).toThrowErrorMatchingInlineSnapshot(`
"Found a return type declaration that appears to be declaring a type union (A | B) but in the incorrect format. Type unions must be fully enclosed in backticks. For instance, instead of \`A\` | \`B\` you should specify \`A | B\`.
[Error: Found a return type declaration that appears to be declaring a type union (A | B) but in the incorrect format. Type unions must be fully enclosed in backticks. For instance, instead of \`A\` | \`B\` you should specify \`A | B\`.
Specifically this error was encountered here:
"Returns \`WebContents\` | \`string\` - A WebContents instance with the given ID."..."
"Returns \`WebContents\` | \`string\` - A WebContents instance with the given ID."...]
`);
});

Expand Down Expand Up @@ -664,7 +665,7 @@ foo`),
};
consumeTypedKeysList(list);
expect(() => consumeTypedKeysList(list)).toThrowErrorMatchingInlineSnapshot(
`"Attempted to consume a typed keys list that has already been consumed"`,
`[Error: Attempted to consume a typed keys list that has already been consumed]`,
);
});
});
Expand Down
8 changes: 5 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"es7"
],
"types": [
"node",
"jest"
"node"
],
"declaration": true,
"sourceMap": true,
Expand All @@ -19,5 +18,8 @@
"strict": true,
"esModuleInterop": true,
"incremental": true
}
},
"include": [
"src"
]
}
Loading

0 comments on commit b2e1e90

Please sign in to comment.