From 67af0a3ced8e430b4545011c37f649dbca754d88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A4rsson?= Date: Fri, 19 Apr 2024 13:27:34 +0200 Subject: [PATCH 1/2] refactor: Format date without a dependency --- package-lock.json | 14 -------------- package.json | 1 - src/test_group.js | 3 +-- src/test_node.js | 23 +++++++++++++++++++++++ 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5d506da..53eb335 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,6 @@ "version": "3.2.1", "license": "MIT", "dependencies": { - "date-format": "4.0.3", "lodash": "^4.17.21", "make-dir": "^3.1.0", "xmlbuilder": "^15.1.1" @@ -1264,14 +1263,6 @@ "node": ">= 12" } }, - "node_modules/date-format": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/date-format/-/date-format-4.0.3.tgz", - "integrity": "sha512-7P3FyqDcfeznLZp2b+OMitV9Sz2lUnsT87WaTat9nVwqsBkTzPG3lPLNwW3en6F4pHUiWzr6vb8CLhjdK9bcxQ==", - "engines": { - "node": ">=4.0" - } - }, "node_modules/date-now": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz", @@ -8006,11 +7997,6 @@ "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", "dev": true }, - "date-format": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/date-format/-/date-format-4.0.3.tgz", - "integrity": "sha512-7P3FyqDcfeznLZp2b+OMitV9Sz2lUnsT87WaTat9nVwqsBkTzPG3lPLNwW3en6F4pHUiWzr6vb8CLhjdK9bcxQ==" - }, "date-now": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz", diff --git a/package.json b/package.json index b9792ee..cf87808 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,6 @@ "time-grunt": "^1.2.1" }, "dependencies": { - "date-format": "4.0.3", "lodash": "^4.17.21", "make-dir": "^3.1.0", "xmlbuilder": "^15.1.1" diff --git a/src/test_group.js b/src/test_group.js index a2ae6d1..64eeecb 100755 --- a/src/test_group.js +++ b/src/test_group.js @@ -1,6 +1,5 @@ // @ts-check var _ = require('lodash'); -var formatDate = require('date-format').asString; var { TestNode } = require('./test_node'); class TestGroup extends TestNode { @@ -20,7 +19,7 @@ class TestGroup extends TestNode { */ timestamp(timestamp) { if (_.isDate(timestamp)) { - this._attributes.timestamp = formatDate('yyyy-MM-ddThh:mm:ss', timestamp); + this._attributes.timestamp = this.formatDate(timestamp); } else { this._attributes.timestamp = timestamp; } diff --git a/src/test_node.js b/src/test_node.js index 7f3ba7d..39152ae 100644 --- a/src/test_node.js +++ b/src/test_node.js @@ -104,6 +104,29 @@ class TestNode { return element; } + /** + * @protected + * @param {Date} date + * @returns {string} + */ + formatDate(date) { + const pad = (num) => (num < 10 ? '0' : '') + num; + + return ( + date.getFullYear() + + '-' + + pad(date.getMonth() + 1) + + '-' + + pad(date.getDate()) + + 'T' + + pad(date.getHours()) + + ':' + + pad(date.getMinutes()) + + ':' + + pad(date.getSeconds()) + ); + } + /** * @protected * @param {import('xmlbuilder').XMLElement} element From cc38417b162086f0cd041a00e684e93b0e9e02dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A4rsson?= Date: Fri, 19 Apr 2024 14:32:51 +0200 Subject: [PATCH 2/2] test: Remove unused argument --- spec/e2e_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/e2e_spec.js b/spec/e2e_spec.js index b184f90..81ec5a7 100644 --- a/spec/e2e_spec.js +++ b/spec/e2e_spec.js @@ -28,7 +28,7 @@ describe('JUnit Report builder', function () { return result.trim(); }; - const reportWith = (content, testSuitesProperties) => '\n' + content; + const reportWith = (content) => '\n' + content; it('should produce a report identical to the expected one', function () { builder.testCase().className('root.test.Class1');