Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Migrate from tape to test_runner #186

Merged
merged 1 commit into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"prepublishOnly": "pkg-ok",
"test": "cross-env esm-tape-runner 'test/**/*.spec.js' | tap-monkey",
"test": "node -r dotenv --test",
"coverage": "c8 -r html npm test"
},
"repository": {
Expand Down Expand Up @@ -35,14 +35,10 @@
"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",
"dotenv": "^16.0.2",
"eslint": "^8.23.0",
"pkg-ok": "^3.0.0",
"tape": "^5.6.0"
"pkg-ok": "^3.0.0"
},
"engines": {
"node": ">=18"
Expand Down
76 changes: 30 additions & 46 deletions test/test.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import dotenv from "dotenv";
dotenv.config();

// Import Node.js Dependencies
import { fileURLToPath } from "url";
import path from "path";
import fs from "fs/promises";
import { test } from "node:test";
import assert from "node:assert";

// Import Third-party Dependencies
import test from "tape";
import is from "@slimio/is";

// Import Internal Dependency
Expand All @@ -19,65 +17,51 @@ const kDownloadDir = path.join(__dirname, "downloads");

await fs.mkdir(kDownloadDir);

test("gitlab.download should be an asyncFunction", (tape) => {
tape.true(is.func(gitlab.download));
tape.true(is.asyncFunction(gitlab.download));

tape.end();
test("gitlab.download should be an asyncFunction", () => {
assert.equal(is.func(gitlab.download), true);
assert.equal(is.asyncFunction(gitlab.download), true);
});

test("gitlab.downloadAndExtract should be an asyncFunction", (tape) => {
tape.true(is.func(gitlab.downloadAndExtract));
tape.true(is.asyncFunction(gitlab.downloadAndExtract));

tape.end();
test("gitlab.downloadAndExtract should be an asyncFunction", () => {
assert.equal(is.func(gitlab.downloadAndExtract), true);
assert.equal(is.asyncFunction(gitlab.downloadAndExtract), true);
});

test("download must throw: repository must be a string!", async(tape) => {
tape.plan(2);

try {
await gitlab.download(10);
}
catch (error) {
tape.strictEqual(error.name, "TypeError");
tape.strictEqual(error.message, "repository must be a string!");
}

tape.end();
test("download must throw: repository must be a string!", async() => {
await assert.rejects(
async() => await gitlab.download(10),
{
name: "TypeError",
message: "repository must be a string!"
}
);
});

test("extract tar.gz at in the current working dir", async(tape) => {
test("extract tar.gz at in the current working dir", async() => {
const { location } = await gitlab.download("polychromatic.plombier-chauffagiste");

await fs.access(location);
tape.strictEqual(path.extname(location), ".gz");

tape.end();
assert.strictEqual(path.extname(location), ".gz");
});

test("download and extract a public gitlab repository", async(tape) => {
test("download and extract a public gitlab repository", async() => {
const { location } = await gitlab.downloadAndExtract("polychromatic.plombier-chauffagiste", {
dest: kDownloadDir
});

await fs.access(location);
tape.pass();

tape.end();
await assert.doesNotReject(
async() => await fs.access(location)
);
});

test("teardown", async(tape) => {
test("teardown", async() => {
await new Promise((resolve) => setImmediate(resolve));
await fs.rm(kDownloadDir, { recursive: true, force: true });

try {
await fs.unlink(path.join(process.cwd(), "plombier-chauffagiste-master.tar.gz"));
}
catch (err) {
// do nothing
}
finally {
tape.end();
}
await assert.doesNotReject(
async() => await fs.rm(kDownloadDir, { recursive: true, force: true })
);

await assert.doesNotReject(
async() => await fs.unlink(path.join(process.cwd(), "plombier-chauffagiste-master.tar.gz"))
);
});
17 changes: 7 additions & 10 deletions test/utils.spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
// Import Third-party Dependencies
import test from "tape";
// Import Node.js Dependencies
import { test } from "node:test";
import assert from "node:assert";

// Import Internal Dependency
import { getRepositoryPath } from "../src/utils.js";

test("getRepositoryPath must return id", (tape) => {
tape.is(getRepositoryPath("10"), "10");

tape.end();
test("getRepositoryPath must return id", () => {
assert.equal(getRepositoryPath("10"), "10");
});

test("getRepositoryPath must return gitlab path", (tape) => {
tape.is(getRepositoryPath("nodesecure.boo"), "nodesecure%2Fboo");

tape.end();
test("getRepositoryPath must return gitlab path", () => {
assert.equal(getRepositoryPath("nodesecure.boo"), "nodesecure%2Fboo");
});