Skip to content

Commit

Permalink
test(jmespath): 100% coverage and spec compliance (#2271)
Browse files Browse the repository at this point in the history
* feat(jmespath): add parser component

* feat: add envelopes & entrypoint

* test(jmespath): full test coverage

* test(jmespath): full test coverage

* chore: add missing export file

---------

Co-authored-by: Simon Thulbourn <[email protected]>
  • Loading branch information
dreamorosi and sthulb authored Mar 27, 2024
1 parent 90d3b84 commit fc37010
Show file tree
Hide file tree
Showing 20 changed files with 8,608 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .github/actions/cached-node-modules/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ runs:
npm run build -w packages/parameters & \
npm run build -w packages/idempotency & \
npm run build -w packages/batch & \
npm run build -w packages/testing
npm run build -w packages/testing & \
npm run build -w packages/jmespath
shell: bash
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ jobs:
with:
nodeVersion: ${{ matrix.version }}
- name: Run linting
run: npm run lint -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics -w packages/parameters -w packages/idempotency -w packages/batch
run: npm run lint -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics -w packages/parameters -w packages/idempotency -w packages/batch -w packages/jmespath
- name: Run unit tests
run: npm t -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics -w packages/parameters -w packages/idempotency -w packages/batch
run: npm t -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics -w packages/parameters -w packages/idempotency -w packages/batch -w packages/jmespath
check-examples:
runs-on: ubuntu-latest
env:
Expand Down
12 changes: 12 additions & 0 deletions packages/jmespath/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export { search } from './search.js';
export {
JMESPathError,
LexerError,
ParseError,
IncompleteExpressionError,
ArityError,
VariadicArityError,
JMESPathTypeError,
EmptyExpressionError,
UnknownFunctionError,
} from './errors.js';
137 changes: 137 additions & 0 deletions packages/jmespath/tests/unit/compliance/base.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/**
* Test Compliance with the JMESPath specification
*
* @group unit/jmespath/compliance/base
*/
import { search } from '../../../src/index.js';

describe('Base tests', () => {
it.each([
{
expression: 'foo',
expected: { bar: { baz: 'correct' } },
},
{
expression: 'foo.bar',
expected: { baz: 'correct' },
},
{
expression: 'foo.bar.baz',
expected: 'correct',
},
{
expression: 'foo\n.\nbar\n.baz',
expected: 'correct',
},
{
expression: 'foo.bar.baz.bad',
expected: null,
},
{
expression: 'foo.bar.bad',
expected: null,
},
{
expression: 'foo.bad',
expected: null,
},
{
expression: 'bad',
expected: null,
},
{
expression: 'bad.morebad.morebad',
expected: null,
},
])(
'should parse a multi-level nested object: $expression',
({ expression, expected }) => {
// Prepare
const data = { foo: { bar: { baz: 'correct' } } };

// Act
const result = search(expression, data);

// Assess
expect(result).toStrictEqual(expected);
}
);

it.each([
{
expression: 'foo',
expected: { bar: ['one', 'two', 'three'] },
},
{
expression: 'foo.bar',
expected: ['one', 'two', 'three'],
},
])(
'should parse multi-level objects with arrays: $expression',
({ expression, expected }) => {
// Prepare
const data = { foo: { bar: ['one', 'two', 'three'] } };

// Act
const result = search(expression, data);

// Assess
expect(result).toStrictEqual(expected);
}
);

it.each([
{
expression: 'one',
expected: null,
},
{
expression: 'two',
expected: null,
},
{
expression: 'three',
expected: null,
},
{
expression: 'one.two',
expected: null,
},
])('should parse an array: $expression', ({ expression, expected }) => {
// Prepare
const data = ['one', 'two', 'three'];

// Act
const result = search(expression, data);

// Assess
expect(result).toStrictEqual(expected);
});

it.each([
{
expression: 'foo."1"',
expected: ['one', 'two', 'three'],
},
{
expression: 'foo."1"[0]',
expected: 'one',
},
{
expression: 'foo."-1"',
expected: 'bar',
},
])(
'should parse an object with arrays and numeric values as keys: $expression',
({ expression, expected }) => {
// Prepare
const data = { foo: { '1': ['one', 'two', 'three'], '-1': 'bar' } };

// Act
const result = search(expression, data);

// Assess
expect(result).toStrictEqual(expected);
}
);
});
Loading

0 comments on commit fc37010

Please sign in to comment.