Comments (5)
This is what I get from the command line:
npx structured-data-testing-tool --file ./bedrock/base/templates/includes/structured-data/product/firefox-developer-product.json --schemas jsonld:Product
Tests
Schema.org > Product - 0% (0 passed, 1 total)
✕ schema in jsonld [Product[*]]
Statistics
Number of Metatags: 0
Schemas in JSON-LD: 0
Schemas in HTML: 0
Schema in RDFa: 0
Schema.org schemas: 0
Other schemas: 0
Test groups run : 1
Total tests run: 1
Results
Passed: 0 (0%)
Warnings: 0 (0%)
Failed: 1 (100%)
✕ 1 of 1 tests failed with 0 warnings.
And here's the output (no errors or warnings) when I try using the API:
sdttt.js
const fs = require("fs");
const glob = require("glob").sync;
const { structuredDataTestHtml } = require("structured-data-testing-tool");
const presets = require("structured-data-testing-tool/presets");
const schemas = require("structured-data-testing-tool/lib/schemas");
main("./bedrock/base/templates/includes/structured-data/product/firefox-developer-product.json");
async function main(g) {
if (!g) {
console.error("Missing glob");
process.exit(1);
}
for (const file of glob(g)) {
try {
// const SoftwareApplication = schemas.getSchema("SoftwareApplication");
const res = await lintFile(file); // , {schemas: [SoftwareApplication]}); // {presets: [presets.SocialMedia]});
const data = [].concat(res.failed, res.warnings);
console.log(`${file}\n${JSON.stringify(data, null, 2)}\n\n`);
if (res && (res.failed.length || res.warnings.length)) {
console.error(file, res.failed, res.warnings);
process.exitCode = 2;
}
} catch (err) {
console.log("!!!", err);
let res;
if (err.res) {
res = [].concat(err.res.failed, err.res.warnings)
.map(err => err.error.message).sort();
}
console.error(file, res);
}
}
}
async function lintFile(file, options = {}) {
const txt = fs.readFileSync(file, "utf-8").toString();
const html = `<script type="application/ld+json">${txt}</script>`;
return await structuredDataTestHtml(html, options);
}
node sdttt
./bedrock/base/templates/includes/structured-data/product/firefox-developer-product.json
[]
from structured-data-testing-tool.
Hi Peter!
That seems like a great use case! It's not currently supported, but based on this I'm happy to add support for both a new structuredDataTestJson
method and auto-detection if a JSON object (or array of objects) is passed. The command line tool should also support validating JSON input.
The approach you have should work in the interim (I did a quick check and works for me), as long as you have an await
before the function call:
async function lintFile(file, options = {}) {
const txt = fs.readFileSync(file, "utf-8").toString();
const html = `<script type="application/ld+json">${txt}</script>`;
return await structuredDataTestHtml(html, options);
}
If this doesn't work for you and/or if the docs need updating anywhere to reflect this would appreciate if you can feedback (happy to help)…
However, ticket #5 is still in progress, which means that for now testing this way is likely of limited usefulness without a custom preset to check the properties and values are valid.
If you have specific use cases, very happy to focus on those first if you want to elaborate!
from structured-data-testing-tool.
Thanks @pdehaan - sorry hadn't missed the notification for this. Are you able to share the JSON file so can investigate (either to fix a bug and/or improve the docs - though sounds like maybe both)?
from structured-data-testing-tool.
Yeah, sorry. Looks like the [draft] PR is public; mozilla/bedrock#7664
I think I tried experimenting w/ linting the JSON files directly, as well as wrapping the files in a <script type="application/ld+json">
tag and writing the file out as an .html and linting that.
from structured-data-testing-tool.
Hi @pdehaan,
It's taken a while for me to get round to, but if it's of use to you or anyone else:
As of version 4.1 JSON input is now supported in URLs, files and strings / buffers / streams / etc in both the API and Command Line Interface.
It actually treats it as described by automatically wrapping it with an appropriate script tag when the input validates as serialized JSON, so that the validation is exactly the same and it's automatic so no additional code or options are required to test JSON files.
Although there is improve schema evaluation in version 4, actual Schema.org property validation is part of the milestone for for version 5 so this still may not be useful to you, but this still may be useful for other folks.
from structured-data-testing-tool.
Related Issues (20)
- Google preset not running HOT 2
- test fails for urls without tld (http://localhost) HOT 2
- Support for validating schema properties HOT 4
- Error: Cannot find module './presets' HOT 5
- Rewrite and collaboration HOT 4
- Schema.org tests should only apply to Schema.org schemas HOT 1
- Add `url` property to tests HOT 1
- New Schema.org tests should work with nested objects HOT 2
- Error "The property _____ was not found" is received if expect value different from actual HOT 1
- Support referencing schemas using @id
- Article Schema not detected & errors not reported HOT 2
- How to test nested Object HOT 1
- Testing tool skips invalid JSON should report as a failure HOT 1
- vulnerabilities with "css-what" module
- Project Status HOT 3
- Not detecting schemas HOT 1
- Add option to check for and test schemas by name HOT 3
- Consolidate presets - allow presets to contain other presets HOT 1
- Add options to test object to evaluate if a test or preset should run
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from structured-data-testing-tool.