Skip to content
Open
Changes from all 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
24 changes: 24 additions & 0 deletions test/package/environments/base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,30 @@ 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)
const flattenedArrayEntries = arrayEntries.flat()

expect(stringEntries.length + arrayEntries.length).toBe(
entryValues.length
)
expect(stringEntries.length).toBeGreaterThan(0)
expect(arrayEntries.length).toBeGreaterThan(0)
expect(stringEntries.every((entryValue) => entryValue.length > 0)).toBe(
Comment on lines +71 to +72
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.

This assertion makes the test fragile. It requires the fixture data to always contain both single-file entries (strings) and multi-file entries (arrays) simultaneously. If a future fixture change removes either shape, the test fails for the wrong reason — it's testing the fixture's contents, not the production logic.

Consider either:

  1. Removing these two toBeGreaterThan(0) guards and letting the forEach assertions below be the actual invariant (they'll trivially pass over an empty array, which is fine), or
  2. Pinning this to known fixture entry names (application → string, multi_entry → array) as the adjacent tests already do, which is explicit about what's being verified.

true
)
expect(flattenedArrayEntries.length).toBeGreaterThan(0)
expect(
flattenedArrayEntries.every(
(entryValue) => typeof entryValue === "string"
)
).toBe(true)
})
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