Skip to content

Commit

Permalink
refactor(test): sources assertions from assert/strict to ease strict …
Browse files Browse the repository at this point in the history
…comparisons (#834)

## Description

- in stead of using the strictEqual/ deepStrictEqual methods from
node:assert use the equal and deepEqual methods from node:assert/strict

## Motivation and Context

... which makes tests easier to read.

## How Has This Been Tested?

- [x] green ci


## Types of changes

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Documentation only change
- [x] Refactor (non-breaking change which fixes an issue without
changing functionality)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
  • Loading branch information
sverweij authored Aug 23, 2023
1 parent fc0200f commit 2344164
Show file tree
Hide file tree
Showing 181 changed files with 1,751 additions and 1,925 deletions.
20 changes: 10 additions & 10 deletions test/api.spec.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// eslint disable because import/no-unresolved,node/no-missing-import don't
// know about (local) module imports yet
/* eslint-disable import/no-unresolved,node/no-missing-import */
import { strictEqual } from "node:assert";
import { equal } from "node:assert/strict";
import satisfies from "semver/functions/satisfies.js";
import dependencyCruiser from "dependency-cruiser";
import extractBabelConfig from "dependency-cruiser/config-utl/extract-babel-config";
Expand All @@ -15,27 +15,27 @@ import extractWebpackResolveConfig from "dependency-cruiser/config-utl/extract-w
if (satisfies(process.versions.node, "^12.19 || >=14.7")) {
describe("[E] api from esm (on node ^12.19 || >= 14.7)", () => {
it("exposes dependency-cruiser main with some functions", () => {
strictEqual(typeof dependencyCruiser, "object");
strictEqual(typeof dependencyCruiser.cruise, "function");
strictEqual(typeof dependencyCruiser.format, "function");
strictEqual(Array.isArray(dependencyCruiser.allExtensions), true);
strictEqual(typeof dependencyCruiser.getAvailableTranspilers, "function");
equal(typeof dependencyCruiser, "object");
equal(typeof dependencyCruiser.cruise, "function");
equal(typeof dependencyCruiser.format, "function");
equal(Array.isArray(dependencyCruiser.allExtensions), true);
equal(typeof dependencyCruiser.getAvailableTranspilers, "function");
});

it("exposes an extract-babel-config function", () => {
strictEqual(typeof extractBabelConfig, "function");
equal(typeof extractBabelConfig, "function");
});

it("exposes an extract-depcruise-config function", () => {
strictEqual(typeof extractDepcruiseConfig, "function");
equal(typeof extractDepcruiseConfig, "function");
});

it("exposes an extract-ts-config function", () => {
strictEqual(typeof extractTsConfig, "function");
equal(typeof extractTsConfig, "function");
});

it("exposes an extract-webpack-resolve-config function", () => {
strictEqual(typeof extractWebpackResolveConfig, "function");
equal(typeof extractWebpackResolveConfig, "function");
});
});
}
31 changes: 14 additions & 17 deletions test/cache/cache.spec.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deepStrictEqual, strictEqual } from "node:assert";
import { deepEqual, equal } from "node:assert/strict";
import { rmSync } from "node:fs";
import { join } from "node:path";
import { isDeepStrictEqual } from "node:util";
Expand All @@ -10,26 +10,23 @@ const OUTPUTS_FOLDER = "test/cache/__outputs__/";
describe("[I] cache/cache - readCache", () => {
it("returns an empty cache when trying to read from a non-existing one", async () => {
const lCache = new Cache();
deepStrictEqual(await lCache.read("this/folder/does/not-exist"), {
deepEqual(await lCache.read("this/folder/does/not-exist"), {
modules: [],
summary: {},
});
});

it("returns an empty cache when trying to read from a file that is invalid JSON", async () => {
const lCache = new Cache();
deepStrictEqual(
await lCache.read("test/cache/__mocks__/cache/invalid-json"),
{
modules: [],
summary: {},
},
);
deepEqual(await lCache.read("test/cache/__mocks__/cache/invalid-json"), {
modules: [],
summary: {},
});
});

it("returns the contents of the cache when trying to read from an existing, valid json", async () => {
const lCache = new Cache();
deepStrictEqual(
deepEqual(
await lCache.read("test/cache/__mocks__/cache/valid-minimal-cache"),
{
modules: [],
Expand Down Expand Up @@ -57,7 +54,7 @@ describe("[I] cache/cache - writeCache", () => {
const lCache = new Cache();

await lCache.write(lCacheFolder, lDummyCacheContents);
deepStrictEqual(await lCache.read(lCacheFolder), lDummyCacheContents);
deepEqual(await lCache.read(lCacheFolder), lDummyCacheContents);
});

it("writes the passed cruise options to the cache folder (folder already exists -> overwrite)", async () => {
Expand All @@ -72,7 +69,7 @@ describe("[I] cache/cache - writeCache", () => {

await lCache.write(lCacheFolder, lDummyCacheContents);
await lCache.write(lCacheFolder, lSecondDummyCacheContents);
deepStrictEqual(await lCache.read(lCacheFolder), lSecondDummyCacheContents);
deepEqual(await lCache.read(lCacheFolder), lSecondDummyCacheContents);
});

it("writes the passed cruise options to the cache folder (which is created when it doesn't exist yet) - content based cached strategy", async () => {
Expand Down Expand Up @@ -124,7 +121,7 @@ describe("[I] cache/cache - canServeFromCache", () => {
changes: [],
},
);
strictEqual(lResult, false);
equal(lResult, false);
});

it("returns false when the base SHA differs", async () => {
Expand All @@ -142,7 +139,7 @@ describe("[I] cache/cache - canServeFromCache", () => {
},
);

strictEqual(lFound, false);
equal(lFound, false);
});

it("returns false when a file was added", async () => {
Expand All @@ -166,7 +163,7 @@ describe("[I] cache/cache - canServeFromCache", () => {
},
);

strictEqual(lFound, false);
equal(lFound, false);
});

it("returns false when cache written & revision data equal & options incompatible", async () => {
Expand All @@ -184,7 +181,7 @@ describe("[I] cache/cache - canServeFromCache", () => {
{ SHA1: "dummy-sha", changes: [] },
);

strictEqual(lFound, false);
equal(lFound, false);
});

it("returns true when cache written & revision data equal & options compatible", async () => {
Expand All @@ -198,6 +195,6 @@ describe("[I] cache/cache - canServeFromCache", () => {
{ SHA1: "dummy-sha", changes: [] },
);

strictEqual(lFound, true);
equal(lFound, true);
});
});
28 changes: 14 additions & 14 deletions test/cache/content-strategy.spec.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deepStrictEqual, strictEqual } from "node:assert";
import { deepEqual, equal } from "node:assert/strict";
import ContentStrategy from "../../src/cache/content-strategy.mjs";

const INTERESTING_EXTENSIONS = new Set([".aap", ".noot", ".mies"]);
Expand Down Expand Up @@ -37,7 +37,7 @@ describe("[U] cache/content-strategy - getRevisionData", () => {
],
};

deepStrictEqual(
deepEqual(
new ContentStrategy().getRevisionData(
null,
null,
Expand All @@ -54,7 +54,7 @@ describe("[U] cache/content-strategy - getRevisionData", () => {
});

it("if there's no changes the change set contains the passed sha & an empty array", () => {
deepStrictEqual(
deepEqual(
new ContentStrategy().getRevisionData(
null,
null,
Expand All @@ -76,7 +76,7 @@ describe("[U] cache/content-strategy - getRevisionData", () => {
it("returns only the extensions passed", () => {
const lLimitedExtensions = new Set([".wim", ".noot"]);

deepStrictEqual(
deepEqual(
new ContentStrategy().getRevisionData(
".",
{ modules: [] },
Expand Down Expand Up @@ -131,7 +131,7 @@ describe("[U] cache/content-strategy - getRevisionData", () => {
},
];

deepStrictEqual(
deepEqual(
new ContentStrategy().getRevisionData(
null,
null,
Expand Down Expand Up @@ -186,11 +186,11 @@ describe("[U] cache/content-strategy - revisionDataEqual", () => {
];

it("returns false when revision data objects don't exist", () => {
strictEqual(new ContentStrategy().revisionDataEqual(null, null), false);
equal(new ContentStrategy().revisionDataEqual(null, null), false);
});

it("returns false when old revision data object doesn't exist", () => {
strictEqual(
equal(
new ContentStrategy().revisionDataEqual(null, {
SHA1: "some-sha",
changes: [],
Expand All @@ -200,7 +200,7 @@ describe("[U] cache/content-strategy - revisionDataEqual", () => {
});

it("returns false when new revision data object doesn't exist", () => {
strictEqual(
equal(
new ContentStrategy().revisionDataEqual(
{ SHA1: "some-sha", changes: [] },
null,
Expand All @@ -210,7 +210,7 @@ describe("[U] cache/content-strategy - revisionDataEqual", () => {
});

it("returns false when changes are not equal", () => {
strictEqual(
equal(
new ContentStrategy().revisionDataEqual(
{ SHA1: "some-sha", changes: [] },
{ SHA1: "some-sha", changes: lChanges },
Expand All @@ -220,7 +220,7 @@ describe("[U] cache/content-strategy - revisionDataEqual", () => {
});

it("returns true when changes are equal", () => {
strictEqual(
equal(
new ContentStrategy().revisionDataEqual(
{ SHA1: "some-sha", changes: lChanges },
{ SHA1: "some-sha", changes: lChanges },
Expand All @@ -230,7 +230,7 @@ describe("[U] cache/content-strategy - revisionDataEqual", () => {
});

it("returns true when changes are equal (even when neither contain changes)", () => {
strictEqual(
equal(
new ContentStrategy().revisionDataEqual(
{ SHA1: "some-sha", changes: [] },
{ SHA1: "some-sha", changes: [] },
Expand Down Expand Up @@ -274,7 +274,7 @@ describe("[U] cache/content-strategy - prepareRevisionDataForSaving", () => {
revisionData: lEmptyRevisionData,
};

deepStrictEqual(
deepEqual(
new ContentStrategy().prepareRevisionDataForSaving(
lEmptyCruiseResult,
lEmptyRevisionData,
Expand Down Expand Up @@ -333,7 +333,7 @@ describe("[U] cache/content-strategy - prepareRevisionDataForSaving", () => {
revisionData: lEmptyRevisionData,
};

deepStrictEqual(
deepEqual(
new ContentStrategy().prepareRevisionDataForSaving(
lEmptyCruiseResult,
lEmptyRevisionData,
Expand Down Expand Up @@ -422,7 +422,7 @@ describe("[U] cache/content-strategy - prepareRevisionDataForSaving", () => {
},
};

deepStrictEqual(
deepEqual(
new ContentStrategy().prepareRevisionDataForSaving(
lCruiseResult,
lRevisionData,
Expand Down
22 changes: 11 additions & 11 deletions test/cache/find-content-changes.spec.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { deepStrictEqual } from "node:assert";
import { deepEqual } from "node:assert/strict";
import findContentChanges from "../../src/cache/find-content-changes.mjs";

describe("[U] cache/find-content-changes - cached vs new", () => {
it("returns files not in directory but in cache as 'ignored' when they're not interesting for diffing", () => {
deepStrictEqual(
deepEqual(
findContentChanges(
".",
{
Expand Down Expand Up @@ -55,7 +55,7 @@ describe("[U] cache/find-content-changes - cached vs new", () => {
});

it("returns files not in directory but in cache as 'deleted'", () => {
deepStrictEqual(
deepEqual(
findContentChanges(
".",
{ modules: [{ source: "only-in-cache-ends-up-as-deleted.js" }] },
Expand All @@ -76,7 +76,7 @@ describe("[U] cache/find-content-changes - cached vs new", () => {
});

it("returns files that have been earmarked as not followable as 'ignored'", () => {
deepStrictEqual(
deepEqual(
findContentChanges(
".",
{
Expand Down Expand Up @@ -105,7 +105,7 @@ describe("[U] cache/find-content-changes - cached vs new", () => {
});

it("returns files both in directory and in cache that are different as 'modified'", () => {
deepStrictEqual(
deepEqual(
findContentChanges(
".",
{
Expand Down Expand Up @@ -142,7 +142,7 @@ describe("[U] cache/find-content-changes - cached vs new", () => {
});

it("returns files both in directory and in cache that are the same as 'unmodified'", () => {
deepStrictEqual(
deepEqual(
findContentChanges(
".",
{
Expand Down Expand Up @@ -173,7 +173,7 @@ describe("[U] cache/find-content-changes - cached vs new", () => {

describe("[U] cache/find-content-changes - new vs cached", () => {
it("returns an empty set when the directory and modules are empty", () => {
deepStrictEqual(
deepEqual(
findContentChanges(
".",
{ modules: [] },
Expand All @@ -189,7 +189,7 @@ describe("[U] cache/find-content-changes - new vs cached", () => {
});

it("returns changes when there's file in the directory and modules is empty (extensions only)", () => {
deepStrictEqual(
deepEqual(
findContentChanges(
".",
{ modules: [] },
Expand All @@ -211,7 +211,7 @@ describe("[U] cache/find-content-changes - new vs cached", () => {
});

it("returns changes when there's file in the directory and modules is empty (missing includeOnly filter)", () => {
deepStrictEqual(
deepEqual(
findContentChanges(
".",
{ modules: [] },
Expand All @@ -232,7 +232,7 @@ describe("[U] cache/find-content-changes - new vs cached", () => {
});

it("returns changes when there's file in the directory and modules is empty (exclude filter)", () => {
deepStrictEqual(
deepEqual(
findContentChanges(
".",
{ modules: [] },
Expand All @@ -254,7 +254,7 @@ describe("[U] cache/find-content-changes - new vs cached", () => {
});

it("returns changes when there's file in the directory and modules is empty (includeOnly filter)", () => {
deepStrictEqual(
deepEqual(
findContentChanges(
".",
{ modules: [] },
Expand Down
Loading

0 comments on commit 2344164

Please sign in to comment.