Skip to content

test(jmespath): 100% coverage and spec compliance #2271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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