BigBlueHat closed pull request #41: Add remote URL fetching to `yarn validate 
--url`
URL: https://github.com/apache/incubator-annotator/pull/41
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/README.md b/README.md
index 32a5514..fd91bd1 100644
--- a/README.md
+++ b/README.md
@@ -63,9 +63,22 @@ using the `validate` script:
 
 
 ```sh
-$ yarn validate --url ../anno1.json
+$ yarn validate --url 
https://raw.githubusercontent.com/w3c/web-annotation-tests/master/tools/samples/correct/anno1.json
 ```
 
+With the `--url` option you can pass in a URL or a local path to a JSON file.
+
+##### Examples
+
+Valid: 
+
+`https://raw.githubusercontent.com/w3c/web-annotation-tests/master/tools/samples/correct/anno1.json`
+
+Invalid:
+
+`https://raw.githubusercontent.com/w3c/web-annotation-tests/master/tools/samples/incorrect/anno1.json`
+
+[(More)](https://github.com/w3c/web-annotation-tests/tree/master/tools/samples)
 
 # License
 
diff --git a/package.json b/package.json
index 3d12dc4..2e633ed 100644
--- a/package.json
+++ b/package.json
@@ -52,6 +52,7 @@
     "mocha": "^5.0.5",
     "mocha-loader": "^1.1.3",
     "multi-entry-loader": "^1.1.2",
+    "node-fetch": "^2.2.0",
     "nyc": "^11.6.0",
     "prettier": "^1.11.1",
     "rimraf": "^2.6.2",
diff --git a/test/data-model.mjs b/test/data-model.mjs
index 3c7fc47..ef99e72 100644
--- a/test/data-model.mjs
+++ b/test/data-model.mjs
@@ -2,6 +2,7 @@
 
 import fs from 'fs';
 import URL from 'url';
+import fetch from 'node-fetch';
 
 import Ajv from 'ajv';
 const ajv = new Ajv({ schemaId: 'auto' });
@@ -40,14 +41,15 @@ const musts = JSON.parse(
 describe('Test JSON against Schemas', () => {
   let data = '';
 
-  before(function() {
+  before(async function() {
     if (!found_url) {
       this.skip();
     } else {
       // load the data from the file or URL
       let url_parsed = URL.parse(url);
       if (url_parsed.path !== url_parsed.href) {
-        // TODO: GET the URL's JSON and use that
+        const data_response = await fetch(url_parsed.href);
+        data = await data_response.json();
       } else {
         // assume we have a local file and use that
         data = JSON.parse(fs.readFileSync(url_parsed.path, 'utf8'));
diff --git a/yarn.lock b/yarn.lock
index 2364d0a..849d2f1 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4648,6 +4648,10 @@ neo-async@^2.5.0:
   version "2.5.1"
   resolved 
"https://registry.yarnpkg.com/neo-async/-/neo-async-2.5.1.tgz#acb909e327b1e87ec9ef15f41b8a269512ad41ee";
 
+node-fetch@^2.2.0:
+  version "2.2.0"
+  resolved 
"https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.2.0.tgz#4ee79bde909262f9775f731e3656d0db55ced5b5";
+
 node-libs-browser@^2.0.0:
   version "2.1.0"
   resolved 
"https://registry.yarnpkg.com/node-libs-browser/-/node-libs-browser-2.1.0.tgz#5f94263d404f6e44767d726901fff05478d600df";


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to