Skip to content

Commit cc192a7

Browse files
rudolf101tamarinvs19
authored andcommitted
Added JavaScript installation guide (#1583)
1 parent 62ebcaa commit cc192a7

File tree

2 files changed

+111
-87
lines changed

2 files changed

+111
-87
lines changed

docs/JavaScriptSupport.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# UnitTestBot JavaScript plugin setup
2+
3+
## How to start using UnitTestBot JavaScript
4+
5+
1. [Install](https://www.jetbrains.com/idea/download/) the latest version of IntelliJ IDEA Ultimate.
6+
2. [Install](https://plugins.jetbrains.com/plugin/19445-unittestbot) the latest version of UnitTestBot plugin.
7+
3. [Install](https://nodejs.org/en/download/) Node.js 10.0.0 or later. Add Node.js to environment variables for better experience.
8+
4. In your IntelliJ IDEA, go to **File** > **Settings** > **Tools** > **UnitTestBot** and enable **Experimental languages support**.
9+
5. Go to **File** > **Settings** > **Languages & Frameworks**, choose **Node.js** and check if the path to Node.js executable file is specified.
10+
6. In a JavaScript file, press **Alt+Shift+U** to open the generation dialog.
11+
12+
## Troubleshooting: _npm_ cannot install requirements
13+
14+
1. The system prohibits installation
15+
16+
Solution: run _cmd_ via `sudo` or with administrator access, run `npm install -g <missing requirement>`.
17+
18+
2. Node.js is missing, or _npm_ is not installed
19+
20+
Solution: install Node.js with default configuration from the official website.
21+
22+
# JavaScript Command Line Interface usage
23+
24+
## Build
25+
26+
JAR file can be built in [GitHub Actions](https://github.com/UnitTestBot/UTBotJava/actions/workflows/publish-plugin-and-cli-from-branch.yml) with the `publish-plugin-and-cli-from-branch` script.
27+
28+
## Requirements
29+
30+
* [Install](https://nodejs.org/en/download/) Node.js 10.0.0 or later
31+
* [Install](https://www.oracle.com/java/technologies/downloads/) Java 11 or later
32+
* Install _nyc_ 15.1.0 or later: `> npm install -g nyc`
33+
* Install Mocha 10.0.0 or later: `> npm install -g mocha`
34+
35+
## Basic usage
36+
37+
### Generate tests: `generate_js`
38+
39+
java -jar utbot-cli.jar generate_js --source="dir/file_with_sources.js" --output="dir/generated_tests.js"
40+
41+
This will generate tests for top-level functions from `file_with_sources.js`.
42+
43+
#### Options
44+
45+
- `-s, --source <path>`
46+
47+
_(required)_ Source code file for test generation.
48+
- `-c, --class <classname>`
49+
50+
Specifies the class to generate tests for.
51+
If not specified, tests for top-level functions or a single class are generated.
52+
53+
- `-o, --output <dir/filename>`
54+
55+
File for generated tests.
56+
- `-p, --print-test`
57+
58+
Specifies whether a test should be printed out to `StdOut` (default = false).
59+
- `-t, --timeout <seconds>`
60+
61+
Timeout for a single test case to generate: in seconds (default = 15).
62+
- `--coverage-mode <BASIC/FAST>`
63+
64+
Specifies the coverage mode for test generation (used for coverage-based optimization). For now, the fast mode cannot deal with exceeding timeouts, but works faster (default = FAST). Do not use the fast mode if you guess there might be infinite loops in your code.
65+
- `--path-to-node <path>`
66+
67+
Sets a path to Node.js executable (default = "node").
68+
- `--path-to-nyc <path>`
69+
70+
Sets a path to _nyc_ executable (default = "nyc").
71+
- `--path-to-npm <path>`
72+
73+
Sets a path to _npm_ executable (default = "npm").
74+
75+
### Run generated tests: `run_js`
76+
77+
java -jar utbot-cli.jar run_js --fileOrDir="generated_tests.js"
78+
79+
This will run generated tests from a file or directory.
80+
81+
#### Options
82+
83+
- `-f, --fileOrDir`
84+
85+
_(required)_ File or directory with tests.
86+
- `-o, --output`
87+
88+
Specifies the output TXT file for a test framework result (if empty, prints the result to `StdOut`).
89+
90+
- `-t, --test-framework <name>`
91+
92+
Test framework to use for test running (default = "Mocha").
93+
94+
### Generate a coverage report: `coverage_js`
95+
96+
java -jar utbot-cli.jar coverage_js --source=dir/generated_tests.js
97+
98+
This will generate a coverage report for generated tests and print it to `StdOut`.
99+
100+
#### Options
101+
102+
- `-s, --source <file>`
103+
104+
_(required)_ File with tests to generate a report for.
105+
106+
- `-o, --output`
107+
108+
Specifies the output JSON file for a coverage report (if empty, prints the report to `StdOut`).
109+
- `--path-to-nyc <path>`
110+
111+
Sets a path to _nyc_ executable (default = "nyc").

utbot-cli-js/src/README.md

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)