-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update normalizePath tests to follow a table test format
- Loading branch information
1 parent
4f8459b
commit aca3bd3
Showing
1 changed file
with
63 additions
and
28 deletions.
There are no files selected for viewing
91 changes: 63 additions & 28 deletions
91
packages/bundler-plugin-core/src/utils/__tests__/normalizePath.test.ts
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,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); | ||
}); | ||
}); | ||
}); |