Skip to content
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

Adds new package @microsoft/sarif-matcher-utils #59

Merged
merged 5 commits into from
May 24, 2022

Conversation

scalvert
Copy link
Collaborator

@scalvert scalvert commented May 18, 2022

The motivation for this change is precipitated by the emergence of jest API compatible frameworks, like vitest. In order to provide the same style expect extension while not depending on jest, it's necessary to extract the core matcher utility into its own package. This allows consumers to import and extend into any framework they wish (so long as it's jest style compatible).

Example of usage for vitest:

import { describe, it, expect } from 'vitest';
import { buildMatcher } from '@microsoft/sarif-matcher-utils';
import Sarif from 'sarif';
import { buildSarifLog } from './build-sarif-log.js';

type MaybeSarifLog = Sarif.Log | unknown;

interface CustomMatchers<R = unknown> {
  toBeValidSarifLog(): R;
}

declare global {
  namespace Vi {
    interface Assertion extends CustomMatchers {}
    interface AsymmetricMatchersContaining extends CustomMatchers {}
  }
}

const toBeValidSarifLog = buildMatcher<MaybeSarifLog>();

expect.extend({ toBeValidSarifLog });

describe('a suite', () => {
  it('can check for a SARIF log', () => {
    let data = buildSarifLog();

    expect(data).toBeValidSarifLog();
  });
});

Copy link
Contributor

@eddynaka eddynaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@scalvert scalvert merged commit 1495f10 into main May 24, 2022
@scalvert scalvert deleted the extract-core-assertion branch May 24, 2022 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants