UNPKG

1.92 kBJavaScriptView Raw
1var cwd = process.cwd();
2var glob = require("glob");
3var path = require("path");
4
5
6function flatten(structure) {
7 return [].concat.apply([], structure);
8}
9
10function expandGlob(file) {
11 return glob.sync(file.pattern || file).map(function (filePath) {
12 return filePath.replace(/\//g, path.sep);
13 });
14};
15
16var createPattern = function(path) {
17 return {pattern: path, included: true, served: true, watched: false};
18};
19
20var createServedPattern = function(path){
21 return {pattern: path, included: false, served: true, watched: true};
22};
23
24var initJspm = function(files, basePath, jspm, client) {
25 // Allow Karma to serve all files within jspm_packages.
26 // This allows jspm/SystemJS to load them
27 files.unshift(createServedPattern(basePath + '/jspm_packages/**/*'));
28
29 // Add SystemJS loader and jspm config
30 files.unshift(createPattern(__dirname + '/src/adapter.js'));
31 files.unshift(createPattern(cwd + '/config.js'));
32 files.unshift(createPattern(cwd + '/jspm_packages/system@0.8.js'));
33 files.unshift(createPattern(cwd + '/jspm_packages/es6-module-loader@0.8.js'));
34 // files.unshift(createPattern(cwd + '/jspm_packages/traceur-runtime@0.0.56.js'));
35
36 // Initialize jspm config if it wasn't specified in karma.conf.js
37 if(!jspm)
38 jspm = {};
39 if(!jspm.files)
40 jspm.files = [];
41 if(!client.jspm)
42 client.jspm = {};
43
44 // Loop through all of jspm.files and do two things
45 // 1. Add all the files as "served" files to the files array
46 // 2. Expand out and globs to end up with actual files for jspm to load.
47 // Store that in client.jspm.expandedFiles
48 client.jspm.expandedFiles = flatten(jspm.files.map(function(file){
49 files.push(createServedPattern(cwd + "/" + (file.pattern || file)));
50 return expandGlob(file);
51 }));
52};
53
54initJspm.$inject = ['config.files', 'config.basePath', 'config.jspm', 'config.client'];
55
56module.exports = {
57 'framework:jspm': ['factory', initJspm]
58};