Skip to content

Commit

Permalink
update normalizePath tests to follow a table test format
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholas-codecov committed Dec 19, 2023
1 parent 4f8459b commit aca3bd3
Showing 1 changed file with 63 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,35 +1,70 @@
import { normalizePath } from "../normalizePath";

describe("normalizePath", () => {
describe("when the format contains a hash", () => {
describe("normalizedPath has hash replaced with wildcard", () => {
it("returns the normalized path", () => {
const result = normalizePath(
"test.123.chunk.js",
"[name].[hash].chunk.js",
);

expect(result).toEqual("test.*.chunk.js");
});
});

describe("normalizedPath doe not have hash replaced with wildcard", () => {
it("returns the normalized path", () => {
const result = normalizePath(
"test.12345678.chunk.js",
"[name]-[hash].chunk.js",
);
interface Test {
name: string;
input: {
path: string;
format: string;
};
expected: string;
}

expect(result).toEqual("test.*.chunk.js");
});
});
});
const tests: Test[] = [
{
name: "should replace '[hash]' with '*'",
input: {
path: "test.123.chunk.js",
format: "[name].[hash].chunk.js",
},
expected: "test.*.chunk.js",
},
{
name: "should replace '[contenthash]' with '*'",
input: {
path: "test.123.chunk.js",
format: "[name].[contenthash].chunk.js",
},
expected: "test.*.chunk.js",
},
{
name: "should replace '[fullhash]' with '*'",
input: {
path: "test.123.chunk.js",
format: "[name].[fullhash].chunk.js",
},
expected: "test.*.chunk.js",
},
{
name: "should replace '[chunkhash]' with '*'",
input: {
path: "test.123.chunk.js",
format: "[name].[chunkhash].chunk.js",
},
expected: "test.*.chunk.js",
},
{
name: "should replace multiple hash format occurrences '*'",
input: {
path: "test.123.456.chunk.js",
format: "[name].[hash].[chunkhash].chunk.js",
},
expected: "test.*.*.chunk.js",
},
{
name: "should brute force wildcard if no hash format is found",
input: {
path: "test.12345678.chunk.js",
format: "[name].chunk.js",
},
expected: "test.*.chunk.js",
},
];

describe("when the format does not contain any hash", () => {
it("returns the passed path", () => {
const result = normalizePath("test.js", "[name].js");

expect(result).toEqual("test.js");
describe("normalizePath", () => {
tests.forEach((test) => {
it(test.name, () => {
const expectation = normalizePath(test.input.path, test.input.format);
expect(expectation).toEqual(test.expected);
});
});
});

0 comments on commit aca3bd3

Please sign in to comment.