diff --git a/.travis.yml b/.travis.yml index 70533b4..9b3e798 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,8 @@ env: node_js: - "20" - "18" + - "16" + - "14" language: node_js script: "npm run coverage" diff --git a/.vscode/extensions.json b/.vscode/extensions.json index a8fd5ce..3f75051 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,3 +1,3 @@ { - "recommendations": ["dbaeumer.vscode-eslint", "eg2.vscode-npm-script", "esbenp.prettier-vscode", "myh.preview-vscode", "rohit-gohri.format-code-action", "streetsidesoftware.code-spell-checker"] + "recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "myh.preview-vscode", "rohit-gohri.format-code-action", "streetsidesoftware.code-spell-checker"] } diff --git a/.vscode/launch.json b/.vscode/launch.json index 26ee333..23631f6 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,8 +8,7 @@ "program": "${workspaceFolder}/node_modules/mocha/bin/mocha", "args": ["-r", "ts-node/register", "--timeout", "999999", "--colors", "${workspaceFolder}/test/*.ts"], "console": "integratedTerminal", - "internalConsoleOptions": "neverOpen", - "protocol": "inspector" + "internalConsoleOptions": "neverOpen" } ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 38c188b..0cf2521 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -11,13 +11,19 @@ "jvassev", "kbirger", "lcov", + "linebreak", + "nonblock", + "nonwords", "parens", + "pyues", "rakshith", "ravi", "reclose", "refinal", "ricci", - "wangao" + "satoshis", + "wangao", + "zmssi" ], "editor.codeActionsOnSave": ["source.formatDocument", "source.fixAll.eslint"], "editor.defaultFormatter": "esbenp.prettier-vscode", diff --git a/CHANGELOG.md b/CHANGELOG.md index 63225ff..21a0ba6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +- 2023-12-28 - v3.2.1 + - Restored support for **Node.js v14**. + - Badges (but dependents) from [shields.io](https://shields.io/). - 2023-12-27 - v3.2.0 - Added `intervalUTC` as [requested](https://github.com/iccicci/rotating-file-stream/issues/97). - 2023-07-22 - v3.1.1 diff --git a/README.md b/README.md index 2aaca09..5cde01d 100644 --- a/README.md +++ b/README.md @@ -16,18 +16,19 @@ [code-url]: https://codeclimate.com/github/iccicci/rotating-file-stream [cover-badge]: https://codeclimate.com/github/iccicci/rotating-file-stream/badges/coverage.svg [deps-badge]: https://badgen.net/npm/dependents/rotating-file-stream?icon=npm +[deps-badge2]: https://img.shields.io/librariesio/dependents/npm/rotating-file-stream?logo=npm [deps-url]: https://www.npmjs.com/package/rotating-file-stream?activeTab=dependents -[donate-badge]: https://badgen.net/badge/donate/bitcoin?icon=bitcoin +[donate-badge]: https://img.shields.io/static/v1?label=donate&message=bitcoin&color=blue&logo=bitcoin [donate-url]: https://blockchain.info/address/12p1p5q7sK75tPyuesZmssiMYr4TKzpSCN [github-url]: https://github.com/iccicci/rotating-file-stream -[npm-downloads-badge]: https://badgen.net/npm/dw/rotating-file-stream?icon=npm -[npm-badge]: https://badgen.net/npm/v/rotating-file-stream?color=green&icon=npm +[npm-downloads-badge]: https://img.shields.io/npm/dw/rotating-file-stream?logo=npm +[npm-badge]: https://img.shields.io/npm/v/rotating-file-stream?color=green&logo=npm [npm-url]: https://www.npmjs.com/package/rotating-file-stream -[stars-badge]: https://badgen.net/github/stars/iccicci/rotating-file-stream?icon=github +[stars-badge]: https://img.shields.io/github/stars/iccicci/rotating-file-stream?logo=github [stars-url]: https://github.com/iccicci/rotating-file-stream/stargazers -[travis-badge]: https://badgen.net/travis/iccicci/rotating-file-stream/master?icon=travis +[travis-badge]: https://img.shields.io/travis/com/iccicci/rotating-file-stream?logo=travis [travis-url]: https://app.travis-ci.com/github/iccicci/rotating-file-stream -[types-badge]: https://badgen.net/npm/types/rotating-file-stream?color=green&icon=typescript +[types-badge]: https://img.shields.io/static/v1?label=types&message=included&color=green&logo=typescript ### Description diff --git a/package-lock.json b/package-lock.json index b9e2dec..9cfcfa2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,7 @@ "typescript": "5.3.3" }, "engines": { - "node": ">=18.0" + "node": ">=14.0" }, "funding": { "url": "https://www.blockchain.com/btc/address/12p1p5q7sK75tPyuesZmssiMYr4TKzpSCN" diff --git a/package.json b/package.json index a29396e..275508b 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "logrotate" ], "engines": { - "node": ">=18.0" + "node": ">=14.0" }, "author": "Daniele Ricci (https://github.com/iccicci)", "contributors": [ diff --git a/test/02write.ts b/test/02write.ts index 1ff6c9d..c37bafe 100644 --- a/test/02write.ts +++ b/test/02write.ts @@ -3,13 +3,17 @@ import { deepStrictEqual as deq, strictEqual as eq } from "assert"; import { readFileSync } from "fs"; import { createStream } from ".."; -import { test } from "./helper"; +import { gte14, test, v14 } from "./helper"; + +export function v14Error(): { error?: string[] } { + return gte14 ? {} : { error: ["ERR_STREAM_DESTROYED"] }; +} describe("write(s)", () => { describe("single write", () => { const events = test({}, rfs => rfs.end("test\n")); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], write: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log"], write: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n")); }); @@ -20,7 +24,7 @@ describe("write(s)", () => { rfs.end("test\n"); }); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], write: 1, writev: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log"], write: 1, writev: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "test\ntest\ntest\ntest\n")); }); @@ -29,14 +33,14 @@ describe("write(s)", () => { rfs.end("test\n", "utf8", () => (events.endcb = true)); }); - it("events", () => deq(events, { close: 1, endcb: true, finish: 1, open: ["test.log"], write: 1 })); + it("events", () => deq(events, { endcb: true, finish: 1, open: ["test.log"], write: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n")); }); describe("write after open", function() { const events = test({}, rfs => rfs.once("open", () => rfs.end("test\n", "utf8"))); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], write: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log"], write: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n")); }); @@ -61,7 +65,7 @@ describe("write(s)", () => { stream.on("open", () => event(done)); }); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"] })); + it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], ...v14Error() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "")); }); @@ -73,7 +77,7 @@ describe("write(s)", () => { }) ); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"] })); + it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], ...v14Error() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "")); }); diff --git a/test/03size.ts b/test/03size.ts index c665577..dd31ed2 100644 --- a/test/03size.ts +++ b/test/03size.ts @@ -3,13 +3,13 @@ import { deepStrictEqual as deq, strictEqual as eq } from "assert"; import { readFileSync } from "fs"; import { sep } from "path"; -import { test } from "./helper"; +import { test, v14 } from "./helper"; describe("size", () => { describe("initial rotation", () => { const events = test({ files: { "test.log": "test\ntest\n" }, options: { size: "10B" } }, rfs => rfs.end("test\n")); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], rotated: ["1-test.log"], rotation: 1, write: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n")); it("rotated file content", () => eq(readFileSync("1-test.log", "utf8"), "test\ntest\n")); }); @@ -17,7 +17,7 @@ describe("size", () => { describe("single write rotation by size", () => { const events = test({ files: { "test.log": "test\n" }, options: { size: "10B" } }, rfs => rfs.end("test\n")); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "")); it("rotated file content", () => eq(readFileSync("1-test.log", "utf8"), "test\ntest\n")); }); @@ -29,7 +29,7 @@ describe("size", () => { rfs.end("test\n"); }); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, writev: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, writev: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n")); it("rotated file content", () => eq(readFileSync("1-test.log", "utf8"), "test\ntest\n")); }); @@ -41,7 +41,7 @@ describe("size", () => { rfs.end("test\n"); }); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, writev: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, writev: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n")); it("rotated file content", () => eq(readFileSync("1-test.log", "utf8"), "test\ntest\ntest\ntest\n")); }); @@ -55,7 +55,7 @@ describe("size", () => { rfs.end("test\n"); }); - it("events", () => deq(events, { close: 1, finish: 1, open: [filename, filename], rotated: [rotated], rotation: 1, write: 1, writev: 1 })); + it("events", () => deq(events, { finish: 1, open: [filename, filename], rotated: [rotated], rotation: 1, write: 1, writev: 1, ...v14() })); it("file content", () => eq(readFileSync(filename, "utf8"), "test\n")); it("rotated file content", () => eq(readFileSync(rotated, "utf8"), "test\ntest\n")); }); diff --git a/test/05options.ts b/test/05options.ts index 5d1363d..a5479ee 100644 --- a/test/05options.ts +++ b/test/05options.ts @@ -4,14 +4,14 @@ import { deepStrictEqual as deq, strictEqual as eq } from "assert"; import { gunzipSync } from "zlib"; import { readFileSync } from "fs"; import { sep } from "path"; -import { test } from "./helper"; +import { test, v14 } from "./helper"; describe("options", () => { describe("size KiloBytes", () => { let size: number; const events = test({ options: { size: "10K" } }, rfs => rfs.end("test\n", () => (size = rfs.options.size))); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], write: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log"], write: 1, ...v14() })); it("10K", () => eq(size, 10240)); }); @@ -19,7 +19,7 @@ describe("options", () => { let size: number; const events = test({ options: { size: "10M" } }, rfs => rfs.end("test\n", () => (size = rfs.options.size))); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], write: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log"], write: 1, ...v14() })); it("10M", () => eq(size, 10485760)); }); @@ -27,7 +27,7 @@ describe("options", () => { let size: number; const events = test({ options: { size: "10G" } }, rfs => rfs.end("test\n", () => (size = rfs.options.size))); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], write: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log"], write: 1, ...v14() })); it("10G", () => eq(size, 10737418240)); }); @@ -35,7 +35,7 @@ describe("options", () => { let interval: number; const events = test({ options: { interval: "3m" } }, rfs => rfs.end("test\n", () => (interval = rfs.options.interval))); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], write: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log"], write: 1, ...v14() })); it("3'", () => deq(interval, { num: 3, unit: "m" })); }); @@ -49,7 +49,7 @@ describe("options", () => { }) ); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], write: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log"], write: 1, ...v14() })); it("3h", () => deq(interval, { num: 3, unit: "h" })); it("hours daylight saving", () => eq(next - prev, 7200000)); }); @@ -64,7 +64,7 @@ describe("options", () => { }) ); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], write: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log"], write: 1, ...v14() })); it("3h", () => deq(interval, { num: 3, unit: "d" })); it("hours daylight saving", () => eq(next - prev, 255600000)); }); @@ -78,7 +78,7 @@ describe("options", () => { rfs.end("test\n"); }); - it("events", () => deq(events, { close: 1, finish: 1, open: [filename, filename], rotated: [rotated], rotation: 1, write: 1, writev: 1 })); + it("events", () => deq(events, { finish: 1, open: [filename, filename], rotated: [rotated], rotation: 1, write: 1, writev: 1, ...v14() })); it("file content", () => eq(readFileSync(filename, "utf8"), "test\n")); it("rotated file content", () => eq(readFileSync(rotated, "utf8"), "test\ntest\n")); }); @@ -92,7 +92,7 @@ describe("options", () => { rfs.end("test\n"); }); - it("events", () => deq(events, { close: 1, finish: 1, open: [filename, filename], rotated: [rotated], rotation: 1, write: 1, writev: 1 })); + it("events", () => deq(events, { finish: 1, open: [filename, filename], rotated: [rotated], rotation: 1, write: 1, writev: 1, ...v14() })); it("file content", () => eq(readFileSync(filename, "utf8"), "test\n")); it("rotated file content", () => eq(readFileSync(rotated, "utf8"), "test\ntest\n")); }); @@ -107,7 +107,7 @@ describe("options", () => { }); it("options", () => deq(options, { interval: { num: 1, unit: "d" }, path: "", rotate: 5, size: 10485760 })); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], write: 1, writev: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log"], write: 1, writev: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "test\ntest\ntest\n")); }); @@ -118,7 +118,7 @@ describe("options", () => { rfs.end("test\n"); }); - it("events", () => deq(events, { close: 1, finish: 1, open: ["log/1-test.log", "log/2-test.log"], rotated: ["log/1-test.log"], rotation: 1, write: 1, writev: 1 })); + it("events", () => deq(events, { finish: 1, open: ["log/1-test.log", "log/2-test.log"], rotated: ["log/1-test.log"], rotation: 1, write: 1, writev: 1, ...v14() })); it("first file content", () => eq(readFileSync("log/1-test.log", "utf8"), "test\ntest\n")); it("second file content", () => eq(readFileSync("log/2-test.log", "utf8"), "test\n")); }); @@ -131,7 +131,7 @@ describe("options", () => { rfs.end("test\n"); }); - it("events", () => deq(events, { close: 1, finish: 1, open: ["1-test.log", "2-test.log", "3-test.log"], rotated: ["1-test.log", "2-test.log"], rotation: 2, write: 1, writev: 1 })); + it("events", () => deq(events, { finish: 1, open: ["1-test.log", "2-test.log", "3-test.log"], rotated: ["1-test.log", "2-test.log"], rotation: 2, write: 1, writev: 1, ...v14() })); it("first file content", () => eq(readFileSync("1-test.log", "utf8"), "test\ntest\n")); it("second file content", () => eq(readFileSync("2-test.log", "utf8"), "test\ntest\n")); it("third file content", () => eq(readFileSync("3-test.log", "utf8"), "test\n")); @@ -147,7 +147,7 @@ describe("options", () => { rfs.end("test\n"); }); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, writev: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, writev: 1, ...v14() })); it("stdout", () => deq(content, [Buffer.from("test\n"), Buffer.from("test\n"), Buffer.from("test\n")])); it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n")); it("rotated file content", () => eq(readFileSync("1-test.log", "utf8"), "test\ntest\n")); @@ -163,7 +163,7 @@ describe("options", () => { rfs.end("test\n"); }); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, writev: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, writev: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n")); it("rotated file content", () => eq(gunzipSync(readFileSync("1-test.log")).toString(), "test\ntest\n")); }); diff --git a/test/06interval.ts b/test/06interval.ts index a7636df..455c420 100644 --- a/test/06interval.ts +++ b/test/06interval.ts @@ -2,7 +2,7 @@ import { deepStrictEqual as deq, strictEqual as eq } from "assert"; import { readFileSync } from "fs"; -import { test } from "./helper"; +import { test, v14 } from "./helper"; describe("interval", () => { describe("initial rotation with interval", () => { @@ -11,7 +11,7 @@ describe("interval", () => { rfs.end("test\n"); }); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], rotated: ["20150301-0000-01-test.log"], rotation: 1, write: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log"], rotated: ["20150301-0000-01-test.log"], rotation: 1, write: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n")); it("rotated file content", () => eq(readFileSync("20150301-0000-01-test.log", "utf8"), "test\ntest\n")); }); @@ -22,7 +22,7 @@ describe("interval", () => { rfs.end("test\n"); }); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log", "test.log"], rotated: ["20150329-0129-01-test.log"], rotation: 1, write: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log", "test.log"], rotated: ["20150329-0129-01-test.log"], rotation: 1, write: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "")); it("rotated file content", () => eq(readFileSync("20150329-0129-01-test.log", "utf8"), "test\ntest\n")); }); @@ -58,7 +58,7 @@ describe("interval", () => { } ); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], rotated: ["20150123-0000-01-test.log"], rotation: 1, write: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log"], rotated: ["20150123-0000-01-test.log"], rotation: 1, write: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n")); it("rotated file content", () => eq(readFileSync("20150123-0000-01-test.log", "utf8"), "test\n")); }); @@ -76,7 +76,7 @@ describe("interval", () => { } ); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log", "test.log"], rotated: ["20150329-0000-01-test.log"], rotation: 1, write: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log", "test.log"], rotated: ["20150329-0000-01-test.log"], rotation: 1, write: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "")); it("rotated file content", () => eq(readFileSync("20150329-0000-01-test.log", "utf8"), "test\ntest\n")); }); @@ -88,7 +88,7 @@ describe("interval", () => { rfs.once("rotation", () => rfs.end("test\n")); }); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n")); it("rotated file content", () => eq(readFileSync("1-test.log", "utf8"), "test\ntest\n")); }); @@ -103,7 +103,7 @@ describe("interval", () => { rfs.end("test\n"); }); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n")); it("rotated file content", () => eq(readFileSync("1-test.log", "utf8"), "test\ntest\n")); }); @@ -137,7 +137,7 @@ describe("interval", () => { }); it("events", () => - deq(events, { close: 1, finish: 1, open: ["test.log", "test.log", "test.log", "test.log"], rotated: ["1-test.log", "2-test.log", "3-test.log"], rotation: 3, write: 3, writev: 1 })); + deq(events, { finish: 1, open: ["test.log", "test.log", "test.log", "test.log"], rotated: ["1-test.log", "2-test.log", "3-test.log"], rotation: 3, write: 3, writev: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n")); it("rotated file content", () => eq(readFileSync("1-test.log", "utf8"), "test\ntest\n")); }); diff --git a/test/07compression.ts b/test/07compression.ts index 9498dc8..7fa3bb2 100644 --- a/test/07compression.ts +++ b/test/07compression.ts @@ -3,7 +3,7 @@ import { readFileSync } from "fs"; import { deepStrictEqual as deq, strictEqual as eq } from "assert"; import { gunzipSync } from "zlib"; -import { test } from "./helper"; +import { test, v14 } from "./helper"; describe("compression", () => { describe("external", () => { @@ -15,7 +15,7 @@ describe("compression", () => { rfs => rfs.end("test\ntest\n") ); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log/log", "test.log/log"], rotated: ["test.log/1"], rotation: 1, stderr: [""], stdout: [""], write: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log/log", "test.log/log"], rotated: ["test.log/1"], rotation: 1, stderr: [""], stdout: [""], write: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log/log", "utf8"), "")); it("rotated file content", () => eq(gunzipSync(readFileSync("test.log/1")).toString(), "test\ntest\n")); }); @@ -29,7 +29,7 @@ describe("compression", () => { rfs => rfs.end("test\ntest\n") ); - it("events", () => deq(events, { close: 1, error: [23], finish: 1, open: ["test.log/log"], rotation: 1, stderr: ["test.log/1\n"], stdout: ["test.log/log\n"], write: 1 })); + it("events", () => deq(events, { error: [23], finish: 1, open: ["test.log/log"], rotation: 1, stderr: ["test.log/1\n"], stdout: ["test.log/log\n"], write: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log/log", "utf8"), "test\ntest\n")); }); @@ -42,7 +42,7 @@ describe("compression", () => { rfs => rfs.end("test\ntest\n") ); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log", "test.log"], rotated: ["test1.log"], rotation: 1, stderr: [""], stdout: [""], write: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log", "test.log"], rotated: ["test1.log"], rotation: 1, stderr: [""], stdout: [""], write: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "")); it("rotated file content", () => eq(gunzipSync(readFileSync("test1.log")).toString(), "test\ntest\n")); }); @@ -53,7 +53,7 @@ describe("compression", () => { rfs.end("test\ntest\n"); }); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log", "test.log"], rotated: ["20150329-0129-01-test.log.gz"], rotation: 1, write: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log", "test.log"], rotated: ["20150329-0129-01-test.log.gz"], rotation: 1, write: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "")); it("rotated file content", () => eq(gunzipSync(readFileSync("20150329-0129-01-test.log.gz")).toString(), "test\ntest\n")); }); @@ -63,7 +63,7 @@ describe("compression", () => { rfs.end("test\ntest\n") ); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log", "test.log"], rotated: ["log/log/test.gz1"], rotation: 1, write: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log", "test.log"], rotated: ["log/log/test.gz1"], rotation: 1, write: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "")); it("rotated file content", () => eq(gunzipSync(readFileSync("log/log/test.gz1")).toString(), "test\ntest\n")); }); diff --git a/test/08classical.ts b/test/08classical.ts index c763f85..f62a17f 100644 --- a/test/08classical.ts +++ b/test/08classical.ts @@ -4,7 +4,7 @@ import { deepStrictEqual as deq, strictEqual as eq } from "assert"; import { readFileSync } from "fs"; import { gunzipSync } from "zlib"; import { sep } from "path"; -import { test } from "./helper"; +import { test, v14 } from "./helper"; describe("classical", function() { describe("classical generator", () => { @@ -13,7 +13,7 @@ describe("classical", function() { rfs.end("test\n"); }); - it("events", () => deq(events, { close: 1, finish: 1, open: ["log/test.log", "log/test.log"], rotated: ["log/test.log.1"], rotation: 1, write: 2 })); + it("events", () => deq(events, { finish: 1, open: ["log/test.log", "log/test.log"], rotated: ["log/test.log.1"], rotation: 1, write: 2, ...v14() })); it("file content", () => eq(readFileSync("log/test.log", "utf8"), "test\n")); it("rotated file content", () => eq(readFileSync("log/test.log.1", "utf8"), "test\ntest\n")); }); @@ -24,7 +24,7 @@ describe("classical", function() { rfs.end("test\n"); }); - it("events", () => deq(events, { close: 1, finish: 1, open: ["log/test.log", "log/test.log"], rotated: ["log/test.log.1.gz"], rotation: 1, write: 2 })); + it("events", () => deq(events, { finish: 1, open: ["log/test.log", "log/test.log"], rotated: ["log/test.log.1.gz"], rotation: 1, write: 2, ...v14() })); it("file content", () => eq(readFileSync("log/test.log", "utf8"), "test\n")); it("rotated file content", () => eq(gunzipSync(readFileSync("log/test.log.1.gz")).toString(), "test\ntest\n")); }); @@ -38,7 +38,7 @@ describe("classical", function() { } ); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log", "test.log"], rotated: ["1.test.log", "2.test.log"], rotation: 2, write: 2 })); + it("events", () => deq(events, { finish: 1, open: ["test.log", "test.log"], rotated: ["1.test.log", "2.test.log"], rotation: 2, write: 2, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "")); it("first rotated file content", () => eq(readFileSync("1.test.log", "utf8"), "test\ntest\n")); it("second rotated file content", () => eq(readFileSync("2.test.log", "utf8"), "test\ntest\n")); @@ -53,7 +53,7 @@ describe("classical", function() { }); it("events", () => - deq(events, { close: 1, finish: 1, open: ["test.log", "test.log", "test.log", "test.log"], rotated: ["1.test.log", "2.test.log", "2.test.log"], rotation: 3, write: 1, writev: 1 })); + deq(events, { finish: 1, open: ["test.log", "test.log", "test.log", "test.log"], rotated: ["1.test.log", "2.test.log", "2.test.log"], rotation: 3, write: 1, writev: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n")); it("first rotated file content", () => eq(readFileSync("1.test.log", "utf8"), "test\ntest\n")); it("second rotated file content", () => eq(readFileSync("2.test.log", "utf8"), "test\ntest\ntest\n")); @@ -65,7 +65,7 @@ describe("classical", function() { rfs.end("test\n"); }); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log", "test.log"], rotated: ["log/1.test.log"], rotation: 1, write: 2 })); + it("events", () => deq(events, { finish: 1, open: ["test.log", "test.log"], rotated: ["log/1.test.log"], rotation: 1, write: 2, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n")); it("rotated file content", () => eq(readFileSync("log/1.test.log", "utf8"), "test\ntest\n")); }); @@ -77,7 +77,7 @@ describe("classical", function() { rfs.end("test\n"); }); - it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log", "test.log", "test.log"], rotated: ["1.test.log", "2.test.log"], rotation: 2, write: 1, writev: 1 })); + it("events", () => deq(events, { finish: 1, open: ["test.log", "test.log", "test.log"], rotated: ["1.test.log", "2.test.log"], rotation: 2, write: 1, writev: 1, ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n")); it("first rotated file content", () => eq(gunzipSync(readFileSync("1.test.log")).toString(), "test\ntest\n")); it("second rotated file content", () => eq(gunzipSync(readFileSync("2.test.log")).toString(), "test\ntest\ntest\n")); diff --git a/test/09history.ts b/test/09history.ts index 80b718d..b1c1b00 100644 --- a/test/09history.ts +++ b/test/09history.ts @@ -2,7 +2,7 @@ import { deepStrictEqual as deq, strictEqual as eq } from "assert"; import { readFileSync } from "fs"; -import { test } from "./helper"; +import { test, v14 } from "./helper"; describe("history", () => { describe("maxFiles", () => { @@ -17,7 +17,6 @@ describe("history", () => { it("events", () => deq(events, { - close: 1, finish: 1, history: 5, open: ["log/test.log", "log/test.log", "log/test.log", "log/test.log", "log/test.log", "log/test.log"], @@ -26,7 +25,8 @@ describe("history", () => { rotation: 5, warning: ["File 'test' contained in history is not a regular file"], write: 1, - writev: 1 + writev: 1, + ...v14() })); it("file content", () => eq(readFileSync("log/test.log", "utf8"), "test\n")); it("first rotated file content", () => eq(readFileSync("log/3-test.log", "utf8"), "test\ntest\ntest\ntest\n")); @@ -47,7 +47,6 @@ describe("history", () => { it("events", () => deq(events, { - close: 1, finish: 1, history: 5, open: ["log/test.log", "log/test.log", "log/test.log", "log/test.log", "log/test.log", "log/test.log"], @@ -56,7 +55,8 @@ describe("history", () => { rotation: 5, warning: ["File 'test' contained in history is not a regular file"], write: 1, - writev: 1 + writev: 1, + ...v14() })); it("file content", () => eq(readFileSync("log/test.log", "utf8"), "test\n")); it("first rotated file content", () => eq(readFileSync("log/1-test.log", "utf8"), "test\ntest\ntest\ntest\ntest\ntest\n")); @@ -75,7 +75,6 @@ describe("history", () => { it("events", () => deq(events, { - close: 1, finish: 1, history: 5, open: ["test.log", "test.log", "test.log", "test.log", "test.log", "test.log"], @@ -83,7 +82,8 @@ describe("history", () => { rotated: ["1-test.log", "2-test.log", "3-test.log", "4-test.log", "1-test.log"], rotation: 5, write: 1, - writev: 1 + writev: 1, + ...v14() })); it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n")); it("first rotated file content", () => eq(readFileSync("4-test.log", "utf8"), "test\ntest\ntest\ntest\ntest\n")); @@ -125,7 +125,6 @@ describe("history", () => { it("events", () => deq(events, { - close: 1, finish: 1, history: 4, open: ["20150123-0101-01-test.log", "20150123-0105-01-test.log", "20150123-0109-01-test.log", "20150123-0113-01-test.log", "20150123-0117-01-test.log"], @@ -133,7 +132,8 @@ describe("history", () => { rotated: ["20150123-0101-01-test.log", "20150123-0105-01-test.log", "20150123-0109-01-test.log", "20150123-0113-01-test.log"], rotation: 4, write: 1, - writev: 1 + writev: 1, + ...v14() })); it("file content", () => eq(readFileSync("20150123-0117-01-test.log", "utf8"), "test\n")); it("first rotated file content", () => eq(readFileSync("20150123-0109-01-test.log", "utf8"), "test\ntest\ntest\ntest\n")); diff --git a/test/helper.ts b/test/helper.ts index c03e6ab..bda138f 100644 --- a/test/helper.ts +++ b/test/helper.ts @@ -131,3 +131,9 @@ export function test(opt: testOpt, test: (rfs: any) => void): any { return events; } + +export const gte14 = parseInt(process.versions.node.split(".")[0], 10) >= 14; + +export function v14(): { close?: number } { + return gte14 ? { close: 1 } : {}; +}