To use Ponicode CLI on one specific source file, you can simply use:
ponicode test /path/to/your/source_file
If you want to add tests for a specific function, Ponicode CLI does it for you. To do so, simply run:
ponicode test --func mySuperFunction /path/to/source_file
You really want to go to the step further and add tests for multiples files?
To do so, you have multiple possibilities.
If you want to add test files for specific source files, you can specify which one only by adding them as arguments to the command, such as:
ponicode test src/utils.ts src/superFile.ts
Glob pattern (
Maybe you’re too lazy to write every single files in the command line, and want to use a glob pattern to fetch them all?
With Ponicode CLI, you can do it:
ponicode test src/**/*.ts
You may want data about your code and the tests generated?
You can generate it along the generated tests, and have it in a json file.
ponicode test src/utils.ts --json
By default, the JSON will be written in the current directory you’re executing the command. If you want to have it in a different location, simply specify it next to the
--json such as:
poniode test src/utils.ts --json report/poni-report.json
Note: You have to add the
--jsonoption to the end of the command.
If you want to test the capabilities of Ponicode CLI, but don’t want it to generate test files, you can run
ponicode with the option
--dry-run. To do so:
ponicode test --dry-run src/api/**.js
By default, Ponicode does not generate unit tests for functions that are not exported. If you would like Ponicode to use the dependency
rewire to unit test unexported functions, you can use the flag
-r when launching
ponicode test src/myFolder/myFile.ts --rewire
When using this flag, please keep in mind that:
rewiremight require additional configuration on your side for Jest to be able to run your tests.
Jestexcludes rewired tests from its coverage calculations