Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion src/actions/__tests__/sponsor-purchases-actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ jest.mock("openstack-uicore-foundation/lib/utils/actions", () => ({
}))
}));

// webpack inlines this asset as a data URI, the generic png file mock would return {}
jest.mock(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This mocks the logo import as a data URI, so the assertion still passes if the webpack rule is removed. I reverted webpack.common.js to master and all three invoice tests stayed green. It does catch the action passing a URL directly, but it doesn't guard the actual fix. Should we add a small check that fails when the inline rule stops applying? For example, compile the logo import and assert a PNG data URI comes out with no emitted image file. Otherwise a future edit to the rule brings the bug back with CI green.

Side note: because moduleNameMapper sends every .png to fileMock.js, this jest.mock makes every image import in this test file return the logo string, not just the logo.

"../../assets/fn-invoice-header.png",
() => "data:image/png;base64,TEST"
);

jest.mock(
"openstack-uicore-foundation/lib/components/order-invoice-pdf",
() => ({
Expand Down Expand Up @@ -93,7 +99,9 @@ describe("downloadSponsorInvoice", () => {
expect(generateInvoicePDF).toHaveBeenCalledWith(
fetchedOrder,
{ id: 1 },
expect.objectContaining({ logoSrc: expect.anything() })
expect.objectContaining({
logoSrc: expect.stringMatching(/^data:image\/png;base64,/)
})
);
expect(snackbarErrorMsg).not.toHaveBeenCalled();
});
Expand Down
6 changes: 6 additions & 0 deletions webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,14 @@ module.exports = {
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: "asset/resource"
},
{
// inline the invoice logo so react-pdf never fetches it (CDN may serve WebP, react-pdf caches failures)
test: /fn-invoice-header\.png$/,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit, fine as is since the ticket allows it: the filename regex is repeated in the inline rule and in the exclude, so renaming the asset quietly falls back to file-loader. An ?inline import with a resourceQuery rule would avoid keeping the two in sync.

type: "asset/inline"
},
{
test: /\.jpg|\.png|\.gif$/,
exclude: /fn-invoice-header\.png$/,
use: "file-loader?name=images/[name].[ext]"
},
{
Expand Down
Loading