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 `url` property to tests #18

Open iaincollins opened 4 years ago

iaincollins commented 4 years ago

Summary of proposed feature Add url property to tests and presets that can be used to link to documentation, and display the the URL in the CLI when a test does not pass (ie on error or warning).

Purpose of proposed feature Provide a way to reference online documentation to resolve issues, especially when a test fails.

Detail of the proposed feature

This property should link to pages that document a schema and/or can help resolve the specific problem. It would work well with the new schema.org property tests (which are in master but not in the release version).

Potential problems None.

Describe any alternatives you've considered None.

Additional context URL properties for Schema objects could also be automatically generated.

iaincollins commented 4 years ago

This feature has been added but not yet documented, this issue should remain open until it is.

URLs can be specified on both presets and tests, like this:

const Twitter = {
  name: 'Twitter',
  description: 'Suggested metatags for Twitter',
  url: 'https://developer.twitter.com/en/docs/tweets/optimize-with-cards',
  tests: [
    { test: `"twitter:card"`, type: 'metatag', description: 'must have card type' },
    { test: `"twitter:title"`, type: 'metatag', description: 'must have title' },
    { test: `"twitter:description"`, type: 'metatag', description: 'must have description' },
    { test: `"twitter:image" || "twitter:image:src"`, type: 'metatag', description: 'must have image url' },
    { test: `"twitter:image:alt"`, type: 'metatag', description: 'must have image alt text' },
    { test: `"twitter:site"`, type: 'metatag', warning: true, description: 'should have account username' },
    { test: `"twitter:creator"`, type: 'metatag', warning: true, description: 'should have username of content creator' },
  ],
}

It is currently only really used internally by the CLI (although 'url' objects are exposed via the API too) but is worth documenting - especially if/when the CLI is able to use custom presets.

NB: If a test (or preset that is part of another preset) does not have a URL, but a parent preset does, then they will inherit the URL property from the nearest parent preset, this is so that you can specify a URL once for multiple tests, while still being able to link to more specific documentation for any given test.