Developer tools dump stack traces, exit codes, and jargon. Figuring out *what to do next* often means searching the same Stack Overflow answers again.
| 1 | """npm rule tests.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import pytest |
| 6 | |
| 7 | from why_failed.matcher import analyze |
| 8 | |
| 9 | CASES = [ |
| 10 | ("npm ERR! code ERESOLVE\nnpm ERR! ERESOLVE unable to resolve dependency tree", "npm.eresolve"), |
| 11 | ("npm ERR! code ETARGET\nnpm ERR! notarget No matching version found", "npm.etarget"), |
| 12 | ("npm ERR! Error: EACCES: permission denied", "npm.eacces"), |
| 13 | ("Error: Cannot find module 'express'\nRequire stack:\n- app.js", "npm.module_not_found"), |
| 14 | ("Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'foo'", "npm.err_module_not_found"), |
| 15 | ("npm ERR! 404 Not Found - GET https://registry.npmjs.org/nope - Not found", "npm.package_not_found"), |
| 16 | ("npm WARN ERESOLVE overriding peer dependency\nrequires a peer of react@^17", "npm.peer_dependency"), |
| 17 | ] |
| 18 | |
| 19 | |
| 20 | @pytest.mark.parametrize("text,rule_id", CASES) |
| 21 | def test_npm_rules(text: str, rule_id: str) -> None: |
| 22 | result = analyze(text) |
| 23 | assert result.match is not None |
| 24 | assert result.match.rule_id == rule_id |