Skip to content

Commit

Permalink
add runner setup examples
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Mar 24, 2014
1 parent fcd534e commit 3da83cb
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 0 deletions.
13 changes: 13 additions & 0 deletions example/basis_setup/env.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>basis.js base environment</title>
</head>

<body>
<script src="../src/basis.js" data-basis-config=""></script>
</body>

</html>
45 changes: 45 additions & 0 deletions example/basis_setup/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>Test runner setup example (for basis.js-based apps)</title>
</head>

<body>
<script src="path/to/src/basis.js" basis-config></script>
<script>
if (this.top === this)
location.href = 'runner/reporter.html?page=../index.html'; // page parameter value should contain relative path
// from reporter.html to this page

(function(){
var originalJsWrapper = basis.resource.extensions['.js'];
basis.resource.extensions['.js'] = function(content, url){
var exports = originalJsWrapper(content, url);
if (exports)
exports.filename_ = url;
return exports;
};

// page reload on spec files update
// run in next tick, because at code run basisjs-tools file sync
// script is not loaded yet
basis.ready(function(){
if (typeof basisjsToolsFileSync != 'undefined')
basisjsToolsFileSync.notifications.attach(function(type, filename){
if (type == 'update' &&
basis.resource.exists(filename) &&
!/^\.\./.test(basis.path.relative(filename)))
location.reload();
});
});
})();

function loadTests(loadTestsToReporter){
loadTestsToReporter(basis.require('./index.js')); // path to test suite index file
}
</script>
</body>

</html>
8 changes: 8 additions & 0 deletions example/basis_setup/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// example test suite
module.exports = {
name: 'Example test suite',
html: __dirname + 'env.html', // base env
test: [
require('./spec/suite1.js')
]
};
17 changes: 17 additions & 0 deletions example/basis_setup/spec/suite1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
name: 'Test suite 1',
test: [
{
name: 'Test #1',
test: function(){
// test code
}
},
{
name: 'Test #2',
test: function(){
// test code
}
}
]
};
13 changes: 13 additions & 0 deletions example/non_basis_setup/env.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>basis.js base environment</title>
</head>

<body>
<script src="../src/basis.js" data-basis-config=""></script>
</body>

</html>
38 changes: 38 additions & 0 deletions example/non_basis_setup/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>Test runner setup example (for non-basis.js-based apps)</title>
</head>

<body>
<script src="path/to/src/basis.js" basis-config></script>
<script>
if (this.top === this)
location.href = 'runner/reporter.html?page=../index.html'; // page parameter value should contain relative path
// from reporter.html to this page

function loadTests(loadTestsToReporter){
loadTestsToReporter({
name: 'Test suite',
test: [
{
name: 'Test #1',
test: function(){
// test code
}
},
{
name: 'Test #2',
test: function(){
// test code
}
}
]
});
}
</script>
</body>

</html>

0 comments on commit 3da83cb

Please sign in to comment.