html-attribute-checker
v1.0.0
Published
Small internal utility created to check for the existance of ID attributes on certain elements in Angular project
Downloads
4
Readme
HMTL Attribute Checker
Internal utility too created to check attributes exist on certain element. Useful if you require every element having a unique ID for E2E testing.
Example usage (from within project root):
$ html-attribute-checker --config=/Test/attribute.config.js
Options
The HTML attribute checker comes with its own limited set of options to configure. Look at the attribute.config.js
see the different options.
Hierarchy of config:
- Command line flags e.g
--config=config.js
- Looks for
attribute.config.js
at the root of the project - Internal default config
| Option | Description | Values |
|--------------------|-------------------------------------------------------------------------------------------------------------------------|--------------------------------|
| log | Console feedback log levels for when a file is being processed, passes and fails. Can be multiple if you want feedback on everything. | ['runs', 'success', 'error']
|
| failThreshold | Number of allowed missing IDs before the script throws an error | number |
| srcDir | Source directory/file to run the script on (accepts globs) | string | string[] |
| filesIgnorePattern | Files / folders to ignore (accepts globs) | string | string[] |
| requiredAttributes | Attribute to check | 'id'
|
| checkableElements | HTML elements to check for missing attribute | |
Example config
module.exports = {
log: ['error'],
failThreshold: 20,
srcDir: 'src/app',
filesIgnorePattern: [
'src/app/shared',
],
requiredAttributes: 'id',
checkableElements: {
'div': true,
},
};
Using the tool
Default
By default the tool will use the configuration to determine what files to check and how to check them.
$ html-attribute-checker
Custom config
It is possible to provide a config file to use via the command line. This will run the tool the same as the default above.
$ html-attribute-checker --config=myconfig.js
Custom threshold
You can change the fail threshold from the command line if you wish that run to be different to what is configured in the config file.
$ html-attribute-checker --threshold=3
Custom files and/or folders
It's possible to tell the tool which files or folders you want to run on without having to edit the config file. All you need to do is pass the file/folder which you want to test as an argument.
Folder (This will test all HTML inside the folder included nested directories)
$ html-attribute-checker src/app/example
Single file
$ html-attribute-checker src/app/example/feature.html
Multiple files
$ html-attribute-checker src/app/example/feature.html src/app/example/request.html
Mixed files and folders
$ html-attribute-checker src/app/example src/app/test/test.html