systemjs/test/test.html
2013-08-19 10:34:49 +02:00

257 lines
7.0 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.import('test-runner', function(runner) {
runner.execute([
{
name: 'Basic exporting & importing',
run: function(complete) {
jspm.import(['tests/default1', 'tests/default2', 'tests/default3'], complete)
},
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';
if (window.jQuery || window.another)
return 'Global object has leaked';
}
},
{
name: 'Global script loading with shim',
run: function(complete) {
jspm.config({
shim: {
'tests/global-with-dep': ['tests/global-dep']
}
});
jspm.import(['tests/global-with-dep'], complete);
},
confirm: function(m) {
if (m.jQueryVersion != '1.8.3')
return 'Global dependency not defined';
}
},
{
name: 'Inline shim configuration',
run: function(complete) {
jspm.import('tests/inline-shim | tests/inline-shim-dep', complete);
},
confirm: function(m) {
if (m.dep != 'dep')
return 'Inline shim dependency not defined';
}
},
{
name: 'Location configuration',
run: function(complete) {
jspm.config({
locations: {
'mypath': 'tests'
}
});
jspm.import(['mypath:path'], complete);
},
confirm: function(m) {
if (m.p != 'path')
return 'module not loaded';
}
},
{
name: 'Location relative resolution',
run: function(complete) {
jspm.config({
locations: {
'mylocation': 'tests/location'
}
});
jspm.import(['mylocation:main'], complete)
},
confirm: function(m) {
if (m.p != 'yay')
return 'relative location 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: 'Package shorthand',
run: function(complete) {
jspm.config({
map: {
'myapp': 'tests/my-app'
}
});
jspm.import(['myapp/', 'myapp/sub'], complete)
},
confirm: function(m1, m2) {
if (!m1.package)
return 'Package not loaded';
if (!m2.package)
return 'Package subpath not loaded';
}
},
{
name: 'Package map configuration',
run: function(complete) {
jspm.config({
map: {
'tests/my-app': {
'jquery': 'tests/my-app/jquery-mapped'
}
}
});
jspm.import(['myapp/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: '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://octodex.github.com/images/codercat.jpg!image', complete);
},
confirm: function(m) {
}
},
{
name: 'CSS plugin',
run: function(complete) {
jspm.import('tests/css.css!', 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>