|
| 1 | +<div align="center"> |
| 2 | + <a href="https://github.com/SimplrJS"> |
| 3 | + <img width="200" src="https://user-images.githubusercontent.com/7989797/27446299-b93aa76c-5785-11e7-8ef6-475f858e3291.png" /> |
| 4 | + </a> |
| 5 | +</div> |
| 6 | +<h1 align="center">test-generator-cli</h1> |
| 7 | + |
| 8 | +Tool to generate tests from cases. |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
| 12 | +```sh |
| 13 | +npm install @simplrjs/test-generator-cli -g |
| 14 | +``` |
| 15 | + |
| 16 | +Global installation is not necessary. You can install this package with: |
| 17 | + |
| 18 | +```sh |
| 19 | +npm install @simplrjs/test-generator-cli --save-dev |
| 20 | +``` |
| 21 | + |
| 22 | +and use it with [`npm-scripts`](https://docs.npmjs.com/misc/scripts). |
| 23 | + |
| 24 | +## Command line |
| 25 | + |
| 26 | +### Usage |
| 27 | + |
| 28 | +```sh |
| 29 | +test-generator-cli -h |
| 30 | +``` |
| 31 | + |
| 32 | +### Arguments |
| 33 | + |
| 34 | +| Argument | Type | Default | Description | |
| 35 | +|-------------------------------|-----------|---------------------------|-------------------------------------------------------------------------------| |
| 36 | +| -h, --help | boolean | `false` | Show help. | |
| 37 | +| -v, --version | boolean | `false` | Show current version. | |
| 38 | +| -p, --project | string | `./` | Project directory path. | |
| 39 | + |
| 40 | +### Project tests structure |
| 41 | + |
| 42 | +Let's say you picked `src` as your project directory. |
| 43 | + |
| 44 | +```bash |
| 45 | +├── src |
| 46 | + └── tests |
| 47 | + ├── cases |
| 48 | + │ ├── __tests__ |
| 49 | + │ | └── __snapshots__ |
| 50 | + │ ├── case-1 |
| 51 | + │ │ ├── ... |
| 52 | + │ │ ├── test-config.json |
| 53 | + │ │ └── case.test.tpl |
| 54 | + │ └── case-2 |
| 55 | + └── default.test.tpl |
| 56 | +``` |
| 57 | + |
| 58 | +| File / Directory | Description | |
| 59 | +|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 60 | +| `__tests__` | Generated tests output directory. | |
| 61 | +| `__snapshots__` | Generated tests snapshots directory. | |
| 62 | +| `case-1`, `case-2` | Directories for test cases. | |
| 63 | +| `case.test.tpl` | Test template file for certain test case. It's not required. If `case.test.tpl` not found in case directory, test template will fallback to `default.test.tpl`. | |
| 64 | +| `test-config.json` | Config file for a test case. You can reach it template. Config structure is at your discretion. | |
| 65 | +| `default.test.tpl` | Default test template file. | |
| 66 | + |
| 67 | +### Templates |
| 68 | + |
| 69 | +Package supports two kinds of templates: |
| 70 | + |
| 71 | +* `case.test.tpl` - test template file for certain test case. It's not required. If `case.test.tpl` not found in case directory, test template will fallback to `default.test.tpl`. |
| 72 | +* `default.test.tpl` - default test template file. |
| 73 | + |
| 74 | +Template should be a valid TypeScript file that can have [Handlebars](http://handlebarsjs.com/) expressions. |
| 75 | + |
| 76 | +#### Supported expressions |
| 77 | + |
| 78 | +| Expression | Description | |
| 79 | +|-------------------------|-------------------------------------------------------| |
| 80 | +| `{{caseName}}` | Test case name. | |
| 81 | +| `{{projectDirectory}}` | Project directory path. | |
| 82 | +| `{{json testConfig}}` | Test case config file (`test-config.json`) content. | |
| 83 | + |
| 84 | +#### Sample |
| 85 | + |
| 86 | +``` |
| 87 | +import * as path from "path"; |
| 88 | +import { Bundler } from "@src/bundler"; |
| 89 | +
|
| 90 | +test("{{caseName}}", async done => { |
| 91 | + const projectDirectory = "{{projectDirectory}}"; |
| 92 | + const testConfig = {{{json testConfig}}}; |
| 93 | + const entryFile = path.join(projectDirectory, testConfig.Entry); |
| 94 | +
|
| 95 | + try { |
| 96 | + const bundleResult = await new Bundler() |
| 97 | + .BundleAll([entryFile]); |
| 98 | + expect(bundleResult[0].bundledContent).toMatchSnapshot(); |
| 99 | + done(); |
| 100 | + } catch (error) { |
| 101 | + done.fail(error); |
| 102 | + } |
| 103 | +}); |
| 104 | +``` |
| 105 | + |
| 106 | +## License |
| 107 | + |
| 108 | +Released under the [MIT license](LICENSE). |
0 commit comments