Skip to content

Commit

Permalink
Improve examples
Browse files Browse the repository at this point in the history
Minor simplification of API examples.
  • Loading branch information
iaincollins committed Mar 11, 2020
1 parent 94d09c2 commit 23732d0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
7 changes: 2 additions & 5 deletions examples/custom-preset-tests-only.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ structuredDataTest(url, {
})
.catch(err => {
if (err.type === 'VALIDATION_FAILED') {
console.log('❌ Some tests failed.')
result = err.res
console.log('❌ Some tests failed.')
console.log("⚠️ Errors:\n", result.failed.map(test => test))
} else {
console.log(err) // Handle other errors here (e.g. an error fetching a URL)
}
Expand All @@ -39,9 +40,5 @@ structuredDataTest(url, {
`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))
}
})
11 changes: 4 additions & 7 deletions examples/test-multiple-urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ const urls = [

urls.forEach(url => {
let result
structuredDataTest(url, {
structuredDataTest(url, {
presets: [ Google, Twitter, Facebook ],
})
.then(res => {
console.log(`✅ ${url}`)
result = res
console.log(`✅ ${url}`)
})
.catch(err => {
if (err.type === 'VALIDATION_FAILED') {
console.log(`❌ ${url}`)
result = err.res
console.log(`❌ ${url}`)
} else {
console.log(err) // Handle other errors here (e.g. an error fetching a URL)
console.error(err) // Handle other errors here (e.g. an error fetching a URL)
}
})
.finally(() => {
Expand All @@ -34,9 +34,6 @@ urls.forEach(url => {
` 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))
}
})
})
11 changes: 4 additions & 7 deletions examples/test-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ structuredDataTest(url, {
schemas: [ 'ReportageNewsArticle' ]
})
.then(res => {
console.log('✅ All tests passed!')
result = res
console.log('✅ All tests passed!')
})
.catch(err => {
if (err.type === 'VALIDATION_FAILED') {
console.log('❌ Some tests failed.')
result = err.res
console.log('❌ Some tests failed.')
console.log("⚠️ Errors:\n", result.failed.map(test => test))
} else {
console.log(err) // Handle other errors here (e.g. an error fetching a URL)
console.error(err) // Handle other errors here (e.g. an error fetching a URL)
}
})
.finally(() => {
Expand All @@ -32,9 +33,5 @@ structuredDataTest(url, {
`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))
}
})

0 comments on commit 23732d0

Please sign in to comment.