Skip to content

Commit

Permalink
feat(adapter.requirejs): normalize paths before appending timestamp
Browse files Browse the repository at this point in the history
Because paths like /base/a/../some.js do not match entries in __testacular__.files, so let's normalize these paths first.
  • Loading branch information
vojtajina committed Feb 10, 2013
1 parent 8b4fd64 commit 94889e7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
24 changes: 23 additions & 1 deletion adapter/require.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,30 @@
// to take advantage of testacular's heavy caching
// it would work even without this hack, but with reloading all the files all the time

var load_original = window.requirejs.load;
var normalizePath = function(path) {
var normalized = [];
var parts = path.split('/');

for (var i = 0; i < parts.length; i++) {
if (parts[i] === '.') {
continue;
}

if (parts[i] === '..' && normalized.length && normalized[normalized.length - 1] !== '..') {
normalized.pop();
continue;
}

normalized.push(parts[i]);
}

return normalized.join('/');
};

var load_original = requirejs.load;
requirejs.load = function (context, moduleName, url) {
url = normalizePath(url);

if (__testacular__.files.hasOwnProperty(url)) {
url = url + '?' + __testacular__.files[url];
} else {
Expand Down
14 changes: 14 additions & 0 deletions test/client/require.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
describe('adapter requirejs', function() {

describe('normalizePath', function() {

it('should normalize . and .. in the path', function() {
expect(normalizePath('/base/a/../b/./../x.js')).toBe('/base/x.js');
});


it('should preserve .. in the beginning of the path', function() {
expect(normalizePath('../../a/file.js')).toBe('../../a/file.js');
});
});
});
1 change: 0 additions & 1 deletion test/client/testacular.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ files = [

// list of files to exclude
exclude = [
'adapter/require.src.js'
];

// use dots reporter, as travis terminal does not support escaping sequences
Expand Down

0 comments on commit 94889e7

Please sign in to comment.