Skip to content

Commit d0cb134

Browse files
authored
Merge pull request #37 from jmespath-community/chore-migrate-to-vitest
chore: migrate from Jest to vitest
2 parents 02604a6 + 4f69e60 commit d0cb134

11 files changed

+2265
-3445
lines changed

package-lock.json

Lines changed: 2198 additions & 3422 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@
4343
"build": "npx tsc --outDir dist/lib -d --module commonjs && npx rollup -c rollup.config.ts",
4444
"perf": "node --expose-gc scripts/perf.js",
4545
"start": "npx rollup -c rollup.config.ts -w",
46-
"test": "npx jest --coverage",
47-
"test:watch": "npx jest --coverage --watch",
48-
"test:prod": "npm run lint && npm run test -- --no-cache",
46+
"test": "vitest --run",
47+
"test:watch": "vitest",
48+
"test:prod": "npm run lint && npm run test",
49+
"coverage": "vitest run --coverage",
4950
"deploy-docs": "ts-node scripts/gh-pages-publish",
5051
"report-coverage": "cat ./coverage/lcov.info | coveralls",
5152
"precommit": "lint-staged",
@@ -56,7 +57,6 @@
5657
"@rollup/plugin-node-resolve": "^13.0.0",
5758
"@rollup/plugin-terser": "^0.4.0",
5859
"@rollup/plugin-typescript": "^8.2.1",
59-
"@types/jest": "^29.4.0",
6060
"@typescript-eslint/eslint-plugin": "^4.26.0",
6161
"@typescript-eslint/parser": "^4.26.0",
6262
"clean-publish": "^3.4.5",
@@ -65,9 +65,6 @@
6565
"eslint-config-prettier": "^8.6.0",
6666
"eslint-plugin-prettier": "^3.4.1",
6767
"husky": "^6.0.0",
68-
"jest": "^29.5.0",
69-
"jest-cli": "^29.5.0",
70-
"jest-config": "^29.5.0",
7168
"lint-staged": "^11.0.0",
7269
"prettier": "^2.3.0",
7370
"prettier-eslint": "^12.0.0",
@@ -76,8 +73,8 @@
7673
"rollup-plugin-typescript2": "^0.34.1",
7774
"shelljs": "^0.8.4",
7875
"tinybench": "^2.5.1",
79-
"ts-jest": "^29.0.5",
8076
"ts-node": "^10.9.1",
81-
"typescript": "^4.3.2"
77+
"typescript": "^4.3.2",
78+
"vitest": "^2.1.8"
8279
}
8380
}

test/compliance.spec.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
import { describe, expect, test } from 'vitest';
12
import { readdirSync, readFileSync } from 'fs';
23
import { basename } from 'path';
34
import { Options, search } from '../src';
45
import { JSONValue } from '../src/JSON.type';
56
import { expectError } from './error.utils';
67

7-
export type ComplianceTestCaseDefinition = { expression: string; result?: JSONValue; error?: string };
8-
export type ComplianceTestCase = { given: JSONValue; cases: ComplianceTestCaseDefinition[] };
8+
export type ComplianceTestCaseDefinition = {
9+
expression: string;
10+
result?: JSONValue;
11+
error?: string;
12+
};
13+
export type ComplianceTestCase = {
14+
given: JSONValue;
15+
cases: ComplianceTestCaseDefinition[];
16+
};
917
export type ComplianceTestSuite = ComplianceTestCase[];
1018

1119
// Compliance tests that aren't supported yet.

test/error.utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { expect } from 'vitest';
12
import { JSONValue } from '../src/JSON.type';
23

34
export function expectError(action: () => JSONValue, expected: string | string[]): void {

test/jmespath-extensions.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, expect } from 'vitest';
12
import jmespath, { search, registerFunction } from '../src';
23
import { JSONObject } from '../src/JSON.type';
34

