-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Addresses issue #15 * Added examples of usage
- Loading branch information
1 parent
1de4782
commit 1ac057e
Showing
5 changed files
with
114 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const { structuredDataTest } = require('structured-data-testing-tool') | ||
const { Google, Twitter, Facebook } = require('structured-data-testing-tool/presets') | ||
|
||
const urls = [ | ||
'https://www.bbc.co.uk/news/world-us-canada-49060410', | ||
'https://www.nytimes.com/2020/03/08/world/coronavirus-news.html', | ||
'https://www.ft.com/content/75583754-5fab-11ea-b0ab-339c2307bcd4', | ||
'https://news.sky.com/story/coronavirus-italy-sees-largest-daily-rise-in-deaths-and-confirmed-cases-11953192' | ||
] | ||
|
||
urls.forEach(url => { | ||
let result | ||
structuredDataTest(url, { | ||
presets: [ Google, Twitter, Facebook ], | ||
}) | ||
.then(res => { | ||
console.log(`✅ ${url}`) | ||
result = res | ||
}) | ||
.catch(err => { | ||
if (err.type === 'VALIDATION_FAILED') { | ||
console.log(`❌ ${url}`) | ||
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)) | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const { structuredDataTest } = require('structured-data-testing-tool') | ||
const { Google, Twitter, Facebook } = require('structured-data-testing-tool/presets') | ||
|
||
const url = 'https://www.bbc.co.uk/news/world-us-canada-49060410' | ||
|
||
let result | ||
|
||
structuredDataTest(url, { | ||
// Check for compliance with Google, Twitter and Facebook recommendations | ||
presets: [ Google, Twitter, Facebook ], | ||
// Check the page includes a specific Schema (see https://schema.org/docs/full.html for a list) | ||
schemas: [ 'ReportageNewsArticle' ] | ||
}) | ||
.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)) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.