Skip to content

Commit

Permalink
[amd] [tests] refs brython-dev#188 - Refactor intern config code acco…
Browse files Browse the repository at this point in the history
…rding to browser vs node.js
  • Loading branch information
olemis committed Feb 21, 2016
1 parent abbce96 commit 2c4a543
Showing 1 changed file with 40 additions and 27 deletions.
67 changes: 40 additions & 27 deletions www/tests/intern.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,47 @@ client.html e.g. http://localhost/intern/client.html?amdLoader=http://localhost/
*/

;(function() {
// See stackoverflow:2976651
var stk = new Error().stack.split('\n');
idx = 0;
for (var i in stk) {
if (!stk[i].match(/http[s]?:\/\//)) continue;
idx = Number(i) + 1;
break;

// FIXME : More reliable check for browser vs node.js
var is_browser = typeof window !== 'undefined';

function browser_params() {
// See stackoverflow:2976651
var stk = new Error().stack.split('\n');
idx = 0;
console.log(stk);
for (var i in stk) {
if (!stk[i].match(/http[s]?:\/\//)) continue;
idx = Number(i) + 1;
break;
}
var path_parts = stk[idx].match(/((http[s]?:\/\/.+\/)([^\/]+\.js)):/),
path_base = (path_parts? path_parts[2]: '') + '../',
path_requirejs_cdn = 'https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.22/require.min.js',
amd_loader_arg = location.search.match(/[?&]amdLoader=([^&]+)/),
cfg_loader = {'host-node' : 'requirejs',
'host-browser' : this['amd']? amd.loader_path :
(amd_loader_arg? amd_loader_arg[1] :
path_requirejs_cdn)};
cfg_loader_options = {baseUrl: 'src/amd',
paths: {'brython_tests' : '../../tests/amd/brython_tests'}}
return {basePath: path_base,
// Intern 2.0
useLoader: cfg_loader,
loader: cfg_loader_options,
// Intern 3.0
loaders: cfg_loader,
loaderOptions: cfg_loader_options}
}
var path_parts = stk[idx].match(/((http[s]?:\/\/.+\/)([^\/]+\.js)):/),
path_base = (path_parts? path_parts[2]: '') + '../',
path_requirejs_cdn = 'https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.22/require.min.js',
amd_loader_arg = location.search.match(/[?&]amdLoader=([^&]+)/),
cfg_loader = {'host-node' : 'requirejs',
'host-browser' : this['amd']? amd.loader_path :
(amd_loader_arg? amd_loader_arg[1] :
path_requirejs_cdn)};
cfg_loader_options = {baseUrl: 'src/amd',
paths: {'brython_tests' : '../../tests/amd/brython_tests'}}

define({
basePath: path_base,
suites: ['brython_tests/tkn'],
// Intern 2.0
useLoader: cfg_loader,
loader: cfg_loader_options,
// Intern 3.0
loaders: cfg_loader,
loaderOptions: cfg_loader_options

function node_params() {
return {};
}

define(function() {
var params = (is_browser? browser_params: node_params)();
params.suites = ['brython_tests/tkn'];
return params;
})
})()

0 comments on commit 2c4a543

Please sign in to comment.