Commit 2e9eb18
authored
chore: migrate test runner from mocha to jest (#2567)
# Migrate Winston Test Suite from Mocha to Jest
This PR fully migrates Winston's test suite from Mocha to Jest to provide a more fully featured testing framework
> [!WARNING]
> The File Transport tests while passing in their current form, illustrate in my opinion
some potential issues in how it currently functions.
> - You can see the `FIX:` comments on a couple of assertions that I presume are correct but are currently failing.
> - The intersection of behavior with with the `maxsize` and `lazy` options result in behavior I found unexpected. e.g. If the rotation is not lazy, it will drop a log file resulting in 1 less populated log file than I would expect
> - The maxsize option appears not to be strictly enforced on a per-file basis. This is probably desirable as in maxsize is likely on a best effort basis. I make this presumption given we wouldn't want to split a log payload across two files, nor do I think we should truncate it. The documentation for the Transport does not state either way though so look to someone with more familiarity than I about original intent.d
## Summary
- Refactored failing tests to be Jest-compatible
- Primarily this was just modify `before()`, `after()`, `this.timeout()` to `beforeAll()`, `afterAll()`, and `jest.setTimeout()`
- Moved the `winston.test.js` from `integration` to `unit`. This felt more appropriate given the contents of the test.
- Refactored some tests for clarity or to resolve testing framework incompatabilities
- Jest intercepts all stderr and pipes to stdout, so some tests have been updated to rely on Spies of `console.error`
- Introduce async/await in some tests to reduce function nesting.
- Combine File Archive tests and remove tests that I felt were redundant. This ensures these tests run sequentially as they're in the same file. This helps to avoid the potential of race conditions. Further improvements could likely be made here. Lastly these are not what I would label as unit tests and would likely advocate moving them to the `integration` suite given they're actually writing files to the FS.
## Test Plan
- All tests are passing in CI environment
- Manual verification of test coverage shows equivalent or better coverage compared to Mocha
- Verified file system tests properly clean up temporary files
- Confirmed logging tests produce expected output formats1 parent 4dc03d6 commit 2e9eb18
File tree
38 files changed
+8646
-8271
lines changed- .github/workflows
- lib/winston
- test
- helpers
- scripts
- integration
- unit/winston
- config
- transports
38 files changed
+8646
-8271
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
2 | 5 | | |
3 | 6 | | |
4 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| 35 | + | |
34 | 36 | | |
35 | 37 | | |
| 38 | + | |
36 | 39 | | |
37 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
38 | 45 | | |
39 | 46 | | |
40 | | - | |
41 | | - | |
| 47 | + | |
42 | 48 | | |
43 | 49 | | |
44 | 50 | | |
45 | 51 | | |
46 | 52 | | |
| 53 | + | |
47 | 54 | | |
48 | | - | |
| 55 | + | |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1234 | 1234 | | |
1235 | 1235 | | |
1236 | 1236 | | |
1237 | | - | |
1238 | | - | |
1239 | | - | |
1240 | 1237 | | |
1241 | | - | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
1242 | 1242 | | |
1243 | 1243 | | |
| 1244 | + | |
| 1245 | + | |
1244 | 1246 | | |
1245 | | - | |
| 1247 | + | |
1246 | 1248 | | |
1247 | 1249 | | |
1248 | 1250 | | |
| |||
1254 | 1256 | | |
1255 | 1257 | | |
1256 | 1258 | | |
1257 | | - | |
1258 | | - | |
1259 | 1259 | | |
1260 | 1260 | | |
1261 | 1261 | | |
| 1262 | + | |
1262 | 1263 | | |
1263 | 1264 | | |
1264 | 1265 | | |
| |||
1268 | 1269 | | |
1269 | 1270 | | |
1270 | 1271 | | |
1271 | | - | |
| 1272 | + | |
| 1273 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
0 commit comments