@@ -155,7 +156,11 @@ describe('registerFunction', () => {
155156
registerFunction(
156157
'optionalArgs',
157158
([first, second, third]) => {
158-
return { first, second: second ?? 'default[2]', third: third ?? 'default[3]' };
159+
return {
160+
first,
161+
second: second ?? 'default[2]',
162+
third: third ?? 'default[3]',
163+
};
159164
},
160165
[{ types: [jmespath.TYPE_ANY] }, { types: [jmespath.TYPE_ANY], optional: true }],
161166
);

test/jmespath-functions.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, expect } from 'vitest';
12
import { search, registerFunction, TYPE_NUMBER } from '../src';
23
import { expectError } from './error.utils';
34

@@ -130,12 +131,13 @@ describe('custom functions', () => {
130131
it('must be in scope for let expression', () => {
131132
registerFunction(
132133
'plusplus', // FUNCTION NAME
133-
(resolvedArgs) => { // CUSTOM FUNCTION
134+
resolvedArgs => {
135+
// CUSTOM FUNCTION
134136
const [num] = resolvedArgs;
135137
return num + 1;
136138
},
137-
[{ types: [TYPE_NUMBER] }] //SIGNATURE
139+
[{ types: [TYPE_NUMBER] }], //SIGNATURE
138140
);
139-
expect(search({index: 0}, 'let $n = index in plusplus($n)')).toEqual(1);
141+
expect(search({ index: 0 }, 'let $n = index in plusplus($n)')).toEqual(1);
140142
});
141-
});
143+
});

test/jmespath-interpreter.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, expect } from 'vitest';
12
import { search } from '../src';
23

34
describe('Searches compiled ast', () => {

test/jmespath-lexer.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, expect } from 'vitest';
12
import { tokenize } from '../src';
23

34
describe('tokenize', () => {
@@ -83,7 +84,7 @@ describe('tokenize', () => {
8384
expect(tokenize('`true`')).toMatchObject([{ type: 'Literal', value: true, start: 0 }]);
8485
});
8586
it('should tokenize raw strings', () => {
86-
expect(tokenize("'raw-string'")).toMatchObject([{ type: 'Literal', value: "raw-string", start: 0 }]);
87+
expect(tokenize("'raw-string'")).toMatchObject([{ type: 'Literal', value: 'raw-string', start: 0 }]);
8788
});
8889
it('should tokenize raw strings single quote', () => {
8990
expect(tokenize("'\\''")).toMatchObject([{ type: 'Literal', value: "'", start: 0 }]);
@@ -92,7 +93,7 @@ describe('tokenize', () => {
9293
expect(tokenize("'\\'raw-string\\''")).toMatchObject([{ type: 'Literal', value: "'raw-string'", start: 0 }]);
9394
});
9495
it('should tokenize raw strings backslash characters', () => {
95-
expect(tokenize("'\\\\'")).toMatchObject([{ type: 'Literal', value: "\\", start: 0 }]);
96+
expect(tokenize("'\\\\'")).toMatchObject([{ type: 'Literal', value: '\\', start: 0 }]);
9697
});
9798
it('should not require surrounding quotes for strings', () => {
9899
expect(tokenize('`foo`', { enable_legacy_literals: true })).toMatchObject([

test/jmespath-parser.spec.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, expect } from 'vitest';
12
import { compile } from '../src';
23
import { expectError } from './error.utils';
34

@@ -42,8 +43,16 @@ describe('parsing', () => {
4243
const expected = {
4344
type: 'LetExpression',
4445
bindings: [
45-
{ type: 'Binding', variable: 'foo', reference: { type: 'Field', name: 'bar' } },
46-
{ type: 'Binding', variable: 'baz', reference: { type: 'Field', name: 'qux' } },
46+
{
47+
type: 'Binding',
48+
variable: 'foo',
49+
reference: { type: 'Field', name: 'bar' },
50+
},
51+
{
52+
type: 'Binding',
53+
variable: 'baz',
54+
reference: { type: 'Field', name: 'qux' },
55+
},
4756
],
4857
expression: { type: 'Current' },
4958
};
@@ -60,9 +69,9 @@ describe('parsing', () => {
6069
const expected = {
6170
type: 'AndExpression',
6271
left: { type: 'Current' },
63-
right: { type: 'Literal' }
72+
right: { type: 'Literal' },
6473
};
65-
expect(compile(' @ && \'truthy\' ')).toMatchObject(expected);
66-
expect(compile('( @ && \'truthy\' )')).toMatchObject(expected);
74+
expect(compile(" @ && 'truthy' ")).toMatchObject(expected);
75+
expect(compile("( @ && 'truthy' )")).toMatchObject(expected);
6776
});
6877
});

test/jmespath-utils.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, expect } from 'vitest';
12
import { expectError } from './error.utils';
23
import { divide, strictDeepEqual } from '../src/utils';
34

0 commit comments

Comments
 (0)