Skip to content

Commit 1a67a91

Browse files
feat: use vitest
1 parent a795768 commit 1a67a91

16 files changed

+383
-1484
lines changed

__tests__/file.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/* eslint-disable no-magic-numbers */
2+
import { describe, expect, it, vi } from 'vitest';
23
import {resolve} from 'path';
34
import {findMarkdownFiles} from '../src';
45

56
describe('findMarkdownFiles', () => {
67
it('should find markdown files', () => {
7-
const mockLog = jest.spyOn(console, 'log').mockImplementation(() => ({}));
8+
const mockLog = vi.spyOn(console, 'log').mockImplementation(() => ({}));
89
expect(findMarkdownFiles(resolve(__dirname, 'fixtures')).map(info => ({
910
name: info.name,
1011
path: info.path,

__tests__/params.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable no-magic-numbers */
2+
import { describe, expect, it } from 'vitest';
23
import {extractParams, getStartSection, getParamsSection} from '../src/lib/params';
34
import {CLOSING_COMMENT, OPENING_COMMENT} from '../src';
45

__tests__/transform-custom-mode.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable no-magic-numbers */
2+
import { describe, expect, it } from 'vitest';
23
import {resolve} from 'path';
34
import {readFileSync} from 'fs';
45
import {transform} from '../src';

__tests__/transform-footer.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable no-magic-numbers */
2+
import { describe, expect, it } from 'vitest';
23
import {resolve} from 'path';
34
import {readFileSync} from 'fs';
45
import {transform} from '../src';

__tests__/transform-html.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable no-magic-numbers */
2+
import { describe, expect, it } from 'vitest';
23
import {resolve} from 'path';
34
import {readFileSync} from 'fs';
45
import {transform} from '../src';

__tests__/transform-nested-markdown.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable no-magic-numbers */
2+
import { describe, expect, it } from 'vitest';
23
import {resolve} from 'path';
34
import {readFileSync} from 'fs';
45
import {transform} from '../src';

__tests__/transform-not-transformed.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable no-magic-numbers */
2+
import { describe, expect, it } from 'vitest';
23
import {resolve} from 'path';
34
import {readFileSync} from 'fs';
45
import {transform} from '../src';

__tests__/transform-override-params.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable no-magic-numbers */
2+
import { describe, expect, it } from 'vitest';
23
import {resolve} from 'path';
34
import {readFileSync} from 'fs';
45
import {transform} from '../src';

__tests__/transform-title.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable no-magic-numbers */
2+
import { describe, expect, it } from 'vitest';
23
import {resolve} from 'path';
34
import {readFileSync} from 'fs';
45
import {transform} from '../src';

__tests__/transform-weird-headers.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable no-magic-numbers */
2+
import { describe, expect, it } from 'vitest';
23
import {resolve} from 'path';
34
import {readFileSync} from 'fs';
45
import {transform} from '../src';

__tests__/transform.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable no-magic-numbers */
2+
import { describe, expect, it } from 'vitest';
23
import {transform} from '../src';
34
import {getLinesToToc, matchesStart, matchesEnd} from '../src/lib/transform';
45
import {OPENING_COMMENT, CLOSING_COMMENT} from '../src';

__tests__/utils.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable no-magic-numbers */
2+
import { describe, expect, it } from 'vitest';
23
import {replaceVariables} from '../src/lib/utils';
34

45
describe('replaceVariables', () => {

jest.config.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

package.json

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
],
3737
"scripts": {
3838
"build": "rm -rf ./build && tsc",
39-
"cover": "jest --coverage",
39+
"cover": "vitest run --coverage",
4040
"lint": "eslint 'src/**/*.ts' '__tests__/**/*.ts' --cache",
4141
"lint:fix": "eslint --fix 'src/**/*.ts' '__tests__/**/*.ts'",
4242
"test": "yarn lint && yarn cover",
43-
"update": "npx npm-check-updates -u && yarn install && yarn upgrade && yarn audit"
43+
"update": "npm_config_yes=true npx npm-check-updates -u --timeout 100000 && yarn install && yarn upgrade && yarn audit"
4444
},
4545
"dependencies": {
4646
"@technote-space/anchor-markdown-header": "^1.1.36",
@@ -52,17 +52,15 @@
5252
"@commitlint/cli": "^17.0.2",
5353
"@commitlint/config-conventional": "^17.0.2",
5454
"@textlint/ast-node-types": "^12.1.1",
55-
"@types/jest": "^28.1.2",
5655
"@types/node": "^18.0.0",
57-
"@typescript-eslint/eslint-plugin": "^5.28.0",
58-
"@typescript-eslint/parser": "^5.28.0",
56+
"@typescript-eslint/eslint-plugin": "^5.29.0",
57+
"@typescript-eslint/parser": "^5.29.0",
58+
"c8": "^7.11.3",
5959
"eslint": "^8.18.0",
6060
"husky": "^8.0.1",
61-
"jest": "^28.1.1",
62-
"jest-circus": "^28.1.1",
6361
"lint-staged": "^13.0.2",
64-
"ts-jest": "^28.0.5",
65-
"typescript": "^4.7.4"
62+
"typescript": "^4.7.4",
63+
"vitest": "^0.15.2"
6664
},
6765
"publishConfig": {
6866
"access": "public"

vite.config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference types="vitest" />
2+
import { defineConfig } from 'vite';
3+
4+
// https://vitejs.dev/config/
5+
export default defineConfig({
6+
test: {
7+
clearMocks: true,
8+
mockReset: true,
9+
restoreMocks: true,
10+
coverage: {
11+
reporter: ['html', 'lcov', 'text'],
12+
},
13+
},
14+
});

0 commit comments

Comments
 (0)