Skip to content

Commit

Permalink
Fix FA5 import & add test for FA5 (#236)
Browse files Browse the repository at this point in the history
* Fix FA5 import & add test

* Fix test

---------

Co-authored-by: Markus Sanin <[email protected]>
  • Loading branch information
mkszepp and mkszepp authored Aug 28, 2023
1 parent 50c5d0f commit 170f445
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
try-scenario:
- ember-lts-3.20
- ember-lts-3.24
- ember-lts-3.24-with-fa5
- ember-release
- ember-classic
- ember-default-with-jquery
Expand Down
11 changes: 11 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ module.exports = async function () {
},
},
},
{
name: 'ember-lts-3.24-with-fa5',
npm: {
devDependencies: {
'ember-source': '~3.24.3',
'@fortawesome/free-brands-svg-icons': '^5.15.4',
'@fortawesome/free-regular-svg-icons': '^5.15.4',
'@fortawesome/free-solid-svg-icons': '^5.15.4',
},
},
},
{
name: 'ember-release',
npm: {
Expand Down
132 changes: 124 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"ember-cli-inject-live-reload": "^2.1.0",
"ember-cli-sri": "^2.1.1",
"ember-cli-terser": "^4.0.2",
"ember-compatibility-helpers": "^1.2.6",
"ember-disable-prototype-extensions": "^1.1.3",
"ember-export-application-global": "^2.0.1",
"ember-load-initializers": "^2.1.2",
Expand Down
22 changes: 14 additions & 8 deletions tests/integration/components/fa-icon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { setupRenderingTest } from 'ember-qunit';
import { render, find } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { htmlSafe } from '@ember/template';
import { gte } from 'ember-compatibility-helpers';

const faCoffee = {
prefix: 'fas',
Expand Down Expand Up @@ -210,16 +211,21 @@ module('Integration | Component | fa icon', function (hooks) {
test('it renders trash-alt (alias) ', async function (assert) {
await render(hbs`<FaIcon @icon="trash-alt" />`);

let icon = 'trash-can';
let path =
'M135.2 17.7C140.6 6.8 151.7 0 163.8 0H284.2c12.1 0 23.2 6.8 28.6 17.7L320 32h96c17.7 0 32 14.3 32 32s-14.3 32-32 32H32C14.3 96 0 81.7 0 64S14.3 32 32 32h96l7.2-14.3zM32 128H416V448c0 35.3-28.7 64-64 64H96c-35.3 0-64-28.7-64-64V128zm96 64c-8.8 0-16 7.2-16 16V432c0 8.8 7.2 16 16 16s16-7.2 16-16V208c0-8.8-7.2-16-16-16zm96 0c-8.8 0-16 7.2-16 16V432c0 8.8 7.2 16 16 16s16-7.2 16-16V208c0-8.8-7.2-16-16-16zm96 0c-8.8 0-16 7.2-16 16V432c0 8.8 7.2 16 16 16s16-7.2 16-16V208c0-8.8-7.2-16-16-16z';

if (!gte('@fortawesome/free-brands-svg-icons', '6.0.0')) {
icon = 'trash-alt';
path =
'M32 464a48 48 0 0 0 48 48h288a48 48 0 0 0 48-48V128H32zm272-256a16 16 0 0 1 32 0v224a16 16 0 0 1-32 0zm-96 0a16 16 0 0 1 32 0v224a16 16 0 0 1-32 0zm-96 0a16 16 0 0 1 32 0v224a16 16 0 0 1-32 0zM432 32H312l-9.4-18.7A24 24 0 0 0 281.1 0H166.8a23.72 23.72 0 0 0-21.4 13.3L136 32H16A16 16 0 0 0 0 48v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16V48a16 16 0 0 0-16-16z';
}

assert.dom('*').hasText('');
assert.dom('svg').hasAttribute('data-icon', 'trash-can');
assert.dom('svg').hasAttribute('data-icon', icon);
assert.ok(
find('svg').getAttribute('class').split(/\s+/).includes('fa-trash-can')
find('svg').getAttribute('class').split(/\s+/).includes(`fa-${icon}`)
);
assert
.dom('svg path')
.hasAttribute(
'd',
'M135.2 17.7C140.6 6.8 151.7 0 163.8 0H284.2c12.1 0 23.2 6.8 28.6 17.7L320 32h96c17.7 0 32 14.3 32 32s-14.3 32-32 32H32C14.3 96 0 81.7 0 64S14.3 32 32 32h96l7.2-14.3zM32 128H416V448c0 35.3-28.7 64-64 64H96c-35.3 0-64-28.7-64-64V128zm96 64c-8.8 0-16 7.2-16 16V432c0 8.8 7.2 16 16 16s16-7.2 16-16V208c0-8.8-7.2-16-16-16zm96 0c-8.8 0-16 7.2-16 16V432c0 8.8 7.2 16 16 16s16-7.2 16-16V208c0-8.8-7.2-16-16-16zm96 0c-8.8 0-16 7.2-16 16V432c0 8.8 7.2 16 16 16s16-7.2 16-16V208c0-8.8-7.2-16-16-16z'
);
assert.dom('svg path').hasAttribute('d', path);
});
});
9 changes: 8 additions & 1 deletion vendor/broccoli-fontawesome-pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,17 @@ class FontAwesomePack extends Plugin {


const packageContents = () => {
const pathToModule = require.resolve(`@fortawesome/${this.options.pack}`)
const moduleDir = path.dirname(pathToModule);
const files = fs.readdirSync(moduleDir);
let entryFile = 'index';
if (files.find((file) => file === 'index.es.js')) {
entryFile = 'index.es.js';
}
return `
export {
${selectedIcons.join(',')}
} from '@fortawesome/${this.options.pack}/index'
} from '@fortawesome/${this.options.pack}/${entryFile}'
`;
}
const _thisPlugin = this
Expand Down

0 comments on commit 170f445

Please sign in to comment.