Skip to content
Open
Changes from 6 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
19 changes: 19 additions & 0 deletions test/package/environments/base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@ describe("Base config", () => {
expect(baseConfig.entry["generated/something"]).toBeUndefined()
})

test("keeps entry value shapes stable for TypeScript narrowing", () => {
const entryValues = Object.values(baseConfig.entry)
const stringEntries = entryValues.filter(
(entryValue) => typeof entryValue === "string"
)
const arrayEntries = entryValues.filter(Array.isArray)

expect(stringEntries.length + arrayEntries.length).toBe(
entryValues.length
)

arrayEntries.forEach((entryValue) => {
expect(entryValue.length).toBeGreaterThan(0)
entryValue.forEach((value) => {
expect(typeof value).toBe("string")
})
})
})
Comment on lines +68 to +81
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .every(...).toBe(true) pattern gives very poor failure messages — when a value fails the predicate, Jest just says expected false to be true with no indication of which value failed or what it was.

Prefer individual assertions per entry using forEach, or at minimum use toStrictEqual on a mapped result:

Suggested change
entryValues.length
)
expect(stringEntries.length).toBeGreaterThan(0)
expect(arrayEntries.length).toBeGreaterThan(0)
expect(stringEntries.every((entryValue) => entryValue.length > 0)).toBe(
true
)
expect(flattenedArrayEntries.length).toBeGreaterThan(0)
expect(
flattenedArrayEntries.every(
(entryValue) => typeof entryValue === "string"
)
).toBe(true)
})
expect(stringEntries.length + arrayEntries.length).toBe(
entryValues.length
)
expect(stringEntries.length).toBeGreaterThan(0)
expect(arrayEntries.length).toBeGreaterThan(0)
stringEntries.forEach((entryValue) =>
expect(typeof entryValue).toBe("string")
)
expect(flattenedArrayEntries.length).toBeGreaterThan(0)
flattenedArrayEntries.forEach((entryValue) =>
expect(typeof entryValue).toBe("string")
)

This way, a failure names the offending value directly.


test("should returns top level and nested entry points with config.nested_entries == true", () => {
process.env.SHAKAPACKER_CONFIG = "config/shakapacker_nested_entries.yml"
const config2 = require("../../../package/config")
Expand Down
Loading