Skip to content

Commit b2e1e90

Browse files
authored
test: switch to vitest (#131)
1 parent 84bf999 commit b2e1e90

20 files changed

+559
-2777
lines changed

jest.config.js

-13
This file was deleted.

jest.setup.js

-1
This file was deleted.

package.json

+4-8
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,26 @@
1717
"prepublishOnly": "npx yarn build",
1818
"prettier:check": "prettier --list-different \"src/**/*.{ts,tsx}\"",
1919
"prettier:write": "prettier --write \"src/**/*.{ts,tsx}\"",
20-
"test": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest",
20+
"test": "vitest run",
2121
"prepare": "husky"
2222
},
2323
"bin": {
2424
"electron-docs-linter": "./dist/bin.js",
2525
"electron-docs-parser": "./dist/bin.js"
2626
},
2727
"files": [
28-
"dist",
29-
"!dist/__tests__"
28+
"dist"
3029
],
3130
"devDependencies": {
3231
"@types/chai": "^4.3.19",
33-
"@types/jest": "^29.5.13",
3432
"@types/lodash.camelcase": "^4.3.9",
3533
"@types/node": "^22.5.5",
3634
"@types/pretty-ms": "^5.0.1",
37-
"cross-env": "^7.0.3",
3835
"husky": "^9.1.6",
39-
"jest": "^30.0.0-alpha.6",
4036
"lint-staged": "^15.2.10",
4137
"prettier": "^3.3.3",
42-
"ts-jest": "^29.2.5",
43-
"typescript": "^5.6.2"
38+
"typescript": "^5.6.2",
39+
"vitest": "^3.0.4"
4440
},
4541
"dependencies": {
4642
"@types/markdown-it": "^14.1.2",

src/__tests__/__snapshots__/markdown-helpers.spec.ts.snap tests/__snapshots__/markdown-helpers.spec.ts.snap

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`markdown-helpers rawTypeToTypeInformation() should allow commas in object types 1`] = `
3+
exports[`markdown-helpers > rawTypeToTypeInformation() > should allow commas in object types 1`] = `
44
{
55
"collection": false,
66
"parameters": [],
@@ -12,7 +12,7 @@ exports[`markdown-helpers rawTypeToTypeInformation() should allow commas in obje
1212
}
1313
`;
1414

15-
exports[`markdown-helpers rawTypeToTypeInformation() should map a Promise types correctly 1`] = `
15+
exports[`markdown-helpers > rawTypeToTypeInformation() > should map a Promise types correctly 1`] = `
1616
{
1717
"collection": false,
1818
"innerTypes": [
@@ -25,7 +25,7 @@ exports[`markdown-helpers rawTypeToTypeInformation() should map a Promise types
2525
}
2626
`;
2727

28-
exports[`markdown-helpers rawTypeToTypeInformation() should map a complex Promise types correctly 1`] = `
28+
exports[`markdown-helpers > rawTypeToTypeInformation() > should map a complex Promise types correctly 1`] = `
2929
{
3030
"collection": false,
3131
"innerTypes": [
@@ -47,7 +47,7 @@ exports[`markdown-helpers rawTypeToTypeInformation() should map a complex Promis
4747
}
4848
`;
4949

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

71-
exports[`markdown-helpers rawTypeToTypeInformation() should map a function return type correctly 1`] = `
71+
exports[`markdown-helpers > rawTypeToTypeInformation() > should map a function return type correctly 1`] = `
7272
{
7373
"collection": false,
7474
"parameters": [],
@@ -80,7 +80,7 @@ exports[`markdown-helpers rawTypeToTypeInformation() should map a function retur
8080
}
8181
`;
8282

83-
exports[`markdown-helpers rawTypeToTypeInformation() should map a function with complex return type + complex param types correctly 1`] = `
83+
exports[`markdown-helpers > rawTypeToTypeInformation() > should map a function with complex return type + complex param types correctly 1`] = `
8484
{
8585
"collection": false,
8686
"parameters": [
@@ -142,7 +142,7 @@ exports[`markdown-helpers rawTypeToTypeInformation() should map a function with
142142
}
143143
`;
144144

145-
exports[`markdown-helpers rawTypeToTypeInformation() should map a nested Function types correctly 1`] = `
145+
exports[`markdown-helpers > rawTypeToTypeInformation() > should map a nested Function types correctly 1`] = `
146146
{
147147
"collection": false,
148148
"innerTypes": [
@@ -169,7 +169,7 @@ exports[`markdown-helpers rawTypeToTypeInformation() should map a nested Functio
169169
}
170170
`;
171171

172-
exports[`markdown-helpers rawTypeToTypeInformation() should map a nested Promise types correctly 1`] = `
172+
exports[`markdown-helpers > rawTypeToTypeInformation() > should map a nested Promise types correctly 1`] = `
173173
{
174174
"collection": false,
175175
"innerTypes": [
@@ -197,7 +197,7 @@ exports[`markdown-helpers rawTypeToTypeInformation() should map a nested Promise
197197
}
198198
`;
199199

200-
exports[`markdown-helpers rawTypeToTypeInformation() should map a nested complex Promise types correctly 1`] = `
200+
exports[`markdown-helpers > rawTypeToTypeInformation() > should map a nested complex Promise types correctly 1`] = `
201201
{
202202
"collection": false,
203203
"innerTypes": [
@@ -225,7 +225,7 @@ exports[`markdown-helpers rawTypeToTypeInformation() should map a nested complex
225225
}
226226
`;
227227

228-
exports[`markdown-helpers rawTypeToTypeInformation() should map a nested complex Promise types correctly 2`] = `
228+
exports[`markdown-helpers > rawTypeToTypeInformation() > should map a nested complex Promise types correctly 2`] = `
229229
{
230230
"collection": false,
231231
"innerTypes": [
@@ -253,14 +253,14 @@ exports[`markdown-helpers rawTypeToTypeInformation() should map a nested complex
253253
}
254254
`;
255255

256-
exports[`markdown-helpers rawTypeToTypeInformation() should map a primitive types correctly 1`] = `
256+
exports[`markdown-helpers > rawTypeToTypeInformation() > should map a primitive types correctly 1`] = `
257257
{
258258
"collection": false,
259259
"type": "Boolean",
260260
}
261261
`;
262262

263-
exports[`markdown-helpers rawTypeToTypeInformation() should map a wrapped collection type correctly 1`] = `
263+
exports[`markdown-helpers > rawTypeToTypeInformation() > should map a wrapped collection type correctly 1`] = `
264264
{
265265
"collection": false,
266266
"innerTypes": [
@@ -287,24 +287,24 @@ exports[`markdown-helpers rawTypeToTypeInformation() should map a wrapped collec
287287
}
288288
`;
289289

290-
exports[`markdown-helpers rawTypeToTypeInformation() should map an unknown types correctly 1`] = `
290+
exports[`markdown-helpers > rawTypeToTypeInformation() > should map an unknown types correctly 1`] = `
291291
{
292292
"collection": false,
293293
"type": "MyType",
294294
}
295295
`;
296296

297-
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."`;
297+
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."`;
298298

299-
exports[`markdown-helpers safelyJoinTokens snapshots should be correct for blockquotes 1`] = `
299+
exports[`markdown-helpers > safelyJoinTokens > snapshots > should be correct for blockquotes 1`] = `
300300
"This is a paragraph
301301
302302
> and here is a quote
303303
304304
and another paragraph"
305305
`;
306306

307-
exports[`markdown-helpers safelyJoinTokens snapshots should be correct for list-after-paragraph 1`] = `
307+
exports[`markdown-helpers > safelyJoinTokens > snapshots > should be correct for list-after-paragraph 1`] = `
308308
"This is a paragraph
309309
310310
* this
@@ -313,20 +313,20 @@ exports[`markdown-helpers safelyJoinTokens snapshots should be correct for list-
313313
* list"
314314
`;
315315

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

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

329-
exports[`markdown-helpers safelyJoinTokens snapshots should be correct for nested-list 1`] = `
329+
exports[`markdown-helpers > safelyJoinTokens > snapshots > should be correct for nested-list 1`] = `
330330
"* top level
331331
* second level
332332
* back to top
@@ -335,13 +335,13 @@ exports[`markdown-helpers safelyJoinTokens snapshots should be correct for neste
335335
* now at third"
336336
`;
337337

338-
exports[`markdown-helpers safelyJoinTokens snapshots should be correct for paragraph-fence-removal 1`] = `
338+
exports[`markdown-helpers > safelyJoinTokens > snapshots > should be correct for paragraph-fence-removal 1`] = `
339339
"This fence should be removed
340340
341341
Hey"
342342
`;
343343

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

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

357-
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."`;
357+
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."`;
358358

359-
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~~"`;
359+
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~~"`;
360360

361-
exports[`markdown-helpers safelyJoinTokens with code fence support should correctly insert the code fence 1`] = `
361+
exports[`markdown-helpers > safelyJoinTokens > with code fence support > should correctly insert the code fence 1`] = `
362362
"> a
363363
364364
\`\`\`

src/__tests__/block-parsers.spec.ts tests/block-parsers.spec.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import MarkdownIt from 'markdown-it';
2-
import { parseMethodBlocks } from '../block-parsers';
2+
import { describe, expect, it } from 'vitest';
3+
4+
import { parseMethodBlocks } from '../src/block-parsers';
35

46
describe('block parsers', () => {
57
it('should parse a method', async () => {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/__tests__/helpers.spec.ts tests/helpers.spec.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { extendError } from '../helpers';
1+
import { extendError } from '../src/helpers';
2+
23
import chalk from 'chalk';
4+
import { describe, expect, it } from 'vitest';
35

46
describe('extendError', () => {
57
it('should extend the error message with the provided prefix', () => {

src/__tests__/markdown-helpers.spec.ts tests/markdown-helpers.spec.ts

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
33
import MarkdownIt from 'markdown-it';
4+
import { describe, expect, it } from 'vitest';
45

56
import {
67
safelyJoinTokens,
@@ -14,8 +15,8 @@ import {
1415
consumeTypedKeysList,
1516
findProcess,
1617
slugifyHeading,
17-
} from '../markdown-helpers';
18-
import { DocumentationTag } from '../ParsedDocumentation';
18+
} from '../src/markdown-helpers';
19+
import { DocumentationTag } from '../src/ParsedDocumentation';
1920

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

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

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

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

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

@@ -608,9 +609,9 @@ foo`),
608609
`Returns \`WebContents\` | \`string\` - A WebContents instance with the given ID.`,
609610
);
610611
expect(() => extractReturnType(customTokens)).toThrowErrorMatchingInlineSnapshot(`
611-
"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\`.
612+
[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\`.
612613
Specifically this error was encountered here:
613-
"Returns \`WebContents\` | \`string\` - A WebContents instance with the given ID."..."
614+
"Returns \`WebContents\` | \`string\` - A WebContents instance with the given ID."...]
614615
`);
615616
});
616617

@@ -664,7 +665,7 @@ foo`),
664665
};
665666
consumeTypedKeysList(list);
666667
expect(() => consumeTypedKeysList(list)).toThrowErrorMatchingInlineSnapshot(
667-
`"Attempted to consume a typed keys list that has already been consumed"`,
668+
`[Error: Attempted to consume a typed keys list that has already been consumed]`,
668669
);
669670
});
670671
});

tsconfig.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
"es7"
1010
],
1111
"types": [
12-
"node",
13-
"jest"
12+
"node"
1413
],
1514
"declaration": true,
1615
"sourceMap": true,
@@ -19,5 +18,8 @@
1918
"strict": true,
2019
"esModuleInterop": true,
2120
"incremental": true
22-
}
21+
},
22+
"include": [
23+
"src"
24+
]
2325
}

0 commit comments

Comments
 (0)