Skip to content

Commit 3999ab7

Browse files
committed
Merge pull request #115 from comdiv/114
CP-1340 feat(config): nocache support for jspm.loadFiles Closes #114 (additionally #113)
2 parents 0a653c3 + 188935a commit 3999ab7

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/init.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ var createPattern = function(path) {
3131
return {pattern: path, included: true, served: true, watched: false};
3232
};
3333

34-
var createServedPattern = function(path){
35-
return {pattern: path, included: false, served: true, watched: true};
34+
var createServedPattern = function(path, nocache){
35+
nocache = nocache || false;
36+
return {pattern: path, included: false, served: true, nocache:nocache, watched: true};
3637
};
3738

3839
function getJspmPackageJson(dir) {
@@ -108,7 +109,7 @@ module.exports = function(files, basePath, jspm, client) {
108109
// 2. Expand out and globs to end up with actual files for jspm to load.
109110
// Store that in client.jspm.expandedFiles
110111
client.jspm.expandedFiles = flatten(jspm.loadFiles.map(function(file){
111-
files.push(createServedPattern(basePath + "/" + (file.pattern || file)));
112+
files.push(createServedPattern(basePath + "/" + (file.pattern || file), file.nocache || false));
112113
return expandGlob(file, basePath);
113114
}));
114115

test/testInit.spec.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ var cwd = process.cwd();
22
var path = require('path');
33
var initJspm = require('../src/init');
44

5+
var normalPath = function(path){
6+
return path.replace(/\\/g,'/');
7+
}
58

69
describe('jspm plugin init', function(){
710
var files, jspm, client;
@@ -11,7 +14,7 @@ describe('jspm plugin init', function(){
1114
files = [];
1215
jspm = {
1316
config: 'custom_config.js',
14-
loadFiles: ['src/**/*.js'],
17+
loadFiles: ['src/**/*.js',{pattern:'not-cached.js', nocache:true}],
1518
packages: 'custom_packages/',
1619
serveFiles: ['testfile.js']
1720
};
@@ -21,22 +24,22 @@ describe('jspm plugin init', function(){
2124
});
2225

2326
it('should add config.js to the top of the files array', function(){
24-
expect(files[3].pattern).toEqual(basePath + '/custom_config.js');
27+
expect(normalPath(files[3].pattern)).toEqual(normalPath(basePath + '/custom_config.js'));
2528
expect(files[3].included).toEqual(true);
2629
});
2730

2831
it('should add adapter.js to the top of the files array', function(){
29-
expect(files[2].pattern).toEqual(basePath + '/src/adapter.js');
32+
expect(normalPath(files[2].pattern)).toEqual(normalPath(basePath + '/src/adapter.js'));
3033
expect(files[2].included).toEqual(true);
3134
});
3235

3336
it('should add systemjs-polyfills to the top of the files array', function(){
34-
expect(files[1].pattern).toEqual(basePath + '/custom_packages/system-polyfills.src.js');
37+
expect(normalPath(files[1].pattern)).toEqual(normalPath(basePath + '/custom_packages/system-polyfills.src.js'));
3538
expect(files[1].included).toEqual(true);
3639
});
3740

3841
it('should add systemjs to the top of the files array', function(){
39-
expect(files[0].pattern).toEqual(basePath + '/custom_packages/system.src.js');
42+
expect(normalPath(files[0].pattern)).toEqual(normalPath(basePath + '/custom_packages/system.src.js'));
4043
expect(files[0].included).toEqual(true);
4144
});
4245

@@ -45,17 +48,24 @@ describe('jspm plugin init', function(){
4548
});
4649

4750
it('should add files from jspm.serveFiles to the end of the files array as served files', function(){
48-
expect(files[files.length - 1].pattern).toEqual(cwd + '/testfile.js');
51+
expect(normalPath(files[files.length - 1].pattern)).toEqual(normalPath(cwd + '/testfile.js'));
4952
expect(files[files.length - 1].included).toEqual(false);
5053
expect(files[files.length - 1].served).toEqual(true);
5154
expect(files[files.length - 1].watched).toEqual(true);
5255
});
5356

5457
it('should use the configured jspm_packages path and include it in the files array', function(){
55-
expect(files[4].pattern).toEqual(path.resolve(cwd, './custom_packages/**/*'));
58+
expect(normalPath(files[4].pattern)).toEqual(normalPath(path.resolve(cwd, './custom_packages/**/*')));
5659
expect(files[4].included).toEqual(false);
5760
expect(files[4].served).toEqual(true);
5861
expect(files[4].watched).toEqual(false);
5962
});
6063

64+
it('should assign true to nocache option to served files with nocache option in jspm.loadFiles', function(){
65+
expect(normalPath(files[files.length - 2].pattern)).toEqual(normalPath(cwd + '/not-cached.js'));
66+
expect(files[files.length - 2].included).toEqual(false);
67+
expect(files[files.length - 2].served).toEqual(true);
68+
expect(files[files.length - 2].watched).toEqual(true);
69+
expect(files[files.length - 2].nocache).toEqual(true);
70+
});
6171
});

0 commit comments

Comments
 (0)