systemjs/test/test.html
2013-10-29 19:54:27 +02:00

316 lines
8.6 KiB
HTML

<!doctype html>
<html>
<script src="../../es6-module-loader/lib/es6-module-loader.js" type="text/javascript"></script>
<script src="../loader.js" type="text/javascript"></script>
<script>
jspm.config({
locations: {
plugin: '../../jspm-plugins'
}
});
jspm.import('./test-runner', function(runner) {
runner.execute([
{
name: 'Wrapper module support',
run: function(complete) {
jspm.import('./tests/wrapper', complete);
},
confirm: function(m) {
if (m != 'default1')
return 'Wrapper module not defined.';
}
},
{
name: 'Basic exporting & importing',
run: function(complete) {
var m1, m2, m3, err;
var checkComplete = function() {
if (m1 && m2 && m3 && err)
complete(m1, m2, m3);
}
jspm.import(['./tests/default1'], function(_m1) {
if (m1 === undefined)
m1 = null;
else
m1 = _m1;
checkComplete();
});
jspm.import(['./tests/default1'], function(_m1) {
if (m1 === undefined)
m1 = null;
else
m1 = _m1;
checkComplete();
});
jspm.import(['./tests/default2'], function(_m2) {
m2 = _m2;
checkComplete();
});
jspm.import(['./tests/asdf'], function() {
}, function(_err) {
err = _err;
checkComplete();
});
jspm.import('./tests/default3', function(_m3) {
m3 = _m3;
checkComplete();
});
},
confirm: function(m1, m2, m3) {
if (m1 != 'default1')
return 'Error defining default 1';
if (m2 != 'default2')
return 'Error defining default 2';
if (m3 != 'default3')
return 'Error defining default 3';
}
},
{
name: 'Global script loading',
run: function(complete) {
jspm.import(['./tests/global'], complete);
},
confirm: function(m) {
if (!m.jQuery || !m.another)
return 'Global objects not defined';
}
},
{
name: 'Global script with multiple objects the same',
run: function(complete) {
jspm.import(['./tests/global-multi'], complete);
},
confirm: function(m) {
if (m.jquery != 'here')
return 'Multi globals not detected';
}
},
{
name: 'Global script loading with depends',
run: function(complete) {
jspm.config({
depends: {
'./tests/global-with-dep': ['./global-dep']
}
});
jspm.import(['./tests/global-with-dep'], complete);
},
confirm: function(m) {
if (m != '1.8.3')
return 'Global dependency not defined';
}
},
{
name: 'Global script loading with inline depends',
run: function(complete) {
jspm.import('./tests/global-inline-dep', complete);
},
confirm: function(m) {
if (m != '1.8.3')
return 'Global dependency not defined';
}
},
{
name: 'Location configuration',
run: function(complete) {
jspm.config({
locations: {
'mypath': './tests'
}
});
jspm.import(['mypath:path'], complete);
},
confirm: function(m) {
console.log(m);
if (m != 'path')
return 'module not loaded';
}
},
{
name: 'Map configuration',
run: function(complete) {
jspm.config({
map: {
'maptest': './tests/map-test'
}
});
jspm.import(['maptest'], complete)
},
confirm: function(m) {
if (m.maptest != 'maptest')
return 'Mapped module not loaded';
}
},
{
name: 'Map main configuration',
run: function(complete) {
jspm.config({
map: {
mapmain: './tests/my-app#main'
}
});
jspm.import(['mapmain', 'mapmain/submodule'], complete)
},
confirm: function(m1, m2) {
if (!m1.isMain)
return 'Main module not loaded';
if (!m2.isSubmodule)
return 'Submodule not loaded';
}
},
{
name: 'Package map configuration',
run: function(complete) {
jspm.config({
map: {
'./tests/my-app': {
'jquery': './tests/my-app/jquery-mapped'
}
}
});
jspm.import(['./tests/my-app/map-test'], complete);
},
confirm: function(m) {
if (!m.mapDep)
return 'Mapped package dependency not loaded';
}
},
{
name: 'Loading an AMD module',
run: function(complete) {
jspm.import(['./tests/amd-module'], complete);
},
confirm: function(m) {
if (m.amd != true)
return 'Incorrect module';
if (m.dep.amd != 'dep')
return 'Dependency not defined';
}
},
{
name: 'Loading AMD CommonJS form',
run: function(complete) {
jspm.import(['./tests/amd-cjs-module'], complete);
},
confirm: function(m) {
if (m.test != 'hi')
return 'Not defined';
}
},
{
name: 'Loading a CommonJS module',
run: function(complete) {
jspm.import(['./tests/common-js-module'], complete);
},
confirm: function(m) {
if (m.hello != 'world')
return 'module value not defined';
if (m.first != 'this is a dep')
return 'dep value not defined';
}
},
{
name: 'Loading a UMD module',
run: function(complete) {
jspm.import(['./tests/umd'], complete);
},
confirm: function(m) {
if (m.d != 'hi')
return 'module value not defined';
}
},
{
name: 'Simple compiler Plugin',
run: function(complete) {
jspm.config({
map: {
'plugin:coffee': './tests/compiler-plugin'
}
});
jspm.import(['./tests/compiler-test.coffee!'], complete);
},
confirm: function(m) {
if (m.output != 'plugin output')
return 'Plugin not working.';
if (m.extra != 'yay!')
return 'Compiler not working.';
}
},
{
name: 'Handlebars plugin',
run: function(complete) {
jspm.import('./tests/hbs.hbs!', complete);
},
confirm: function(m) {
if (m({ title: 'hello' }) != '<h1>hello</h1>\n')
return 'Handlebars template not compiled';
}
},
{
name: 'Text plugin',
run: function(complete) {
jspm.import('./tests/some-text.txt!text', complete);
},
confirm: function(m) {
if (m != 'this is some text\n')
return 'Text not defined.';
}
},
{
name: 'JSON plugin',
run: function(complete) {
jspm.import('./tests/some-json.json!', complete);
},
confirm: function(m) {
if (m.some != 'json')
return 'JSON not defined.';
}
},
{
name: 'Image plugin',
run: function(complete) {
jspm.import('http://jspm.io/icons.png!image', complete);
},
confirm: function(m) {
}
},
{
name: 'CSS plugin',
run: function(complete) {
jspm.import('./tests/css.css!', complete);
},
confirm: function(m) {
}
},
{
name: 'Font plugin',
run: function(complete) {
jspm.import('#google Port Lligat Slab !font', complete);
},
confirm: function(m) {
}
},
{
name: 'onLoad hook',
run: function(complete) {
jspm.config({
onLoad: complete
});
jspm.import(['./tests/normalize-hook-test']);
},
confirm: function(name, source, options) {
jspm.config({
onLoad: null
});
if (name != './tests/normalize-hook-test')
return 'normalize hook has incorrect name';
if (source != '"hello world";')
return 'invalid source';
}
}
]);
});
</script>