xunit.ts 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +137 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+

|
|
2
|
+
# xunit.ts
|
|
3
|
+
### A TypeScript unit testing framework, following standard xUnit patterns
|
|
4
|
+
|
|
5
|
+
[](https://npmjs.com/package/xunit.ts)
|
|
6
|
+
[](https://github.com/ecoAPM/xunit.ts/actions)
|
|
7
|
+
[](https://sonarcloud.io/dashboard?id=ecoAPM_xunit.ts)
|
|
8
|
+
|
|
9
|
+
[](https://sonarcloud.io/dashboard?id=ecoAPM_xunit.ts)
|
|
10
|
+
[](https://sonarcloud.io/dashboard?id=ecoAPM_xunit.ts)
|
|
11
|
+
[](https://sonarcloud.io/dashboard?id=ecoAPM_xunit.ts)
|
|
12
|
+
|
|
13
|
+
## Documentation
|
|
14
|
+
|
|
15
|
+
Detailed documentation is available at https://ecoAPM.github.io/xunit.ts
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
### Requirements
|
|
20
|
+
|
|
21
|
+
- Node.js 16
|
|
22
|
+
|
|
23
|
+
(older versions may work, but only the latest LTS is actively supported)
|
|
24
|
+
|
|
25
|
+
### Installation
|
|
26
|
+
|
|
27
|
+
`npm install --dev xunit.ts`
|
|
28
|
+
|
|
29
|
+
or
|
|
30
|
+
|
|
31
|
+
`yarn add --dev xunit.ts`
|
|
32
|
+
|
|
33
|
+
### Configure your test project
|
|
34
|
+
|
|
35
|
+
At a minimum, your `tsconfig.json` will require the following:
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"compilerOptions": {
|
|
40
|
+
"target": "ES2015", //or "ES6"
|
|
41
|
+
"module": "CommonJS",
|
|
42
|
+
"experimentalDecorators": true
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
If you're using `rollup` or `vite`, you'll need to set `xunit.ts` as an `external` in your build config file (under `rollupOptions` in `vite`) for the tests to be detected.
|
|
48
|
+
|
|
49
|
+
### Create your first test
|
|
50
|
+
|
|
51
|
+
`MyTestSuite.ts`:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { Test, TestSuite } from 'xunit.ts';
|
|
55
|
+
|
|
56
|
+
export default class MyTestSuite extends TestSuite {
|
|
57
|
+
@Test()
|
|
58
|
+
async MyFirstTest() {
|
|
59
|
+
this.assert.equal(2, 1 + 1);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Run your tests
|
|
65
|
+
|
|
66
|
+
You'll need to compile your TypeScript tests into JavaScript using `tsc` or a bundler such as `rollup`, `parcel`, `vite`, etc. (these are the supported ones, feel free to add your favorite to the `compiler-tests` directory!)
|
|
67
|
+
|
|
68
|
+
Then run:
|
|
69
|
+
|
|
70
|
+
`npm run xunit compiled_tests_dir`
|
|
71
|
+
|
|
72
|
+
or
|
|
73
|
+
|
|
74
|
+
`yarn xunit compiled_tests_dir`
|
|
75
|
+
|
|
76
|
+
to run the tests.
|
|
77
|
+
|
|
78
|
+
You can also run `xunit.ts` from a script in your `package.json`:
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"scripts": {
|
|
83
|
+
"test": "tsc --outDir compiled_tests_dir && xunit compiled_tests_dir"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
#### Filtering tests
|
|
89
|
+
|
|
90
|
+
The `xunit` command can take one or more `--filter` flags (`-f` alias) followed by a regular expression to match `TestSuiteName.TestMethodName`. See the [full documentation](https://ecoAPM.github.io/xunit.ts) for more details.
|
|
91
|
+
|
|
92
|
+
## Output
|
|
93
|
+
|
|
94
|
+
### Console
|
|
95
|
+
|
|
96
|
+
By default, `xunit.ts` will output test results to `stdout` so they can be captured by your terminal, or piped elsewhere:
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
~/example $ npm run test
|
|
100
|
+
|
|
101
|
+
My Test Suite
|
|
102
|
+
✓ My First Test
|
|
103
|
+
|
|
104
|
+
Passed: 1
|
|
105
|
+
Total: 1
|
|
106
|
+
|
|
107
|
+
~/example $ _
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Results can also be output in JUnit and Sonar XML formats, for import into other systems. See the [full documentation](https://ecoAPM.github.io/xunit.ts) for a list of all available output options.
|
|
111
|
+
|
|
112
|
+
## Assertions
|
|
113
|
+
|
|
114
|
+
`xunit.ts` has a built-in assertion library, accessible via `this.assert...` from within a `TestSuite`, or you can use your favorite third-party one: anything that uses Node.js' `AssertionError` is supported.
|
|
115
|
+
|
|
116
|
+
If you prefer, you can `import { Assert } from 'xunit.ts` and call e.g. `Assert.true(expression);` instead of `this.assert.true(expression);` for any included assertion.
|
|
117
|
+
|
|
118
|
+
See the [full documentation](https://ecoAPM.github.io/xunit.ts) for a list of all available assertions.
|
|
119
|
+
|
|
120
|
+
## Contributing
|
|
121
|
+
|
|
122
|
+
Please be sure to read and follow ecoAPM's [Contribution Guidelines](CONTRIBUTING.md) when submitting issues or pull requests.
|
|
123
|
+
|
|
124
|
+
### Building / Testing locally
|
|
125
|
+
|
|
126
|
+
From the `core` directory:
|
|
127
|
+
1. `npm install` or `yarn install` to download all dependencies
|
|
128
|
+
2. `npm run build` or `yarn build` will compile `xunit.ts` and its tests to the `dist` directory
|
|
129
|
+
3. `npm run test` or `yarn test` will run all unit tests in `dist/tests`
|
|
130
|
+
4. `npm run build && npm run test` or `yarn build && yarn test` will build and run tests in a single step
|
|
131
|
+
|
|
132
|
+
### Missing an assertion?
|
|
133
|
+
|
|
134
|
+
Create an issue or submit a pull request!
|
|
135
|
+
1. Add a new function to `core/src/Assertions`
|
|
136
|
+
2. Add tests for both the positive and negative cases in `core/tests/Assertions`
|
|
137
|
+
3. Add a field for the assertion to `core/src/Assertions/index.ts`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xunit.ts",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "A unit testing framework for TypeScript, following standard xUnit patterns",
|
|
5
5
|
"main": "dist/xunit.js",
|
|
6
6
|
"author": "ecoAPM LLC",
|
|
@@ -37,4 +37,4 @@
|
|
|
37
37
|
"bin": {
|
|
38
38
|
"xunit": "dist/cli.js"
|
|
39
39
|
}
|
|
40
|
-
}
|
|
40
|
+
}
|