iaincollins / structured-data-testing-tool

A library and command line tool to help inspect and test for Structured Data.
https://www.npmjs.com/package/structured-data-testing-tool
ISC License
63 stars 14 forks source link

Add options to test object to evaluate if a test or preset should run #7

Closed iaincollins closed 4 years ago

iaincollins commented 4 years ago

How could the tool be better? Please describe. Individual tests and presets (collections of tests) should be able to specify a conditional test that must match the expected result for the test to run.

The purpose of this is to be able to conditionally run a test or a preset, so that a preset only applies if the response matches a precondition; for example if the preset "Google" is specified, it should only validate schemas found in the input.

Describe the solution you'd like This could be something like another test object (the same syntax for "test" and "expect", with the same default assumed value for "expect" of "true") although supporting this may require refactoring of the existing method that invokes tests.

{
  test: 'test-to-run',
  expect: 'value-to-expect',
  conditional: {
    test: 'evaluate-before-running-test',
    expect: 'value-to-expect-conditional-test-to-return'
  }
}

Additional context