Skip to content

Commit

Permalink
Merge pull request #37 from jmespath-community/chore-migrate-to-vitest
Browse files Browse the repository at this point in the history
chore: migrate from Jest to vitest
  • Loading branch information
cawalch authored Dec 14, 2024
2 parents 02604a6 + 4f69e60 commit d0cb134
Show file tree
Hide file tree
Showing 11 changed files with 2,265 additions and 3,445 deletions.
5,620 changes: 2,198 additions & 3,422 deletions package-lock.json

Large diffs are not rendered by default.

15 changes: 6 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@
"build": "npx tsc --outDir dist/lib -d --module commonjs && npx rollup -c rollup.config.ts",
"perf": "node --expose-gc scripts/perf.js",
"start": "npx rollup -c rollup.config.ts -w",
"test": "npx jest --coverage",
"test:watch": "npx jest --coverage --watch",
"test:prod": "npm run lint && npm run test -- --no-cache",
"test": "vitest --run",
"test:watch": "vitest",
"test:prod": "npm run lint && npm run test",
"coverage": "vitest run --coverage",
"deploy-docs": "ts-node scripts/gh-pages-publish",
"report-coverage": "cat ./coverage/lcov.info | coveralls",
"precommit": "lint-staged",
Expand All @@ -56,7 +57,6 @@
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-terser": "^0.4.0",
"@rollup/plugin-typescript": "^8.2.1",
"@types/jest": "^29.4.0",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"clean-publish": "^3.4.5",
Expand All @@ -65,9 +65,6 @@
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-prettier": "^3.4.1",
"husky": "^6.0.0",
"jest": "^29.5.0",
"jest-cli": "^29.5.0",
"jest-config": "^29.5.0",
"lint-staged": "^11.0.0",
"prettier": "^2.3.0",
"prettier-eslint": "^12.0.0",
Expand All @@ -76,8 +73,8 @@
"rollup-plugin-typescript2": "^0.34.1",
"shelljs": "^0.8.4",
"tinybench": "^2.5.1",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.1",
"typescript": "^4.3.2"
"typescript": "^4.3.2",
"vitest": "^2.1.8"
}
}
12 changes: 10 additions & 2 deletions test/compliance.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { describe, expect, test } from 'vitest';
import { readdirSync, readFileSync } from 'fs';
import { basename } from 'path';
import { Options, search } from '../src';
import { JSONValue } from '../src/JSON.type';
import { expectError } from './error.utils';

export type ComplianceTestCaseDefinition = { expression: string; result?: JSONValue; error?: string };
export type ComplianceTestCase = { given: JSONValue; cases: ComplianceTestCaseDefinition[] };
export type ComplianceTestCaseDefinition = {
expression: string;
result?: JSONValue;
error?: string;
};
export type ComplianceTestCase = {
given: JSONValue;
cases: ComplianceTestCaseDefinition[];
};
export type ComplianceTestSuite = ComplianceTestCase[];

// Compliance tests that aren't supported yet.
Expand Down
1 change: 1 addition & 0 deletions test/error.utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect } from 'vitest';
import { JSONValue } from '../src/JSON.type';

