Skip to content

Commit 5bfbbba

Browse files
committed
chore: cleanup and leverage await rather than timeouts
1 parent c6dbdc1 commit 5bfbbba

File tree

3 files changed

+19
-27
lines changed

3 files changed

+19
-27
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,13 +1234,16 @@ yarn add winston
12341234

12351235
## Run Tests
12361236

1237-
All of the winston tests are written with [`mocha`][mocha], [`nyc`][nyc], and
1238-
[`assume`][assume]. They can be run with `npm`.
1239-
12401237
``` bash
1241-
npm test
1238+
npm test # Runs all tests
1239+
npm run test:unit # Runs all Unit tests with coverage
1240+
npm run test:test # Runs all integration tests
1241+
npm run test:test # Runs all integration tests
1242+
npm run typescript:test # Runs tests verifying Typescript types
12421243
```
12431244

1245+
All of the winston tests are written with [`jest`][jest]. Assertions use a mix of [`assume`][assume] and the built-in jest assertion library.
1246+
12441247
#### Author: [Charlie Robbins]
12451248
#### Contributors: [Jarrett Cruger], [David Hyde], [Chris Alderson]
12461249

@@ -1254,8 +1257,6 @@ npm test
12541257

12551258
[RFC5424]: https://tools.ietf.org/html/rfc5424
12561259
[util.format]: https://nodejs.org/dist/latest/docs/api/util.html#util_util_format_format_args
1257-
[mocha]: https://mochajs.org
1258-
[nyc]: https://github.com/istanbuljs/nyc
12591260
[assume]: https://github.com/bigpipe/assume
12601261
[logform]: https://github.com/winstonjs/logform#readme
12611262
[winston-transport]: https://github.com/winstonjs/winston-transport
@@ -1268,4 +1269,4 @@ npm test
12681269
[Charlie Robbins]: http://github.com/indexzero
12691270
[Jarrett Cruger]: https://github.com/jcrugzz
12701271
[David Hyde]: https://github.com/dabh
1271-
[Chris Alderson]: https://github.com/chrisalderson
1272+
[Chris Alderson]: https://github.com/chrisalderson

test/unit/winston/transports/00-file-stress.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ describe('File (stress)', function () {
150150
});
151151
}, 10000);
152152
});
153-
153+
154154
it('should handle a high volume of writes with lazy option enabled', function (done) {
155155
const logger = winston.createLogger({
156156
transports: [

test/unit/winston/transports/file.test.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const testLogFixturesPath = path.join(__dirname, '..', '..', '..', 'fixtures', '
1010

1111
const { MESSAGE } = require('triple-beam');
1212

13-
function removeFixtures() {
14-
rimraf(path.join(testLogFixturesPath, 'test*'), { glob: true });
13+
async function removeFixtures() {
14+
await rimraf(path.join(testLogFixturesPath, 'test*'), { glob: true });
1515
}
1616
function getFilePath(filename) {
1717
return path.join(testLogFixturesPath, filename);
@@ -55,16 +55,15 @@ describe('File Transport', function () {
5555
const logPayload = { level: 'info', [MESSAGE]: kbStr };
5656
transport.log(logPayload);
5757
}
58-
await new Promise(resolve => setTimeout(resolve, 50));
58+
await new Promise(resolve => setTimeout(resolve, 100));
5959
}
60-
beforeEach(() => {
61-
removeFixtures();
60+
61+
beforeEach(async () => {
62+
await removeFixtures();
6263
});
6364

6465
afterEach(async () => {
65-
removeFixtures();
66-
// Allow time for file system operations to complete
67-
await new Promise(resolve => setTimeout(resolve, 500));
66+
await removeFixtures();
6867
});
6968

7069
describe('Filename Option', function () {
@@ -92,8 +91,6 @@ describe('File Transport', function () {
9291

9392
await logKbytesToTransport(transport, 4);
9493

95-
await new Promise(resolve => setTimeout(resolve, 50));
96-
9794
assertFileExists('testarchive.log');
9895
assertFileExists('testarchive_.log');
9996
});
@@ -151,9 +148,6 @@ describe('File Transport', function () {
151148
await logKbytesToTransport(transport, 4, 'B');
152149
await logKbytesToTransport(transport, 4, 'C');
153150

154-
// Give file system operations time to complete archiving
155-
await new Promise(resolve => setTimeout(resolve, 500));
156-
157151
// Verify the expected files exist and their contents are correct
158152
assertFileExists('testarchive.log');
159153
assertFileExists('testarchive1.log');
@@ -164,7 +158,7 @@ describe('File Transport', function () {
164158
assertFileContentsStartWith('testarchive.log');
165159
assertFileContentsStartWith('testarchive1.log', 'C');
166160
assertFileContentsStartWith('testarchive2.log', 'B');
167-
// TODO: I would expect the first file that was rolled to be filled with the first log message
161+
// FIX: I would expect the first file that was rolled to be filled with the first log message
168162
// assertFileContentsStartWith('testarchive3.log', 'A');
169163
});
170164

@@ -179,9 +173,6 @@ describe('File Transport', function () {
179173
await logKbytesToTransport(transport, 4, 'B');
180174
await logKbytesToTransport(transport, 4, 'C');
181175

182-
// Give file system operations time to complete archiving
183-
await new Promise(resolve => setTimeout(resolve, 500));
184-
185176
// Verify the expected files exist
186177
assertFileExists('testarchive.log');
187178
assertFileExists('testarchive1.log');
@@ -190,7 +181,7 @@ describe('File Transport', function () {
190181

191182
// Verify the contents of the files are in the expected order
192183
assertFileContentsStartWith('testarchive.log');
193-
// TODO: only two of the files are filled and are not in the expected order
184+
// FIX: only two of the files are filled and are not in the expected order
194185
// assertFileContentsStartWith('testarchive1.log', 'A');
195186
// assertFileContentsStartWith('testarchive2.log', 'B');
196187
// assertFileContentsStartWith('testarchive3.log', 'C');
@@ -232,7 +223,7 @@ describe('File Transport', function () {
232223
});
233224

234225

235-
// TODO: Rewrite these tests in mocha
226+
// TODO: Reintroduce these tests
236227
//
237228
// "Error object in metadata #610": {
238229
// topic: function () {

0 commit comments

Comments
 (0)