Skip to content

Commit

Permalink
Add support for <fest:script/>
Browse files Browse the repository at this point in the history
  • Loading branch information
ogonkov committed Aug 31, 2020
1 parent ef98a04 commit 661d92a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/get-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const readFile = util.promisify(fs.readFile);
* @return {boolean}
*/
function hasAttributes({item: [attributes]}) {
return attributes && NODE_ATTRIBUTES in attributes;
return Boolean(attributes?.[NODE_ATTRIBUTES]);
}

function getSrcAttribute({item: [attributes]}) {
Expand All @@ -27,7 +27,8 @@ async function getFileImports(source) {
const root = await getParser().then((parseString) => parseString(source));
const nodes = filterNodes(root, [
'fest:include',
'fest:insert'
'fest:insert',
'fest:script'
]);

return new Set(
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/include.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<fest:template xmlns:fest="http://fest.mail.ru" context_name="json">
Simple include

<fest:script>
<![CDATA[
console.log('Hello, again.');
]]>
</fest:script>
</fest:template>
1 change: 1 addition & 0 deletions test/fixtures/nested-dependency.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<fest:template xmlns:fest="http://fest.mail.ru" context_name="json">
<fest:include context="json.list" src="./include.xml"/>
<fest:script src="./script.js"/>
</fest:template>
1 change: 1 addition & 0 deletions test/fixtures/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello, world');
5 changes: 4 additions & 1 deletion test/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('dependencies parse', function() {
return done(err);
}

expect(context.addDependency).toHaveBeenCalledTimes(3);
expect(context.addDependency).toHaveBeenCalledTimes(4);
expect(context.addDependency).toHaveBeenCalledWith(
expect.stringMatching('nested-dependency.xml')
);
Expand All @@ -62,6 +62,9 @@ describe('dependencies parse', function() {
expect(context.addDependency).toHaveBeenCalledWith(
expect.stringMatching('include.xml')
);
expect(context.addDependency).toHaveBeenCalledWith(
expect.stringMatching('script.js')
);

done();
}
Expand Down

0 comments on commit 661d92a

Please sign in to comment.