export function expectError(action: () => JSONValue, expected: string | string[]): void {
Expand Down
7 changes: 6 additions & 1 deletion test/jmespath-extensions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import jmespath, { search, registerFunction } from '../src';
import { JSONObject } from '../src/JSON.type';

Expand Down Expand Up @@ -155,7 +156,11 @@ describe('registerFunction', () => {
registerFunction(
'optionalArgs',
([first, second, third]) => {
return { first, second: second ?? 'default[2]', third: third ?? 'default[3]' };
return {
first,
second: second ?? 'default[2]',
third: third ?? 'default[3]',
};
},
[{ types: [jmespath.TYPE_ANY] }, { types: [jmespath.TYPE_ANY], optional: true }],
);
Expand Down
10 changes: 6 additions & 4 deletions test/jmespath-functions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { search, registerFunction, TYPE_NUMBER } from '../src';
import { expectError } from './error.utils';

Expand Down Expand Up @@ -130,12 +131,13 @@ describe('custom functions', () => {
it('must be in scope for let expression', () => {
registerFunction(
'plusplus', // FUNCTION NAME
(resolvedArgs) => { // CUSTOM FUNCTION
resolvedArgs => {
// CUSTOM FUNCTION
const [num] = resolvedArgs;
return num + 1;
},
[{ types: [TYPE_NUMBER] }] //SIGNATURE
[{ types: [TYPE_NUMBER] }], //SIGNATURE
);
expect(search({index: 0}, 'let $n = index in plusplus($n)')).toEqual(1);
expect(search({ index: 0 }, 'let $n = index in plusplus($n)')).toEqual(1);
});
});
});
1 change: 1 addition & 0 deletions test/jmespath-interpreter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { search } from '../src';

describe('Searches compiled ast', () => {
Expand Down
5 changes: 3 additions & 2 deletions test/jmespath-lexer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { tokenize } from '../src';

describe('tokenize', () => {
Expand Down Expand Up @@ -83,7 +84,7 @@ describe('tokenize', () => {
expect(tokenize('`true`')).toMatchObject([{ type: 'Literal', value: true, start: 0 }]);
});
it('should tokenize raw strings', () => {
expect(tokenize("'raw-string'")).toMatchObject([{ type: 'Literal', value: "raw-string", start: 0 }]);
expect(tokenize("'raw-string'")).toMatchObject([{ type: 'Literal', value: 'raw-string', start: 0 }]);
});
it('should tokenize raw strings single quote', () => {
expect(tokenize("'\\''")).toMatchObject([{ type: 'Literal', value: "'", start: 0 }]);
Expand All @@ -92,7 +93,7 @@ describe('tokenize', () => {
expect(tokenize("'\\'raw-string\\''")).toMatchObject([{ type: 'Literal', value: "'raw-string'", start: 0 }]);
});
it('should tokenize raw strings backslash characters', () => {
expect(tokenize("'\\\\'")).toMatchObject([{ type: 'Literal', value: "\\", start: 0 }]);
expect(tokenize("'\\\\'")).toMatchObject([{ type: 'Literal', value: '\\', start: 0 }]);
});
it('should not require surrounding quotes for strings', () => {
expect(tokenize('`foo`', { enable_legacy_literals: true })).toMatchObject([
Expand Down
19 changes: 14 additions & 5 deletions test/jmespath-parser.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { compile } from '../src';
import { expectError } from './error.utils';

Expand Down Expand Up @@ -42,8 +43,16 @@ describe('parsing', () => {
const expected = {
type: 'LetExpression',
bindings: [
{ type: 'Binding', variable: 'foo', reference: { type: 'Field', name: 'bar' } },
{ type: 'Binding', variable: 'baz', reference: { type: 'Field', name: 'qux' } },
{
type: 'Binding',
variable: 'foo',
reference: { type: 'Field', name: 'bar' },
},
{
type: 'Binding',
variable: 'baz',
reference: { type: 'Field', name: 'qux' },
},
],
expression: { type: 'Current' },
};
Expand All @@ -60,9 +69,9 @@ describe('parsing', () => {
const expected = {
type: 'AndExpression',
left: { type: 'Current' },
right: { type: 'Literal' }
right: { type: 'Literal' },
};
expect(compile(' @ && \'truthy\' ')).toMatchObject(expected);
expect(compile('( @ && \'truthy\' )')).toMatchObject(expected);
expect(compile(" @ && 'truthy' ")).toMatchObject(expected);
expect(compile("( @ && 'truthy' )")).toMatchObject(expected);
});
});
1 change: 1 addition & 0 deletions test/jmespath-utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest';
import { expectError } from './error.utils';
import { divide, strictDeepEqual } from '../src/utils';

Expand Down
19 changes: 19 additions & 0 deletions vitest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
globals: true,
environment: 'node',
coverage: {
provider: 'v8',
reporter: ['text', 'lcov'],
include: ['src/**/*.ts'],
thresholds: {
branches: 90,
functions: 95,
lines: 95,
statements: 95,
},
},
},
});

0 comments on commit d0cb134

Please sign in to comment.