systemjs/test/test.html

385 lines
10 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({
urlArgs: '?test'
});
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, m4, err;
var checkComplete = function() {
if (m1 && m2 && m3 && m4 && err)
complete(m1, m2, m3, m4);
}
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();
});
jspm.import('~/tests/module', function(_m4) {
m4 = _m4;
checkComplete();
});
},
confirm: function(m1, m2, m3, m4) {
if (m1 != 'default1')
return 'Error defining default 1';
if (m2 != 'default2')
return 'Error defining default 2';
if (m3 != 'default3')
return 'Error defining default 3';
if (m4.test != 'default3')
return 'Error defining module';
}
},
{
name: 'Error handling',
run: function(complete) {
jspm.import('~/tests/error', complete);
},
confirm: function() {
return;
}
},
{
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: 'Shim with imports',
run: function(complete) {
jspm.config({
packages: {
'~': {
shim: {
'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 shim',
run: function(complete) {
jspm.import('~/tests/global-inline-dep', complete);
},
confirm: function(m) {
if (m != '1.8.3')
return 'Global dependency not defined';
}
},
{
name: 'Wildcard shim with export specified',
run: function(complete) {
jspm.config({
packages: {
'~': {
shim: {
'tests/global-with-*': {
exports: 'window.q.r'
}
}
}
}
});
jspm.import(['~/tests/global-with-export'], complete);
},
confirm: function(m) {
if (m != 'r')
return 'Exports value not correct'
}
},
{
name: 'Global script with inline exports',
run: function(complete) {
jspm.import('~/tests/global-inline-export', complete);
},
confirm: function(m) {
if (m != 'r')
return 'Inline export not applied'
}
},
{
name: 'Endpoint configuration',
run: function(complete) {
jspm.config({
endpoints: {
'mypath': {
location: './tests',
depth: 1,
main: 'deep',
format: 'cjs'
}
}
});
jspm.import(['mypath:path', 'mypath:deep'], complete);
},
confirm: function(m) {
if (m != 'path')
return 'module not loaded';
}
},
{
name: 'Map configuration',
run: function(complete) {
jspm.config({
map: {
'maptest': '~/tests/map-test'
}
});
jspm.import(['maptest', 'maptest/sub'], complete)
},
confirm: function(m1, m2) {
if (m1.maptest != 'maptest')
return 'Mapped module not loaded';
if (m2.maptest != 'maptestsub')
return 'Mapped folder not loaded';
}
},
{
name: 'Wildcard Map Configuration',
run: function(complete) {
jspm.config({
map: {
'wild/card.*.*': '~/tests/wildcard-test/*',
'wild/card.second.*': '~/tests/wildcard-test/2'
}
});
jspm.import(['wild/card.first.here', 'wild/card.second.here', 'wild/card.second.here/sub'], complete);
},
confirm: function(m1, m2, m3) {
if (!m1 || !m2 || !m3)
return 'Failed';
}
},
{
name: 'Package Configuration',
run: function(complete) {
jspm.config({
packages: {
'~/tests/mypackage': {
main: 'index',
format: 'global',
map: {
'bar': './lib/bar'
},
shim: {
'src/*': ['bar']
}
}
}
});
jspm.import(['~/tests/mypackage', '~/tests/mypackage/src/foo'], complete);
},
confirm: function(m1, m2) {
if (m1 != 'bar')
return 'Mapped package dependency not loaded';
if (m2 != 'foo')
return 'Sub 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 an AMD named define',
run: function(complete) {
jspm.import(['github:coreyti/showdown@0.3.1/src/showdown'], complete);
},
confirm: function(m) {
if (!m.converter)
return 'Showdown not loaded!';
}
},
{
name: 'Loading AMD CommonJS form',
run: function(complete) {
jspm.config({
packages: {
'~/tests/amd-cjs-module': {
shim: 'amd'
}
}
});
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: {
'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://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>