From 52c1010d4f5ac79f1a4f725c8bed4ef32ca8434b Mon Sep 17 00:00:00 2001 From: Maxime <57860498+MaximeMRF@users.noreply.github.com> Date: Fri, 24 Feb 2023 23:23:36 +0100 Subject: [PATCH] refactor(test): use Node.js native test runner (#19) --- package.json | 11 +--- test/formatBytes.spec.js | 37 +++++------ test/locationToString.spec.js | 25 ++++---- test/parseManifestAuthor.spec.js | 102 ++++++++++++++----------------- test/taggedString.spec.js | 29 +++++---- 5 files changed, 90 insertions(+), 114 deletions(-) diff --git a/package.json b/package.json index 4723da7..b9f11a7 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,8 @@ "test": "test" }, "scripts": { - "lint": "cross-env eslint index.js", - "test-only": "cross-env esm-tape-runner 'test/**/*.spec.js' | tap-monkey", + "lint": "eslint index.js", + "test-only": "node --test test/", "test": "npm run lint && npm run test-only", "coverage": "c8 -r html npm test" }, @@ -35,12 +35,7 @@ "homepage": "https://github.com/NodeSecure/utils#readme", "devDependencies": { "@nodesecure/eslint-config": "^1.5.0", - "@slimio/is": "^2.0.0", - "@small-tech/esm-tape-runner": "^2.0.0", - "@small-tech/tap-monkey": "^1.4.0", "c8": "^7.12.0", - "cross-env": "^7.0.3", - "eslint": "^8.23.0", - "tape": "^5.6.0" + "eslint": "^8.23.0" } } diff --git a/test/formatBytes.spec.js b/test/formatBytes.spec.js index e657287..91e52b5 100644 --- a/test/formatBytes.spec.js +++ b/test/formatBytes.spec.js @@ -1,29 +1,24 @@ -// Import Third-party Dependencies -import test from "tape"; +// Import Node.js Dependencies +import { describe, it } from "node:test"; +import assert from "node:assert"; // Import Internal Dependencies import * as utils from "../index.js"; -test("formatBytes should return '0 B' if bytes argument is equal zero", (tape) => { - tape.equal(utils.formatBytes(0), "0 B"); +describe("formatBytes", () => { + it("should return '0 B' if bytes argument is equal zero", () => { + assert.equal(utils.formatBytes(0), "0 B"); + }); - tape.end(); -}); - -test("formatBytes should format 10 bytes", (tape) => { - tape.equal(utils.formatBytes(10), "10 B"); - - tape.end(); -}); - -test("formatBytes should format 3000 bytes in KB with two fixed number", (tape) => { - tape.equal(utils.formatBytes(3000), "2.93 KB"); - - tape.end(); -}); + it("should format 10 bytes", () => { + assert.equal(utils.formatBytes(10), "10 B"); + }); -test("formatBytes should format 822_223_900 bytes in MB", (tape) => { - tape.equal(utils.formatBytes(822_223_900), "784.13 MB"); + it("should format 3000 bytes in KB with two fixed number", () => { + assert.equal(utils.formatBytes(3000), "2.93 KB"); + }); - tape.end(); + it("should format 822_223_900 bytes in MB", () => { + assert.equal(utils.formatBytes(822_223_900), "784.13 MB"); + }); }); diff --git a/test/locationToString.spec.js b/test/locationToString.spec.js index e2aa407..3944a68 100644 --- a/test/locationToString.spec.js +++ b/test/locationToString.spec.js @@ -1,19 +1,18 @@ -// Import Third-party Dependencies -import test from "tape"; +// Import Node.js Dependencies +import { describe, it } from "node:test"; +import assert from "node:assert"; // Import Internal Dependencies import * as utils from "../index.js"; -test("locationToString should return the location array in string syntax", (tape) => { - const str = utils.locationToString([[1, 2], [2, 4]]); - tape.equal(str, "[1:2] - [2:4]"); +describe("locationToString", () => { + it("should return the location array in string syntax", () => { + const str = utils.locationToString([[1, 2], [2, 4]]); + assert.equal(str, "[1:2] - [2:4]"); + }); - tape.end(); -}); - -test("locationToString should ignore elements after length 1", (tape) => { - const str = utils.locationToString([[1, 2, 3], [2, 4, 10], [50]]); - tape.equal(str, "[1:2] - [2:4]"); - - tape.end(); + it("should ignore elements after length 1", () => { + const str = utils.locationToString([[1, 2, 3], [2, 4, 10], [50]]); + assert.equal(str, "[1:2] - [2:4]"); + }); }); diff --git a/test/parseManifestAuthor.spec.js b/test/parseManifestAuthor.spec.js index 131e857..f44bcca 100644 --- a/test/parseManifestAuthor.spec.js +++ b/test/parseManifestAuthor.spec.js @@ -1,73 +1,61 @@ -// Import Third-party Dependencies -import test from "tape"; -import is from "@slimio/is"; +// Import Node.js Dependencies +import { describe, it } from "node:test"; +import assert from "node:assert"; // Import Internal Dependencies import * as utils from "../index.js"; -test("manifestAuthorRegex must return a RegExp", (tape) => { - const regex = utils.manifestAuthorRegex(); - tape.true(is.regExp(regex)); - - tape.end(); -}); - -test("parse a name field", (tape) => { - const result = utils.parseManifestAuthor("GENTILHOMME Thomas"); - tape.deepEqual(result, { - name: "GENTILHOMME Thomas" +describe("manifestAuthorRegex", () => { + it("must return a RegExp", () => { + const regex = utils.manifestAuthorRegex(); + assert.ok(regex instanceof RegExp); }); - - tape.end(); }); -test("parse a generic name field", (tape) => { - const result = utils.parseManifestAuthor("GENTILHOMME Thomas "); - tape.deepEqual(result, { - name: "GENTILHOMME Thomas", - email: "gentilhomme.thomas@gmail.com" +describe("parseManifestAuthor", () => { + it("parse a name field", () => { + const result = utils.parseManifestAuthor("GENTILHOMME Thomas"); + assert.deepEqual(result, { + name: "GENTILHOMME Thomas" + }); }); - tape.end(); -}); - -test("parse an author field with name, email and URL", (tape) => { - const result = utils.parseManifestAuthor("John-David Dalton (http://allyoucanleet.com/)"); - tape.deepEqual(result, { - name: "John-David Dalton", - email: "john.david.dalton@gmail.com", - url: "http://allyoucanleet.com/" + it("parse a generic name field", () => { + const result = utils.parseManifestAuthor("GENTILHOMME Thomas "); + assert.deepEqual(result, { + name: "GENTILHOMME Thomas", + email: "gentilhomme.thomas@gmail.com" + }); }); - tape.end(); -}); - -test("parse an author field with name and URL", (tape) => { - const result = utils.parseManifestAuthor("John-David Dalton (http://allyoucanleet.com/)"); - tape.deepEqual(result, { - name: "John-David Dalton", - url: "http://allyoucanleet.com/" + it("parse an author field with name, email and URL", () => { + const result = utils.parseManifestAuthor("John-David Dalton (http://allyoucanleet.com/)"); + assert.deepEqual(result, { + name: "John-David Dalton", + email: "john.david.dalton@gmail.com", + url: "http://allyoucanleet.com/" + }); }); - tape.end(); -}); - -test("empty string must return empty object", (tape) => { - const result = utils.parseManifestAuthor(""); - tape.deepEqual(result, {}); - - tape.end(); -}); - -test("parseManifestAuthor must throw an Error if the argument is not a string", (tape) => { - tape.plan(1); + it("parse an author field with name and URL", () => { + const result = utils.parseManifestAuthor("John-David Dalton (http://allyoucanleet.com/)"); + assert.deepEqual(result, { + name: "John-David Dalton", + url: "http://allyoucanleet.com/" + }); + }); - try { - utils.parseManifestAuthor(null); - } - catch (error) { - tape.strictEqual(error.message, "expected manifestAuthorField to be a string"); - } + it("empty string must return empty object", () => { + const result = utils.parseManifestAuthor(""); + assert.deepEqual(result, {}); + }); - tape.end(); + it("must throw an Error if the argument is not a string", () => { + try { + utils.parseManifestAuthor(null); + } + catch (error) { + assert.strictEqual(error.message, "expected manifestAuthorField to be a string"); + } + }); }); diff --git a/test/taggedString.spec.js b/test/taggedString.spec.js index b94c522..03dd37f 100644 --- a/test/taggedString.spec.js +++ b/test/taggedString.spec.js @@ -1,21 +1,20 @@ -// Import Third-party Dependencies -import test from "tape"; +// Import Node.js Dependencies +import { describe, it } from "node:test"; +import assert from "node:assert"; // Import Internal Dependencies import * as utils from "../index.js"; -test("taggedString with numeric parameter", (tape) => { - const clojureHello = utils.taggedString`Hello ${0}`; - tape.strictEqual(clojureHello(), "Hello "); - tape.strictEqual(clojureHello("world"), "Hello world"); +describe("taggedString", () => { + it("with numeric parameter", () => { + const clojureHello = utils.taggedString`Hello ${0}`; + assert.strictEqual(clojureHello(), "Hello "); + assert.strictEqual(clojureHello("world"), "Hello world"); + }); - tape.end(); -}); - -test("taggedString with nammed parameter", (tape) => { - const clojureFoo = utils.taggedString`Hello ${"word"}`; - tape.strictEqual(clojureFoo({}), "Hello "); - tape.strictEqual(clojureFoo({ word: "bar" }), "Hello bar"); - - tape.end(); + it("with nammed parameter", () => { + const clojureFoo = utils.taggedString`Hello ${"word"}`; + assert.strictEqual(clojureFoo({}), "Hello "); + assert.strictEqual(clojureFoo({ word: "bar" }), "Hello bar"); + }); });