Skip to content

Commit

Permalink
Merge pull request #131 from FrederikNS/master
Browse files Browse the repository at this point in the history
CP-1770 expandedFiles now update when files are added/removed.
  • Loading branch information
jayudey-wf committed May 13, 2016
2 parents 06eae4c + 587cbe2 commit b4faa9e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

var initJspm = require('./src/init');

initJspm.$inject = ['config.files', 'config.basePath', 'config.jspm', 'config.client'];
initJspm.$inject = ['config.files', 'config.basePath', 'config.jspm', 'config.client', 'emitter'];

module.exports = {
'framework:jspm': ['factory', initJspm]
Expand Down
15 changes: 10 additions & 5 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function getJspmPackageJson(dir) {
return pjson;
}

module.exports = function(files, basePath, jspm, client) {
module.exports = function(files, basePath, jspm, client, emitter) {
// Initialize jspm config if it wasn't specified in karma.conf.js
if(!jspm)
jspm = {};
Expand Down Expand Up @@ -109,10 +109,15 @@ module.exports = function(files, basePath, jspm, client) {
// 1. Add all the files as "served" files to the files array
// 2. Expand out and globs to end up with actual files for jspm to load.
// Store that in client.jspm.expandedFiles
client.jspm.expandedFiles = flatten(jspm.loadFiles.map(function(file){
files.push(createServedPattern(basePath + "/" + (file.pattern || file), file.nocache || false));
return expandGlob(file, basePath);
}));
function addExpandedFiles() {
client.jspm.expandedFiles = flatten(jspm.loadFiles.map(function(file){
files.push(createServedPattern(basePath + "/" + (file.pattern || file), file.nocache || false));
return expandGlob(file, basePath);
}));
}
addExpandedFiles();

emitter.on('file_list_modified', addExpandedFiles);

// Add served files to files array
jspm.serveFiles.map(function(file){
Expand Down
7 changes: 5 additions & 2 deletions test/testInit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var normalPath = function(path){
}

describe('jspm plugin init', function(){
var files, jspm, client;
var files, jspm, client, emitter;
var basePath = path.resolve(__dirname, '..');

beforeEach(function(){
Expand All @@ -20,8 +20,11 @@ describe('jspm plugin init', function(){
serveFiles: ['testfile.js']
};
client = {};
emitter = {
on: function() {}
}

initJspm(files, basePath, jspm, client);
initJspm(files, basePath, jspm, client, emitter);
});

it('should add config.js to the top of the files array', function(){
Expand Down

0 comments on commit b4faa9e

Please sign in to comment.