From d3872208c904a6014e7ed84c06793bca9f633e81 Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Tue, 25 Jan 2022 18:25:11 +0800 Subject: [PATCH] refactor(test): tap v15 - replaced deprecated synonyms, separated tap.has() and tap.match() https://github.com/tapjs/node-tap/pull/649/files https://github.com/coreyfarrell/node-tap/blob/6d9f5798a9700be6773b6fe8c1339796bdf6928b/lib/synonyms.js https://github.com/tapjs/node-tap/commit/2c15bd87796df89a1112cd457579f440ee0b3e94 --- test/tap/cluster-test.js | 4 +-- test/tap/connect-logger-test.js | 8 +++--- test/tap/connect-nolog-test.js | 40 ++++++++++++++-------------- test/tap/dateFileAppender-test.js | 8 +++--- test/tap/disable-cluster-test.js | 2 +- test/tap/fileAppender-test.js | 20 +++++++------- test/tap/fileSyncAppender-test.js | 14 +++++----- test/tap/multi-file-appender-test.js | 20 +++++++------- test/tap/multiprocess-test.js | 20 +++++++------- 9 files changed, 68 insertions(+), 68 deletions(-) diff --git a/test/tap/cluster-test.js b/test/tap/cluster-test.js index b42703a..f25eb28 100644 --- a/test/tap/cluster-test.js +++ b/test/tap/cluster-test.js @@ -42,13 +42,13 @@ if (cluster.isMaster) { t.equal(logEvents[1].pid, workerPid); // serialising errors with stacks intact t.type(logEvents[1].data[1], "Error"); - t.contains(logEvents[1].data[1].stack, "Error: oh dear"); + t.match(logEvents[1].data[1].stack, "Error: oh dear"); // serialising circular references in objects t.type(logEvents[1].data[2], "object"); t.type(logEvents[1].data[2].me, "object"); // serialising errors with custom properties t.type(logEvents[1].data[3], "Error"); - t.contains(logEvents[1].data[3].stack, "Error: wtf"); + t.match(logEvents[1].data[3].stack, "Error: wtf"); t.equal(logEvents[1].data[3].alert, "chartreuse"); // serialising things that are not errors, but look a bit like them t.type(logEvents[1].data[4], "object"); diff --git a/test/tap/connect-logger-test.js b/test/tap/connect-logger-test.js index 944b3cc..6ee278e 100644 --- a/test/tap/connect-logger-test.js +++ b/test/tap/connect-logger-test.js @@ -114,10 +114,10 @@ test("log4js connect logger", batch => { assert.type(messages, "Array"); assert.equal(messages.length, 1); assert.ok(levels.INFO.isEqualTo(messages[0].level)); - assert.include(messages[0].message, "GET"); - assert.include(messages[0].message, "http://url"); - assert.include(messages[0].message, "my.remote.addr"); - assert.include(messages[0].message, "200"); + assert.match(messages[0].message, "GET"); + assert.match(messages[0].message, "http://url"); + assert.match(messages[0].message, "my.remote.addr"); + assert.match(messages[0].message, "200"); assert.end(); }); diff --git a/test/tap/connect-nolog-test.js b/test/tap/connect-nolog-test.js index 6edba66..1e33948 100644 --- a/test/tap/connect-nolog-test.js +++ b/test/tap/connect-nolog-test.js @@ -75,10 +75,10 @@ test("log4js connect logger", batch => { assert.type(messages, "Array"); assert.equal(messages.length, 1); assert.ok(levels.INFO.isEqualTo(messages[0].level)); - assert.include(messages[0].message, "GET"); - assert.include(messages[0].message, "http://url"); - assert.include(messages[0].message, "my.remote.addr"); - assert.include(messages[0].message, "200"); + assert.match(messages[0].message, "GET"); + assert.match(messages[0].message, "http://url"); + assert.match(messages[0].message, "my.remote.addr"); + assert.match(messages[0].message, "200"); assert.end(); }); @@ -121,10 +121,10 @@ test("log4js connect logger", batch => { assert.equal(messages.length, 1); assert.ok(levels.INFO.isEqualTo(messages[0].level)); - assert.include(messages[0].message, "GET"); - assert.include(messages[0].message, "http://url"); - assert.include(messages[0].message, "my.remote.addr"); - assert.include(messages[0].message, "200"); + assert.match(messages[0].message, "GET"); + assert.match(messages[0].message, "http://url"); + assert.match(messages[0].message, "my.remote.addr"); + assert.match(messages[0].message, "200"); assert.end(); }); @@ -182,10 +182,10 @@ test("log4js connect logger", batch => { assert.equal(messages.length, 1); assert.ok(levels.INFO.isEqualTo(messages[0].level)); - assert.include(messages[0].message, "GET"); - assert.include(messages[0].message, "http://url"); - assert.include(messages[0].message, "my.remote.addr"); - assert.include(messages[0].message, "200"); + assert.match(messages[0].message, "GET"); + assert.match(messages[0].message, "http://url"); + assert.match(messages[0].message, "my.remote.addr"); + assert.match(messages[0].message, "200"); assert.end(); }); @@ -243,10 +243,10 @@ test("log4js connect logger", batch => { assert.equal(messages.length, 1); assert.ok(levels.INFO.isEqualTo(messages[0].level)); - assert.include(messages[0].message, "GET"); - assert.include(messages[0].message, "http://url"); - assert.include(messages[0].message, "my.remote.addr"); - assert.include(messages[0].message, "200"); + assert.match(messages[0].message, "GET"); + assert.match(messages[0].message, "http://url"); + assert.match(messages[0].message, "my.remote.addr"); + assert.match(messages[0].message, "200"); assert.end(); }); @@ -304,10 +304,10 @@ test("log4js connect logger", batch => { assert.equal(messages.length, 1); assert.ok(levels.INFO.isEqualTo(messages[0].level)); - assert.include(messages[0].message, "GET"); - assert.include(messages[0].message, "http://url"); - assert.include(messages[0].message, "my.remote.addr"); - assert.include(messages[0].message, "200"); + assert.match(messages[0].message, "GET"); + assert.match(messages[0].message, "http://url"); + assert.match(messages[0].message, "my.remote.addr"); + assert.match(messages[0].message, "200"); assert.end(); }); diff --git a/test/tap/dateFileAppender-test.js b/test/tap/dateFileAppender-test.js index 8baa968..c224a96 100644 --- a/test/tap/dateFileAppender-test.js +++ b/test/tap/dateFileAppender-test.js @@ -31,7 +31,7 @@ test("../../lib/appenders/dateFile", batch => { setTimeout(() => { fs.readFile(testFile, "utf8", (err, contents) => { - t.include(contents, "This should be in the file"); + t.match(contents, "This should be in the file"); t.match( contents, /\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}] \[INFO] default-settings - / @@ -62,7 +62,7 @@ test("../../lib/appenders/dateFile", batch => { path.join(__dirname, "date-file-test.log"), "utf8", (err, contents) => { - t.include(contents, `this should be written to the file${EOL}`); + t.match(contents, `this should be written to the file${EOL}`); t.equal( contents.indexOf("this should not be written to the file"), -1 @@ -115,12 +115,12 @@ test("../../lib/appenders/dateFile", batch => { // wait for filesystem to catch up log4js.shutdown(() => { fs.readFile(existingFile, "utf8", (err, contents) => { - t.include( + t.match( contents, "this is existing data", "should not overwrite the file on open (issue #132)" ); - t.include( + t.match( contents, "this should be written to the file with the appended date" ); diff --git a/test/tap/disable-cluster-test.js b/test/tap/disable-cluster-test.js index 4cec193..4d3ed74 100644 --- a/test/tap/disable-cluster-test.js +++ b/test/tap/disable-cluster-test.js @@ -46,7 +46,7 @@ if (cluster.isMaster) { t.equal(workerEvents[0].categoryName, "worker"); t.equal(workerEvents[0].data[0], "this is worker"); t.type(workerEvents[0].data[1], "Error"); - t.contains(workerEvents[0].data[1].stack, "Error: oh dear"); + t.match(workerEvents[0].data[1].stack, "Error: oh dear"); t.end(); }); batch.end(); diff --git a/test/tap/fileAppender-test.js b/test/tap/fileAppender-test.js index 02eaca6..f325a50 100644 --- a/test/tap/fileAppender-test.js +++ b/test/tap/fileAppender-test.js @@ -38,7 +38,7 @@ test("log4js fileAppender", batch => { await sleep(100); const fileContents = await fs.readFile(testFile, "utf8"); - t.include(fileContents, `This should be in the file.${EOL}`); + t.match(fileContents, `This should be in the file.${EOL}`); t.match( fileContents, /\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}] \[INFO] default-settings - / @@ -107,7 +107,7 @@ test("log4js fileAppender", batch => { // wait for the file system to catch up await sleep(100); const fileContents = await fs.readFile(testFile, "utf8"); - t.include(fileContents, "This is the second log message."); + t.match(fileContents, "This is the second log message."); t.equal(fileContents.indexOf("This is the first log message."), -1); const files = await fs.readdir(__dirname); const logFiles = files.filter(file => @@ -213,11 +213,11 @@ test("log4js fileAppender", batch => { "fa-maxFileSize-with-backups-test.log.2" ]); let contents = await fs.readFile(path.join(__dirname, logFiles[0]), "utf8"); - t.include(contents, "This is the fourth log message."); + t.match(contents, "This is the fourth log message."); contents = await fs.readFile(path.join(__dirname, logFiles[1]), "utf8"); - t.include(contents, "This is the third log message."); + t.match(contents, "This is the third log message."); contents = await fs.readFile(path.join(__dirname, logFiles[2]), "utf8"); - t.include(contents, "This is the second log message."); + t.match(contents, "This is the second log message."); t.end(); }); @@ -275,16 +275,16 @@ test("log4js fileAppender", batch => { "fa-maxFileSize-with-backups-compressed-test.log.2.gz" ]); let contents = await fs.readFile(path.join(__dirname, logFiles[0]), "utf8"); - t.include(contents, "This is the fourth log message."); + t.match(contents, "This is the fourth log message."); contents = await gunzip( await fs.readFile(path.join(__dirname, logFiles[1])) ); - t.include(contents.toString("utf8"), "This is the third log message."); + t.match(contents.toString("utf8"), "This is the third log message."); contents = await gunzip( await fs.readFile(path.join(__dirname, logFiles[2])) ); - t.include(contents.toString("utf8"), "This is the second log message."); + t.match(contents.toString("utf8"), "This is the second log message."); t.end(); }); @@ -369,14 +369,14 @@ test("log4js fileAppender", batch => { await sleep(100); let fileContents = await fs.readFile(testFilePlain, "utf8"); - t.include(fileContents, `This should be in the file. Color should be plain.${EOL}`); + t.match(fileContents, `This should be in the file. Color should be plain.${EOL}`); t.match( fileContents, /\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}] \[INFO] default-settings - / ); fileContents = await fs.readFile(testFileAsIs, "utf8"); - t.include(fileContents, "This should be in the file.", + t.match(fileContents, "This should be in the file.", `\x1b[33mColor\x1b[0m \x1b[93;41mshould\x1b[0m be \x1b[38;5;8mplain\x1b[0m.${EOL}`); t.match( fileContents, diff --git a/test/tap/fileSyncAppender-test.js b/test/tap/fileSyncAppender-test.js index bb068ad..d7bd810 100644 --- a/test/tap/fileSyncAppender-test.js +++ b/test/tap/fileSyncAppender-test.js @@ -30,7 +30,7 @@ test("log4js fileSyncAppender", batch => { logger.info("This should be in the file."); fs.readFile(testFile, "utf8", (err, fileContents) => { - t.include(fileContents, `This should be in the file.${EOL}`); + t.match(fileContents, `This should be in the file.${EOL}`); t.match( fileContents, /\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}] \[INFO] default-settings - / @@ -66,7 +66,7 @@ test("log4js fileSyncAppender", batch => { t.test("log file should only contain the second message", assert => { fs.readFile(testFile, "utf8", (err, fileContents) => { - assert.include(fileContents, `This is the second log message.${EOL}`); + assert.match(fileContents, `This is the second log message.${EOL}`); assert.equal( fileContents.indexOf("This is the first log message."), -1 @@ -192,21 +192,21 @@ test("log4js fileSyncAppender", batch => { path.join(__dirname, logFiles[0]), "utf8", (e, contents) => { - assert.include(contents, "This is the fourth log message."); + assert.match(contents, "This is the fourth log message."); } ); fs.readFile( path.join(__dirname, logFiles[1]), "utf8", (e, contents) => { - assert.include(contents, "This is the third log message."); + assert.match(contents, "This is the third log message."); } ); fs.readFile( path.join(__dirname, logFiles[2]), "utf8", (e, contents) => { - assert.include(contents, "This is the second log message."); + assert.match(contents, "This is the second log message."); } ); }); @@ -242,7 +242,7 @@ test("log4js fileSyncAppender", batch => { logger.warn("this should be written to the file"); fs.readFile(testFile, "utf8", (err, contents) => { - t.include(contents, `this should be written to the file${EOL}`); + t.match(contents, `this should be written to the file${EOL}`); t.equal(contents.indexOf("this should not be written to the file"), -1); t.end(); }); @@ -276,7 +276,7 @@ test("log4js fileSyncAppender", batch => { logger.warn("log message"); fs.readFile(testFile, "ascii", (err, contents) => { - t.include(contents, `log message${EOL}`); + t.match(contents, `log message${EOL}`); t.end(); }); }); diff --git a/test/tap/multi-file-appender-test.js b/test/tap/multi-file-appender-test.js index 14cd42e..0d69a05 100644 --- a/test/tap/multi-file-appender-test.js +++ b/test/tap/multi-file-appender-test.js @@ -34,8 +34,8 @@ test("multiFile appender", batch => { loggerA.info("I am in logger A"); loggerB.info("I am in logger B"); log4js.shutdown(() => { - t.contains(fs.readFileSync("logs/A.log", "utf-8"), "I am in logger A"); - t.contains(fs.readFileSync("logs/B.log", "utf-8"), "I am in logger B"); + t.match(fs.readFileSync("logs/A.log", "utf-8"), "I am in logger A"); + t.match(fs.readFileSync("logs/B.log", "utf-8"), "I am in logger B"); t.end(); }); } @@ -65,8 +65,8 @@ test("multiFile appender", batch => { loggerC.info("I am in logger C"); loggerD.info("I am in logger D"); log4js.shutdown(() => { - t.contains(fs.readFileSync("logs/C.log", "utf-8"), "I am in logger C"); - t.contains(fs.readFileSync("logs/D.log", "utf-8"), "I am in logger D"); + t.match(fs.readFileSync("logs/C.log", "utf-8"), "I am in logger C"); + t.match(fs.readFileSync("logs/D.log", "utf-8"), "I am in logger D"); t.end(); }); } @@ -105,7 +105,7 @@ test("multiFile appender", batch => { loggerC.addContext("label", "C"); loggerC.info("I am in logger C"); setTimeout(() => { - t.contains( + t.match( debugLogs[debugLogs.length - 1], "C not used for > 20 ms => close" ); @@ -143,7 +143,7 @@ test("multiFile appender", batch => { loggerE.info("I am also not in logger E"); log4js.shutdown(() => { const contents = fs.readFileSync("logs/E.log", "utf-8"); - t.contains(contents, "I am in logger E"); + t.match(contents, "I am in logger E"); t.notMatch(contents, "I am not in logger E"); t.notMatch(contents, "I am also not in logger E"); t.end(); @@ -176,11 +176,11 @@ test("multiFile appender", batch => { loggerF.info("I am in logger F"); log4js.shutdown(() => { let contents = fs.readFileSync("logs/F.log", "utf-8"); - t.contains(contents, "I am in logger F"); + t.match(contents, "I am in logger F"); contents = fs.readFileSync("logs/F.log.1", "utf-8"); - t.contains(contents, "I am also in logger F"); + t.match(contents, "I am also in logger F"); contents = fs.readFileSync("logs/F.log.2", "utf-8"); - t.contains(contents, "Being in logger F is the best"); + t.match(contents, "Being in logger F is the best"); t.end(); }); }); @@ -209,7 +209,7 @@ test("multiFile appender", batch => { testLogger.debug("This should go to the file"); log4js.shutdown(() => { const contents = fs.readFileSync("logs/test.someTest.log", "utf-8"); - t.contains(contents, "This should go to the file"); + t.match(contents, "This should go to the file"); t.end(); }); }); diff --git a/test/tap/multiprocess-test.js b/test/tap/multiprocess-test.js index dd22f4d..6901939 100644 --- a/test/tap/multiprocess-test.js +++ b/test/tap/multiprocess-test.js @@ -95,7 +95,7 @@ test("Multiprocess Appender", async batch => { t.test( "should buffer messages written before socket is connected", assert => { - assert.include(net.data[0], "before connect"); + assert.match(net.data[0], "before connect"); assert.end(); } ); @@ -103,9 +103,9 @@ test("Multiprocess Appender", async batch => { t.test( "should write log messages to socket as flatted strings with a terminator string", assert => { - assert.include(net.data[0], "before connect"); + assert.match(net.data[0], "before connect"); assert.equal(net.data[1], "__LOG4JS__"); - assert.include(net.data[2], "after connect"); + assert.match(net.data[2], "after connect"); assert.equal(net.data[3], "__LOG4JS__"); assert.equal(net.encoding, "utf8"); assert.end(); @@ -113,9 +113,9 @@ test("Multiprocess Appender", async batch => { ); t.test("should attempt to re-open the socket on error", assert => { - assert.include(net.data[4], "after error, before connect"); + assert.match(net.data[4], "after error, before connect"); assert.equal(net.data[5], "__LOG4JS__"); - assert.include(net.data[6], "after error, after connect"); + assert.match(net.data[6], "after error, after connect"); assert.equal(net.data[7], "__LOG4JS__"); assert.equal(net.createConnectionCalled, 2); assert.end(); @@ -162,11 +162,11 @@ test("Multiprocess Appender", async batch => { t.test("should attempt to re-open the socket", assert => { // skipping the __LOG4JS__ separators - assert.include(net.data[0], "before connect"); - assert.include(net.data[2], "after connect"); - assert.include(net.data[4], "after timeout, before close"); - assert.include(net.data[6], "after close, before connect"); - assert.include(net.data[8], "after close, after connect"); + assert.match(net.data[0], "before connect"); + assert.match(net.data[2], "after connect"); + assert.match(net.data[4], "after timeout, before close"); + assert.match(net.data[6], "after close, before connect"); + assert.match(net.data[8], "after close, after connect"); assert.equal(net.createConnectionCalled, 2); assert.end(); });