Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Commit

Permalink
refactor(test): Migrating from tape to Node.js test runner (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabnguess authored Nov 29, 2023
1 parent 92e1980 commit 8c0b8bc
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 130 deletions.
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"start": "node index.js",
"lint": "eslint index.js",
"test-only": "cross-env esm-tape-runner 'tests/**/*.test.js' | tap-monkey",
"test-only": "node --test",
"test": "npm run lint && npm run test-only",
"coverage": "c8 -r html npm test",
"spdx:refresh": "node ./scripts/fetchSpdxLicenses.js"
Expand Down Expand Up @@ -39,14 +39,10 @@
"devDependencies": {
"@myunisoft/httpie": "^2.0.3",
"@nodesecure/eslint-config": "^1.8.0",
"@small-tech/esm-tape-runner": "^2.0.0",
"@small-tech/tap-monkey": "^1.4.0",
"astring": "^1.8.6",
"c8": "^8.0.1",
"cross-env": "^7.0.3",
"eslint": "^8.31.0",
"node-estree": "^4.0.0",
"tape": "^5.7.2"
"node-estree": "^4.0.0"
},
"engines": {
"node": ">=18"
Expand Down
50 changes: 22 additions & 28 deletions tests/licenseIdConformance.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Import Third-party Dependencies
import test from "tape";
// Import Node.js Dependencies
import { test } from "node:test";
import assert from "node:assert";

// Import Internal Dependencies
import { licenseIdConformance } from "../index.js";

test("check the output of MIT license", (tape) => {
test("check the output of MIT license", () => {
const mitLicense = unwrap(licenseIdConformance("MIT"));
tape.same(mitLicense,
assert.deepEqual(mitLicense,
{
uniqueLicenseIds: ["MIT"],
spdxLicenseLinks: ["https://spdx.org/licenses/MIT.html#licenseText"],
Expand All @@ -18,12 +19,11 @@ test("check the output of MIT license", (tape) => {
}
}
);
tape.end();
});

test("check the output of BSD 3-Clause license (missing hyphen)", (tape) => {
test("check the output of BSD 3-Clause license (missing hyphen)", () => {
const mitLicense = unwrap(licenseIdConformance("BSD 3-Clause"));
tape.same(mitLicense,
assert.deepEqual(mitLicense,
{
uniqueLicenseIds: ["BSD-3-Clause"],
spdxLicenseLinks: ["https://spdx.org/licenses/BSD-3-Clause.html#licenseText"],
Expand All @@ -35,12 +35,11 @@ test("check the output of BSD 3-Clause license (missing hyphen)", (tape) => {
}
}
);
tape.end();
});

test("check deprecated license cases", (tape) => {
test("check deprecated license cases", () => {
const deprecatedLicense = unwrap(licenseIdConformance("AGPL-1.0"));
tape.same(deprecatedLicense, {
assert.deepEqual(deprecatedLicense, {
uniqueLicenseIds: ["AGPL-1.0"],
spdxLicenseLinks: [
"https://spdx.org/licenses/AGPL-1.0.html#licenseText"
Expand All @@ -54,7 +53,7 @@ test("check deprecated license cases", (tape) => {
});

const multipleDeprecatedLicenses = unwrap(licenseIdConformance("AGPL-1.0 AND AGPL-3.0"));
tape.same(multipleDeprecatedLicenses, {
assert.deepEqual(multipleDeprecatedLicenses, {
uniqueLicenseIds: ["AGPL-1.0", "AGPL-3.0"],
spdxLicenseLinks: [
"https://spdx.org/licenses/AGPL-1.0.html#licenseText",
Expand All @@ -67,25 +66,23 @@ test("check deprecated license cases", (tape) => {
includesDeprecated: true
}
});
tape.end();
});

test("check two licenses that pass osi and fsf", (tape) => {
test("check two licenses that pass osi and fsf", () => {
const licenses = unwrap(licenseIdConformance("ISC OR MIT"));
tape.same(licenses, {
assert.deepEqual(licenses, {
uniqueLicenseIds: ["ISC", "MIT"],
spdxLicenseLinks: [
"https://spdx.org/licenses/ISC.html#licenseText",
"https://spdx.org/licenses/MIT.html#licenseText"
],
spdx: { osi: true, fsf: true, fsfAndOsi: true, includesDeprecated: false }
});
tape.end();
});

test("complex license statement that does not pass osi but does pass fsf", (tape) => {
test("complex license statement that does not pass osi but does pass fsf", () => {
const licenses = unwrap(licenseIdConformance("MIT OR (CC0-1.0 AND ISC)"));
tape.same(licenses, {
assert.deepEqual(licenses, {
uniqueLicenseIds: ["MIT", "CC0-1.0", "ISC"],
spdxLicenseLinks: [
"https://spdx.org/licenses/MIT.html#licenseText",
Expand All @@ -98,19 +95,16 @@ test("complex license statement that does not pass osi but does pass fsf", (tape
fsfAndOsi: false,
includesDeprecated: false }
});
tape.end();
});

test("check license that should throw an Error", (tape) => {
try {
unwrap(licenseIdConformance("unreallicense"));
tape.fail("should not get here since license-conformance should throw new Error");
}
catch (err) {
tape.strictEqual(err.message, "Passed license expression 'unreallicense' was not a valid license expression.");
tape.strictEqual(err.cause.message, "Unexpected `u` at offset 0");
}
tape.end();
test("check license that should throw an Error", () => {
assert.throws(
() => unwrap(licenseIdConformance("unreallicense")),
{
name: "Error",
message: "Passed license expression 'unreallicense' was not a valid license expression."
}
);
});

function unwrap(result) {
Expand Down
27 changes: 13 additions & 14 deletions tests/licenses.test.js
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, test } from "node:test";
import assert from "node:assert";

// Import Internal Dependencies
import { closestSpdxLicenseID } from "../src/licenses.js";

// Check everytruthy
test("it should return the given LicenseID if no record match", (tape) => {
tape.same(closestSpdxLicenseID("foooobar"), "foooobar");
tape.end();
});
describe("Check everytruthy", () => {
test("it should return the given LicenseID if no record match", () => {
assert.equal(closestSpdxLicenseID("foooobar"), "foooobar");
});

test("it should fix 'BSD 3-Clause' to 'BSD-3-Clause'", (tape) => {
tape.same(closestSpdxLicenseID("BSD 3-Clause"), "BSD-3-Clause");
tape.end();
});
test("it should fix 'BSD 3-Clause' to 'BSD-3-Clause'", () => {
assert.equal(closestSpdxLicenseID("BSD 3-Clause"), "BSD-3-Clause");
});

test("it should not fix 'BSD 3 Clause' because the distance is greater than one", (tape) => {
tape.same(closestSpdxLicenseID("BSD 3 Clause"), "BSD 3 Clause");
tape.end();
test("it should not fix 'BSD 3 Clause' because the distance is greater than one", () => {
assert.equal(closestSpdxLicenseID("BSD 3 Clause"), "BSD 3 Clause");
});
});
23 changes: 9 additions & 14 deletions tests/searchSpdxLicenseId.test.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
// Import Third-party Dependencies
import test from "tape";
// Import Node.js Dependencies
import { test } from "node:test";
import assert from "node:assert";

// Import Internal Dependencies
import { searchSpdxLicenseId } from "../index.js";

test("search for Apache 2.0 license", (tape) => {
test("search for Apache 2.0 license", () => {
const result = searchSpdxLicenseId("Apache License 2.0");
tape.strictEqual(result, "Apache-2.0");

tape.end();
assert.strictEqual(result, "Apache-2.0");
});

test("search for Artistic 1.0 license", (tape) => {
test("search for Artistic 1.0 license", () => {
const result = searchSpdxLicenseId("Artistic License 1.0");
tape.strictEqual(result, "Artistic-1.0");

tape.end();
assert.strictEqual(result, "Artistic-1.0");
});

test("it should return null if there is no license matching name", (tape) => {
test("it should return null if there is no license matching name", () => {
const result = searchSpdxLicenseId("not a license");
tape.strictEqual(result, null);

tape.end();
assert.strictEqual(result, null);
});
126 changes: 58 additions & 68 deletions tests/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,90 +1,80 @@
// Import Third-party Dependencies
import test from "tape";
// Import Node.js Dependencies
import { describe, test } from "node:test";
import assert from "node:assert";

// Import Internal Dependencies
import { checkEveryTruthy, checkSomeTruthy, checkSpdx, createSpdxLink } from "../src/utils.js";

// Check everytruthy
test("check a single true is true", (tape) => {
tape.same(checkEveryTruthy(true), true);
tape.end();
});
describe("Check everytruthy", () => {
test("check a single true is true", () => {
assert.equal(checkEveryTruthy(true), true);
});

test("check multiple true booleans are true", (tape) => {
tape.same(checkEveryTruthy(true, true, true), true);
tape.end();
});
test("check multiple true booleans are true", () => {
assert.equal(checkEveryTruthy(true, true, true), true);
});

test("check that a single false is false", (tape) => {
tape.same(checkEveryTruthy(false), false);
tape.end();
});
test("check that a single false is false", () => {
assert.equal(checkEveryTruthy(false), false);
});

test("ensure that one false will result in a false return", (tape) => {
tape.same(checkEveryTruthy(true, false), false);
tape.end();
test("ensure that one false will result in a false return", () => {
assert.equal(checkEveryTruthy(true, false), false);
});
});

// check someTruthy
test("check a single true is true", (tape) => {
tape.same(checkSomeTruthy(true), true);
tape.end();
});
describe("check someTruthy", () => {
test("check a single true is true", () => {
assert.equal(checkSomeTruthy(true), true);
});

test("check multiple true booleans are true", (tape) => {
tape.same(checkSomeTruthy(true, true, true), true);
tape.end();
});
test("check multiple true booleans are true", () => {
assert.equal(checkSomeTruthy(true, true, true), true);
});

test("check that a single false is false", (tape) => {
tape.same(checkSomeTruthy(false), false);
tape.end();
});
test("check that a single false is false", () => {
assert.equal(checkSomeTruthy(false), false);
});

test("ensure that one false will result in a true return", (tape) => {
tape.same(checkSomeTruthy(true, false), true);
tape.end();
});
test("ensure that one false will result in a true return", () => {
assert.equal(checkSomeTruthy(true, false), true);
});

test("create an MIT SPDX link", (tape) => {
const link = createSpdxLink("MIT");
test("create an MIT SPDX link", () => {
const link = createSpdxLink("MIT");

tape.strictEqual(link, "https://spdx.org/licenses/MIT.html#licenseText");
tape.end();
assert.strictEqual(link, "https://spdx.org/licenses/MIT.html#licenseText");
});
});

// checkSpdx
test("test with MIT license", (tape) => {
const mitLicense = checkSpdx("MIT");
tape.same(mitLicense, {
osi: true,
fsf: true,
fsfAndOsi: true,
includesDeprecated: false
describe("checkSpdx", () => {
test("test with MIT license", () => {
const mitLicense = checkSpdx("MIT");
assert.deepEqual(mitLicense, {
osi: true,
fsf: true,
fsfAndOsi: true,
includesDeprecated: false
});
});
tape.end();
});

test("test with a deprecated license", (tape) => {
const deprecatedLicense = checkSpdx("AGPL-1.0");
tape.same(deprecatedLicense, {
osi: false,
fsf: true,
fsfAndOsi: false,
includesDeprecated: true
test("test with a deprecated license", () => {
const deprecatedLicense = checkSpdx("AGPL-1.0");
assert.deepEqual(deprecatedLicense, {
osi: false,
fsf: true,
fsfAndOsi: false,
includesDeprecated: true
});
});
tape.end();
});

test("test with a broken license", (tape) => {
const brokenLicense = checkSpdx("wrong");
tape.same(brokenLicense, {
osi: false,
fsf: false,
fsfAndOsi: false,
includesDeprecated: false
test("test with a broken license", () => {
const brokenLicense = checkSpdx("wrong");
assert.deepEqual(brokenLicense, {
osi: false,
fsf: false,
fsfAndOsi: false,
includesDeprecated: false
});
});
tape.end();
});


0 comments on commit 8c0b8bc

Please sign in to comment.