Load config from a .js file
I´m trying to load the config from an external file to get the --tags and some others flags:
package.json:
"axeconfig": "node axe/index.js"
"accessibility:local": "axe npm run axeconfig -- http://localhost:3000"
axe/index.js is a js file that returns a string like "--timeout=120 --save testlog.json --tags (a list of tags)" . I just want to concatenate this string to the script and run it, but it take the string as another URL argument and ends up testing npm, run and axeconfig as URLs.
How can I execute the axeconfig script and add the string to run axe with parameters?
Thanks!
Does the file return the string or console.log? If it just outputs the string, you could execute a command using $(command)
axe $(node axe/index.js)
The js file returns a string:
return ` --timeout=${axeconfig.timeout} --save ${axeconfig.fileName} ${
axeconfig.tags.length ? `--tags ${axeconfig.tags}` : ''
}`;
(axeconfig is a json file that holds the parameters)
I have tried using } axe $(node axe/index.js) as you suggested but it keeps taking node and axe/index.js as URLs instead of running the file 😕
Odd. If you have it console.log() instead of return it should take the output of the file and use it as parameters.
// axe/index.js
console.log("dequeuniversity --timeout=120 --save testlog.json");
axe $(node axe/index.js)
Running axe-core 3.2.2 in chrome-headless
Testing http://dequeuniversity ... please wait, this may take a minute.
Violation of "document-title" with 1 occurrences!
Ensures each HTML document contains a non-empty <title> element. Correct invalid elements at:
- html
For details, see: https://dequeuniversity.com/rules/axe/3.2/document-title
Violation of "html-has-lang" with 1 occurrences!
Ensures every HTML document has a lang attribute. Correct invalid elements at:
- html
For details, see: https://dequeuniversity.com/rules/axe/3.2/html-has-lang
Violation of "landmark-one-main" with 1 occurrences!
Ensures the document has only one main landmark and each iframe in the page has at most one main landmark. Correct invalid elements at:
- html
For details, see: https://dequeuniversity.com/rules/axe/3.2/landmark-one-main
Violation of "page-has-heading-one" with 1 occurrences!
Ensure that the page, or at least one of its frames contains a level-one heading. Correct invalid elements at:
- html
For details, see: https://dequeuniversity.com/rules/axe/3.2/page-has-heading-one
4 Accessibility issues detected.
Saved file at /Users/stevenlambert/deque/axe-cli/testlog.json
Please note that only 20% to 50% of all accessibility issues can automatically be detected.
Manual testing is always required. For more information see:
https://dequeuniversity.com/curriculum/courses/testingmethods
// axe/index.js:
console.log(
` http://localhost:3000 --timeout=${axeconfig.timeout} --save ${
axeconfig.fileName
} ${axeconfig.tags.length ? `--tags ${axeconfig.tags}` : ''}`
);
// package.json:
"accessibility:test": "axe $(node axe/index.js)"
Running axe-core 3.3.2 in chrome-headless
DevTools listening on ws://127.0.0.1:58280/devtools/browser/88f47308-7229-433b-9c00-aeea62ca637a
Testing **http://$(node** ... please wait, this may take a minute.
Violation of "document-title" with 1 occurrences!
Ensures each HTML document contains a non-empty <title> element. Correct invalid elements at:
- html
For details, see: https://dequeuniversity.com/rules/axe/3.3/document-title
Violation of "html-has-lang" with 1 occurrences!
Ensures every HTML document has a lang attribute. Correct invalid elements at:
- html
For details, see: https://dequeuniversity.com/rules/axe/3.3/html-has-lang
Violation of "landmark-one-main" with 1 occurrences!
Ensures the document has only one main landmark and each iframe in the page has at most one main landmark. Correct invalid elements at:
- html
For details, see: https://dequeuniversity.com/rules/axe/3.3/landmark-one-main
Violation of "page-has-heading-one" with 1 occurrences!
Ensure that the page, or at least one of its frames contains a level-one heading. Correct invalid elements at:
- html
For details, see: https://dequeuniversity.com/rules/axe/3.3/page-has-heading-one
4 Accessibility issues detected.
Testing **http://axe/index.js)** ... please wait, this may take a minute.
Violation of "document-title" with 1 occurrences!
Ensures each HTML document contains a non-empty <title> element. Correct invalid elements at:
- html
For details, see: https://dequeuniversity.com/rules/axe/3.3/document-title
Violation of "html-has-lang" with 1 occurrences!
Ensures every HTML document has a lang attribute. Correct invalid elements at:
- html
For details, see: https://dequeuniversity.com/rules/axe/3.3/html-has-lang
Violation of "landmark-one-main" with 1 occurrences!
Ensures the document has only one main landmark and each iframe in the page has at most one main landmark. Correct invalid elements at:
- html
For details, see: https://dequeuniversity.com/rules/axe/3.3/landmark-one-main
Violation of "page-has-heading-one" with 1 occurrences!
Ensure that the page, or at least one of its frames contains a level-one heading. Correct invalid elements at:
- html
For details, see: https://dequeuniversity.com/rules/axe/3.3/page-has-heading-one
4 Accessibility issues detected.
Testing complete of 2 pages
Please note that only 20% to 50% of all accessibility issues can automatically be detected.
Manual testing is always required. For more information see:
https://dequeuniversity.com/curriculum/courses/testingmethods
I just realize that if I run axe $(node axe/index.js) in the console the tests works fine, but if I run it in the console trough npm run accessibility:test it gives me the above problem. I don´t know how to solve it 😕