Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for working with systemjs 0.17+ without getting 404s #67

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,18 @@
* limitations under the License.
*/

(function(karma, System) {
System.config({ baseURL: 'base' });
function configureSystem(config) {
var baseURLPattern = /(["']baseURL["']:.*["'])(.*)(["'])/;

// Fix baseURL path, by injecting base instead of the current value from config.js
var jspmConfig = config.replace(baseURLPattern, '$1base$3');

// Evel the config
eval(jspmConfig);
}

(function(karma, System) {
configureSystem(karma.config.jspm.config);

// Prevent immediately starting tests.
window.__karma__.loaded = function() {
Expand Down
13 changes: 11 additions & 2 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = function(files, basePath, jspm, client) {

// Pass on useBundles option to client
client.jspm.useBundles = jspm.useBundles;

var packagesPath = path.normalize(basePath + '/' + jspm.packages + '/');
var configPath = path.normalize(basePath + '/' + jspm.config);

Expand All @@ -93,7 +93,7 @@ module.exports = function(files, basePath, jspm, client) {
return packagesPath + fileName + '.js';
}
}
files.unshift(createPattern(configPath));

files.unshift(createPattern(__dirname + '/adapter.js'));
files.unshift(createPattern(getLoaderPath('system-polyfills.src')));
files.unshift(createPattern(getLoaderPath('system.src')));
Expand All @@ -107,6 +107,15 @@ module.exports = function(files, basePath, jspm, client) {
return expandGlob(file, basePath);
}));

// Inject the jspm config for later evaluation
if (fs.existsSync(configPath)) {
client.jspm.config = fs.readFileSync(configPath).toString();
} else {
client.jspm.config = {
baseURL: 'base'
};
}

// Add served files to files array
jspm.serveFiles.map(function(file){
files.push(createServedPattern(basePath + "/" + (file.pattern || file)));
Expand Down
13 changes: 6 additions & 7 deletions test/testInit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ describe('jspm plugin init', function(){
initJspm(files, basePath, jspm, client);
});

it('should add config.js to the top of the files array', function(){
expect(files[3].pattern).toEqual(basePath + '/custom_config.js');
expect(files[3].included).toEqual(true);
it('should add inject the config for later evaluation', function(){
expect(client.jspm.config).not.toBe(false);
});

it('should add adapter.js to the top of the files array', function(){
Expand Down Expand Up @@ -52,10 +51,10 @@ describe('jspm plugin init', function(){
});

it('should use the configured jspm_packages path and include it in the files array', function(){
expect(files[4].pattern).toEqual(path.resolve(cwd, './custom_packages/**/*'));
expect(files[4].included).toEqual(false);
expect(files[4].served).toEqual(true);
expect(files[4].watched).toEqual(true);
expect(files[3].pattern).toEqual(path.resolve(cwd, './custom_packages/**/*'));
expect(files[3].included).toEqual(false);
expect(files[3].served).toEqual(true);
expect(files[3].watched).toEqual(true);
});

});