-
The Usage section of the README file contains the example: import { Audit } from "@siteimprove/alfa-act";
import { Scraper } from "@siteimprove/alfa-scraper";
import rules from "@siteimprove/alfa-rules";
Scraper.with(async (scraper) => {
for (const input of await scraper.scrape("http://example.com")) {
const outcomes = await Audit.of(input, rules).evaluate();
}
}); But this script executed with Node.js crashes on
I believe this is because |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 6 replies
-
Hi @jrpool, thanks for reporting. I'll look into it. I guess we haven't updated the readme at some point. In the meantime, please have a look at the Alfa examples repository where you'll hopefully find inspiration on using Alfa 😃 |
Beta Was this translation helpful? Give feedback.
-
Hi @jrpool I've tried the code with no problem on my side. A possible issue is that this code is supposed to be TypeScript code that then needs to be built into JavaScript. When doing so (with a "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const alfa_act_1 = require("@siteimprove/alfa-act");
const alfa_scraper_1 = require("@siteimprove/alfa-scraper");
const alfa_rules_1 = require("@siteimprove/alfa-rules");
alfa_scraper_1.Scraper.with(async (scraper) => {
for (const input of await scraper.scrape("http://example.com")) {
const outcomes = await alfa_act_1.Audit.of(input, alfa_rules_1.default).evaluate();
}
}); which runs without problems (on Powershell on a windows box). Another possible issue is Node version. Mine is v15.14.0. Our build scripts use Node v14 and 16, so I assume it should also work with these versions. |
Beta Was this translation helpful? Give feedback.
-
Hi, @Jym77. Thank you for your helpful comment. I have tried your version under Node 14.16.0 and Node 16.8.0. In both cases, I do not get an error message. The I have reviewed the examples, but they involve packages that I have not been using, and it is not evident that any of those packages is intrinsically required for use of alfa. That is why I have concentrated on the basic Node scripts in the README file. |
Beta Was this translation helpful? Give feedback.
-
Some analysis suggests that the error message had been due to using The following code outputs an But the script outputs an empty object as
|
Beta Was this translation helpful? Give feedback.
-
Can you try the full scraping example (first run It is essentially the same script as the one in the README. When trying this version of your script: const { Audit } = require("@siteimprove/alfa-act");
const { Scraper } = require("@siteimprove/alfa-scraper");
const alfaRules = require("@siteimprove/alfa-rules");
Scraper.with(async (scraper) => {
for (const input of await scraper.scrape("https://example.com/")) {
const audit = Audit.of(input, alfaRules.default);
const outcomes = await audit.evaluate();
const result = [...outcomes];
console.log(`Found ${result.length} outcomes`);
console.log(result[0].toJSON());
}
}); I get
I think the difference comes from the fact that |
Beta Was this translation helpful? Give feedback.
Can you try the full scraping example (first run
yarn build
at top level of the examples repo, then runyarn test
in thecustom-testing/scraping
directory).It is essentially the same script as the one in the README.
When trying this version of your script: