Skip to content

Commit 3da83cb

Browse files
committed
add runner setup examples
1 parent fcd534e commit 3da83cb

File tree

6 files changed

+134
-0
lines changed

6 files changed

+134
-0
lines changed

example/basis_setup/env.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<title>basis.js base environment</title>
7+
</head>
8+
9+
<body>
10+
<script src="../src/basis.js" data-basis-config=""></script>
11+
</body>
12+
13+
</html>

example/basis_setup/index.html

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!doctype html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<title>Test runner setup example (for basis.js-based apps)</title>
7+
</head>
8+
9+
<body>
10+
<script src="path/to/src/basis.js" basis-config></script>
11+
<script>
12+
if (this.top === this)
13+
location.href = 'runner/reporter.html?page=../index.html'; // page parameter value should contain relative path
14+
// from reporter.html to this page
15+
16+
(function(){
17+
var originalJsWrapper = basis.resource.extensions['.js'];
18+
basis.resource.extensions['.js'] = function(content, url){
19+
var exports = originalJsWrapper(content, url);
20+
if (exports)
21+
exports.filename_ = url;
22+
return exports;
23+
};
24+
25+
// page reload on spec files update
26+
// run in next tick, because at code run basisjs-tools file sync
27+
// script is not loaded yet
28+
basis.ready(function(){
29+
if (typeof basisjsToolsFileSync != 'undefined')
30+
basisjsToolsFileSync.notifications.attach(function(type, filename){
31+
if (type == 'update' &&
32+
basis.resource.exists(filename) &&
33+
!/^\.\./.test(basis.path.relative(filename)))
34+
location.reload();
35+
});
36+
});
37+
})();
38+
39+
function loadTests(loadTestsToReporter){
40+
loadTestsToReporter(basis.require('./index.js')); // path to test suite index file
41+
}
42+
</script>
43+
</body>
44+
45+
</html>

example/basis_setup/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// example test suite
2+
module.exports = {
3+
name: 'Example test suite',
4+
html: __dirname + 'env.html', // base env
5+
test: [
6+
require('./spec/suite1.js')
7+
]
8+
};

example/basis_setup/spec/suite1.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
name: 'Test suite 1',
3+
test: [
4+
{
5+
name: 'Test #1',
6+
test: function(){
7+
// test code
8+
}
9+
},
10+
{
11+
name: 'Test #2',
12+
test: function(){
13+
// test code
14+
}
15+
}
16+
]
17+
};

example/non_basis_setup/env.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<title>basis.js base environment</title>
7+
</head>
8+
9+
<body>
10+
<script src="../src/basis.js" data-basis-config=""></script>
11+
</body>
12+
13+
</html>

example/non_basis_setup/index.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!doctype html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<title>Test runner setup example (for non-basis.js-based apps)</title>
7+
</head>
8+
9+
<body>
10+
<script src="path/to/src/basis.js" basis-config></script>
11+
<script>
12+
if (this.top === this)
13+
location.href = 'runner/reporter.html?page=../index.html'; // page parameter value should contain relative path
14+
// from reporter.html to this page
15+
16+
function loadTests(loadTestsToReporter){
17+
loadTestsToReporter({
18+
name: 'Test suite',
19+
test: [
20+
{
21+
name: 'Test #1',
22+
test: function(){
23+
// test code
24+
}
25+
},
26+
{
27+
name: 'Test #2',
28+
test: function(){
29+
// test code
30+
}
31+
}
32+
]
33+
});
34+
}
35+
</script>
36+
</body>
37+
38+
</html>

0 commit comments

Comments
 (0)