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
64 stars 14 forks source link

Error "The property _____ was not found" is received if expect value different from actual #20

Open Paychokxxx opened 4 years ago

Paychokxxx commented 4 years ago

Describe the bug Incorrect error is displayed

To Reproduce After run of

const { structuredDataTest } = require('structured-data-testing-tool')
const url = 'https://www.bbc.co.uk/news/world-us-canada-49060410'
const testUrl = 'https://www.bbc.co.uk/news/world-us-canada-49060410_EXTRA_TEXT'

const CustomPreset = {
    name: 'Non-premium About Page',
    description: 'Test all the structured data is correct for Non-premium about tab',
    tests: [
        // Check 'NewsArticle' schema exists in JSON-LD
        { test: 'ReportageNewsArticle', expect: true, type: 'jsonld' },

        // Check a 'NewsArticle' schema exists with 'url' property set to the value of the  variable 'url'
        { test: 'ReportageNewsArticle[*].url', expect: testUrl },

        // A similar check as above, but won't fail (only warn) if the test doesn't pass
        { test: 'ReportageNewsArticle[*].mainEntityOfPage', expect: testUrl, warning: true },

        // Test for a Twitter meta tag with specific value
        { test: '"twitter:domain"', expect: 'www.bbc.co.uk', type: 'metatag' }
      ]
};

let result

structuredDataTest(url, {
  // Check for compliance with Google, Twitter and Facebook recommendations
  presets: [ CustomPreset ],
  // Check the page includes a specific Schema (see https://schema.org/docs/full.html for a list)
})
.then(res => {
  console.log('✅ All tests passed!')
  result = res
})
.catch(err => {
  if (err.type === 'VALIDATION_FAILED') {
    console.log('❌ Some tests failed.')
    result = err.res
  } else {
    console.log(err) // Handle other errors here (e.g. an error fetching a URL)
  }
})
.finally(() => {
  if (result) {
    console.log(
      `Passed: ${result.passed.length},`,
      `Failed: ${result.failed.length},`,
      `Warnings: ${result.warnings.length}`,
    )
    console.log(`Schemas found: ${result.schemas.join(',')}`)

    // Loop over validation errors
    if (result.failed.length > 0)
      console.log("⚠️  Errors:\n", result.failed.map(test => test))
  }
})

I receive

❌ Some tests failed.
Passed: 3, Failed: 1, Warnings: 1
Schemas found: ReportageNewsArticle
⚠️  Errors:
 [ { test: 'ReportageNewsArticle[*].url',
    expect:
     'https://www.bbc.co.uk/news/world-us-canada-49060410_EXTRA_TEXT',
    group: 'Non-premium About Page',
    passed: false,
    type: 'any',
    value: null,
    error:
     { type: 'NOT_FOUND',
       message: 'The property "ReportageNewsArticle[*].url" was not found' } } ]

Include either CLI command or example code which can be used to reproduce the behavior.

Expected behavior Should it be ?
type: 'INCORRECT_VALUE', message: Incorrect value found for "${path}",

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

iaincollins commented 4 years ago

Thanks for the bug report.

If I'm reading it correctly, yes it should be INCORRECT_VALUE instead of NOT_FOUND.

I'll clean up the formatting of the ticket and take a look!