Skip to content

Commit

Permalink
fix: fixes cdn helper early hint construction (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafa-avila-bc authored May 9, 2023
1 parent 58d3cd2 commit 9955e92
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion helpers/cdn.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const factory = globals => {
globals,
fullPath,
options.hash.resourceHint,
options.hash.as
options.hash.as,
options.hash.crossorigin
);
}

Expand Down
10 changes: 6 additions & 4 deletions spec/helpers/cdn.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,24 @@ describe('cdn helper', function () {
const runTestCases = testRunner({context, renderer});
runTestCases([
{
input: '{{cdn "assets/css/style.css" resourceHint="preload" as="style"}}',
input: '{{cdn "assets/css/style.css" resourceHint="preload" as="style" crossorigin="use-credentials"}}',
output: 'https://cdn.bcapp/3dsf74g/stencil/123/css/style.css',
},
{
input: '{{cdn "/assets/css/style.modal.css" resourceHint="preconnect" as="style"}}',
input: '{{cdn "/assets/css/style.modal.css" resourceHint="preconnect" as="style" crossorigin="anonymous"}}',
output: 'https://cdn.bcapp/3dsf74g/stencil/123/css/style.modal.css',
},
{
input: '{{cdn "/assets/css/style.modal.css" as="style"}}',
input: '{{cdn "/assets/css/style.modal.css" as="style" crossorigin="use-credentials"}}',
output: 'https://cdn.bcapp/3dsf74g/stencil/123/css/style.modal.css',
}
], () => {
const hints = renderer.getResourceHints();
expect(hints).to.have.length(2);
hints.forEach(hint => {
expect(hint.state).to.satisfy((state) => state === 'preload' || state === 'preconnect');
expect(hint.type).to.equals("style")
expect(hint.type).to.equals("style");
expect(hint.cors).to.satisfy((cors) => cors === 'anonymous' || cors === 'use-credentials');
});
done();
});
Expand All @@ -65,6 +66,7 @@ describe('cdn helper', function () {
hints.forEach(hint => {
expect(hint.state).to.equals('preload');
expect(hint.type).to.not.exist();
expect(hint.cors).to.equals('no');
});
done();
});
Expand Down

0 comments on commit 9955e92

Please sign in to comment.