-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(test): use Node.js native test runner (#19)
- Loading branch information
Showing
5 changed files
with
90 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <email> field", (tape) => { | ||
const result = utils.parseManifestAuthor("GENTILHOMME Thomas <gentilhomme.thomas@gmail.com>"); | ||
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 <john.david.dalton@gmail.com> (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 <email> field", () => { | ||
const result = utils.parseManifestAuthor("GENTILHOMME Thomas <gentilhomme.thomas@gmail.com>"); | ||
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 <john.david.dalton@gmail.com> (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"); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
}); | ||
}); |