Outcomes are 'None' or 'Inapplicable' for default rules #247
-
I wrote a script (see https://gist.github.com/drc-nloftsgard/588ddfef8d7fdd42cb7df4a50ecda884) to scrape a page and am not getting the outcomes that I expect. The command to run this script is: Am I missing something in the setup of this test? Is there a certain TypeScript version or dependencies required that would fix this? What else can I try to troubleshoot the issue? |
Beta Was this translation helpful? Give feedback.
Replies: 12 comments
-
Thanks for reaching out! The issue you're seeing is related to the use of iterables. Some iterables, such as the one containing the outcomes, can only be iterated once while your code attempts to iterate it several times. On line 50, the iterable of outcomes is fully consumed to determine its size. Then, on line 57, the code attempts to iterate the iterable again once for every outcome, but at this point the iterable is actually empty. That's why you're seeing The easiest solution would be to instead use a for (const outcome of outcomes) {
console.log(outcome);
} The behaviour you're seeing on line 8 is also a little concerning so I'll look into that. |
Beta Was this translation helpful? Give feedback.
-
I'm suspecting that you've got two incompatible versions of @siteimprove/alfa-web installed, which perhaps isn't surprising as none of the currently published versions of that package are compatible. The wonders of pre-releases! Could you send me the output of |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick response on the main issue. I took out the code to determine size and updated to use
|
Beta Was this translation helpful? Give feedback.
-
With every |
Beta Was this translation helpful? Give feedback.
-
Sure, I set them as below (devDependencies in my package.json) and ran npm install
I get the same 'inapplicable' for all rules. I'm experimented with different values/settings in my tsconfig.json but that doesn't seem to help or change the results. Is there any other debugging I can do? What other output would help figure this out? |
Beta Was this translation helpful? Give feedback.
-
The dependencies look correct so that's good 👍 Could you try filtering out inapplicable outcomes to see if every rule is indeed inapplicable? One way would be: [...outcomes].filter(Outcome.isApplicable); |
Beta Was this translation helpful? Give feedback.
-
Indeed, I verified all rules are inapplicable. |
Beta Was this translation helpful? Give feedback.
-
That's really odd and not at all what I'm seeing on my end 🤔 Does the screenshot look correct? |
Beta Was this translation helpful? Give feedback.
-
Here's what I'm seeing as a result of |
Beta Was this translation helpful? Give feedback.
-
The screenshot looks correct. I created a new project/repository, alfa-test, and I get the expected Outcomes! So there must be something in my other (private company) repository that's causing this issue. |
Beta Was this translation helpful? Give feedback.
-
Wonderful! 👏 Do let me know if anything else pops up! |
Beta Was this translation helpful? Give feedback.
Thanks for reaching out! The issue you're seeing is related to the use of iterables. Some iterables, such as the one containing the outcomes, can only be iterated once while your code attempts to iterate it several times. On line 50, the iterable of outcomes is fully consumed to determine its size. Then, on line 57, the code attempts to iterate the iterable again once for every outcome, but at this point the iterable is actually empty. That's why you're seeing
None
returned every time the code attempts to read an outcome.The easiest solution would be to instead use a
for ... of
loop to ensure that the iterable is only iterated once: