Skip to content

Commit

Permalink
Handle the case when CSS or JavaScript files do not exist in the pack…
Browse files Browse the repository at this point in the history
…age.
  • Loading branch information
njostonehouse committed Nov 24, 2014
1 parent 7b5319b commit f2ab425
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 16 deletions.
37 changes: 21 additions & 16 deletions lib/loadByFileSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 7 additions & 0 deletions test/data/test3.package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Package Name="TestPackage3" xmlns="http://schemas.desire2learn.com/xml/schemas/package.xsd">
<JavaScript>
<File Path="file3.js" />
<File Path="file4.js" />
<File/>
</JavaScript>
</Package>
7 changes: 7 additions & 0 deletions test/data/test4.package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Package Name="TestPackage4" xmlns="http://schemas.desire2learn.com/xml/schemas/package.xsd">
<Css>
<File Path="file3.css" />
<File Path="file4.css" />
<File/>
</Css>
</Package>
10 changes: 10 additions & 0 deletions test/loadByFileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
});

} );

0 comments on commit f2ab425

Please sign in to comment.