xunit.ts 1.2.0 → 1.3.0

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.
Files changed (2) hide show
  1. package/README.md +144 -0
  2. package/package.json +7 -7
package/README.md ADDED
@@ -0,0 +1,144 @@
1
+ ![xunit.ts logo](docs/assets/logo.png)
2
+ # xunit.ts
3
+ ### A TypeScript unit testing framework, following standard xUnit patterns
4
+
5
+ [![npm version](https://img.shields.io/npm/v/xunit.ts?logo=npm&label=Install)](https://npmjs.com/package/xunit.ts)
6
+ [![CI status](https://github.com/ecoAPM/xunit.ts/workflows/CI/badge.svg)](https://github.com/ecoAPM/xunit.ts/actions)
7
+ [![Code Coverage](https://sonarcloud.io/api/project_badges/measure?project=ecoAPM_xunit.ts&metric=coverage)](https://sonarcloud.io/dashboard?id=ecoAPM_xunit.ts)
8
+
9
+ [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=ecoAPM_xunit.ts&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=ecoAPM_xunit.ts)
10
+ [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=ecoAPM_xunit.ts&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=ecoAPM_xunit.ts)
11
+ [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=ecoAPM_xunit.ts&metric=security_rating)](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 14, 16, 18
22
+
23
+ (other versions may work, but only the latest minor release for each LTS version is actively supported)
24
+
25
+ - A supported TypeScript compiler
26
+ - TypeScript 4
27
+ - Vite 2
28
+ - Rollup 2
29
+ - Parcel 1
30
+ - Webpack 5
31
+
32
+ ### Installation
33
+
34
+ `npm install --dev xunit.ts`
35
+
36
+ or
37
+
38
+ `yarn add --dev xunit.ts`
39
+
40
+ ### Configure your test project
41
+
42
+ At a minimum, your `tsconfig.json` will require the following:
43
+
44
+ ```json
45
+ {
46
+ "compilerOptions": {
47
+ "target": "ES2015", //or "ES6"
48
+ "module": "CommonJS",
49
+ "experimentalDecorators": true
50
+ }
51
+ }
52
+ ```
53
+
54
+ If you're using a bundler, you'll need to declare `xunit.ts` as an `external` in your build config file for the tests to be detected. See the [officially-supported configurations](https://github.com/ecoAPM/xunit.ts/tree/main/compiler-tests) in the `compiler-tests` directory of the source code for detailed examples.
55
+
56
+ ### Create your first test
57
+
58
+ `MyTestSuite.ts`:
59
+
60
+ ```ts
61
+ import { Test, TestSuite } from 'xunit.ts';
62
+
63
+ export default class MyTestSuite extends TestSuite {
64
+ @Test()
65
+ async MyFirstTest() {
66
+ this.assert.equal(2, 1 + 1);
67
+ }
68
+ }
69
+ ```
70
+
71
+ ### Run your tests
72
+
73
+ You'll first need to compile your TypeScript tests into JavaScript using `tsc` or the supported bundler of your choice.
74
+
75
+ Then run:
76
+
77
+ `npm run xunit compiled_tests_dir`
78
+
79
+ or
80
+
81
+ `yarn xunit compiled_tests_dir`
82
+
83
+ to run the tests.
84
+
85
+ You can also run `xunit.ts` from a script in your `package.json`:
86
+
87
+ ```json
88
+ {
89
+ "scripts": {
90
+ "test": "tsc --outDir compiled_tests_dir && xunit compiled_tests_dir"
91
+ }
92
+ }
93
+ ```
94
+
95
+ #### Filtering tests
96
+
97
+ 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.
98
+
99
+ ## Output
100
+
101
+ ### Console
102
+
103
+ By default, `xunit.ts` will output test results to `stdout` so they can be captured by your terminal, or piped elsewhere:
104
+
105
+ ```
106
+ ~/example $ npm run test
107
+
108
+ My Test Suite
109
+ ✓ My First Test
110
+
111
+ Passed: 1
112
+ Total: 1
113
+
114
+ ~/example $ _
115
+ ```
116
+
117
+ 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.
118
+
119
+ ## Assertions
120
+
121
+ `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.
122
+
123
+ 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.
124
+
125
+ See the [full documentation](https://ecoAPM.github.io/xunit.ts) for a list of all available assertions.
126
+
127
+ ## Contributing
128
+
129
+ Please be sure to read and follow ecoAPM's [Contribution Guidelines](CONTRIBUTING.md) when submitting issues or pull requests.
130
+
131
+ ### Building / Testing locally
132
+
133
+ From the `core` directory:
134
+ 1. `npm install` or `yarn install` to download all dependencies
135
+ 2. `npm run build` or `yarn build` will compile `xunit.ts` and its tests to the `dist` directory
136
+ 3. `npm run test` or `yarn test` will run all unit tests in `dist/tests`
137
+ 4. `npm run build && npm run test` or `yarn build && yarn test` will build and run tests in a single step
138
+
139
+ ### Missing an assertion?
140
+
141
+ Create an issue or submit a pull request!
142
+ 1. Add a new function to `core/src/Assertions`
143
+ 2. Add tests for both the positive and negative cases in `core/tests/Assertions`
144
+ 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.0",
3
+ "version": "1.3.0",
4
4
  "description": "A unit testing framework for TypeScript, following standard xUnit patterns",
5
5
  "main": "dist/xunit.js",
6
6
  "author": "ecoAPM LLC",
@@ -18,13 +18,13 @@
18
18
  "@types/command-line-args": "5.2.0",
19
19
  "@types/command-line-usage": "5.0.2",
20
20
  "@types/lodash.isequal": "4.5.6",
21
- "@types/node": "17.0.41",
21
+ "@types/node": "18.0.6",
22
22
  "@types/xml": "1.0.8",
23
- "@typescript-eslint/eslint-plugin": "5.27.1",
24
- "@typescript-eslint/parser": "5.27.1",
25
- "eslint": "8.17.0",
23
+ "@typescript-eslint/eslint-plugin": "5.30.7",
24
+ "@typescript-eslint/parser": "5.30.7",
25
+ "eslint": "8.20.0",
26
26
  "ts-mockito": "2.6.1",
27
- "typescript": "4.7.3"
27
+ "typescript": "4.7.4"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "typescript": "^4.0.0"
@@ -37,4 +37,4 @@
37
37
  "bin": {
38
38
  "xunit": "dist/cli.js"
39
39
  }
40
- }
40
+ }