diff --git a/lib/loadByFileSync.js b/lib/loadByFileSync.js
index 7b6f5fd..dfabbf7 100644
--- a/lib/loadByFileSync.js
+++ b/lib/loadByFileSync.js
@@ -21,28 +21,33 @@ module.exports = function( packagePath ) {
var jsFiles = xml.get(
'//xmlns:JavaScript',
'http://schemas.desire2learn.com/xml/schemas/package.xsd'
- ).childNodes();
+ );
filePaths.JavaScript = [];
- jsFiles.forEach(function( jsFile ) {
- var filePath = jsFile.attr("Path");
- if( filePath ) {
- filePath = path.join( dir, filePath.value() );
- filePaths.JavaScript.push( filePath );
- }
- });
+ if( jsFiles ) {
+ jsFiles.childNodes().forEach(function( jsFile ) {
+ var filePath = jsFile.attr("Path");
+ if( filePath ) {
+ filePath = path.join( dir, filePath.value() );
+ filePaths.JavaScript.push( filePath );
+ }
+ });
+ }
var cssFiles = xml.get(
'//xmlns:Css',
'http://schemas.desire2learn.com/xml/schemas/package.xsd'
- ).childNodes();
+ );
+
filePaths.Css = [];
- cssFiles.forEach(function( jsFile ) {
- var filePath = jsFile.attr("Path");
- if( filePath ) {
- filePath = path.join( dir, filePath.value() );
- filePaths.Css.push( filePath );
- }
- });
+ if( cssFiles ) {
+ cssFiles.childNodes().forEach( function( cssFile ) {
+ var filePath = cssFile.attr("Path");
+ if( filePath ) {
+ filePath = path.join( dir, filePath.value() );
+ filePaths.Css.push( filePath );
+ }
+ });
+ }
return filePaths;
diff --git a/test/data/test3.package.xml b/test/data/test3.package.xml
new file mode 100644
index 0000000..58c46ac
--- /dev/null
+++ b/test/data/test3.package.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/test/data/test4.package.xml b/test/data/test4.package.xml
new file mode 100644
index 0000000..c8c32f4
--- /dev/null
+++ b/test/data/test4.package.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/test/loadByFileSpec.js b/test/loadByFileSpec.js
index 5ca9362..cb33b4c 100644
--- a/test/loadByFileSpec.js
+++ b/test/loadByFileSpec.js
@@ -49,4 +49,14 @@ describe( 'Load By File (Synchronous)', function() {
}).toThrow();
} );
+ it( 'Should not fail with missing Css list.', function() {
+ var files = webPackageReader.loadByFileSync( path.join( dataPath, 'test3.package.xml' ) );
+ expect( files.Css.length ).toBe( 0 );
+ });
+
+ it( 'Should not fail with missing JavaScript list.', function() {
+ var files = webPackageReader.loadByFileSync( path.join( dataPath, 'test4.package.xml' ) );
+ expect( files.JavaScript.length ).toBe( 0 );
+ });
+
} );