Skip to content

Commit

Permalink
Add test-suite using SlimerJS
Browse files Browse the repository at this point in the history
  • Loading branch information
tsauerwein committed Apr 4, 2015
1 parent 28a13e3 commit 8e0c21e
Show file tree
Hide file tree
Showing 13 changed files with 394 additions and 26 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
@@ -1,9 +1,13 @@
env:
- DISPLAY=:99.0

before_install:
- "sudo pip install -r requirements.txt"
- "npm install -g npm && npm install"

before_script:
- "rm src/ol/renderer/webgl/*shader.js"
- "sh -e /etc/init.d/xvfb start"

script: "./build.py ci"

Expand Down
57 changes: 42 additions & 15 deletions build.py
Expand Up @@ -145,6 +145,10 @@ def wait_completion(self):
for path in ifind('test/spec')
if path.endswith('.js')]

SPEC_RENDERING = [path
for path in ifind('test_rendering/spec')
if path.endswith('.js')]

TASKS = [path
for path in ifind('tasks')
if path.endswith('.js')]
Expand Down Expand Up @@ -172,7 +176,7 @@ def report_sizes(t):
virtual('default', 'build')


virtual('ci', 'lint', 'build', 'test',
virtual('ci', 'lint', 'build', 'test', 'test-rendering',
'build/examples/all.combined.js', 'check-examples', 'apidoc')


Expand Down Expand Up @@ -231,19 +235,28 @@ def shader_src(t):
shader_src_helper(glsl_src)


@target('build/test/requireall.js', SPEC)
def build_test_requireall_js(t):
def build_requires(task):
requires = set()
for dependency in t.dependencies:
for dependency in task.dependencies:
for line in open(dependency, 'rU'):
match = re.match(r'goog\.provide\(\'(.*)\'\);', line)
if match:
requires.add(match.group(1))
with open(t.name, 'wb') as f:
with open(task.name, 'wb') as f:
for require in sorted(requires):
f.write('goog.require(\'%s\');\n' % (require,))


@target('build/test_requires.js', SPEC)
def build_test_requires(t):
build_requires(t)


@target('build/test_rendering_requires.js', SPEC_RENDERING)
def build_test_rendering_requires(t):
build_requires(t)


virtual('build-examples', 'examples', 'build/examples/all.combined.js',
EXAMPLES_COMBINED)

Expand Down Expand Up @@ -389,7 +402,8 @@ def action(t):
return Target(name, action=action, dependencies=dependencies)


@target('serve', 'examples', NPM_INSTALL)
@target('serve', 'examples', 'build/test_requires.js', 'build/test_rendering_requires.js',
NPM_INSTALL)
def serve(t):
t.run('node', 'tasks/serve.js')

Expand All @@ -398,7 +412,8 @@ def serve(t):
'build/check-whitespace-timestamp', 'jshint')


@target('build/lint-timestamp', SRC, EXAMPLES_SRC, SPEC, precious=True)
@target('build/lint-timestamp', SRC, EXAMPLES_SRC, SPEC, SPEC_RENDERING,
precious=True)
def build_lint_src_timestamp(t):
t.run('%(GJSLINT)s',
'--jslint_error=all',
Expand All @@ -409,8 +424,8 @@ def build_lint_src_timestamp(t):

virtual('jshint', 'build/jshint-timestamp')

@target('build/jshint-timestamp', SRC, EXAMPLES_SRC, SPEC, TASKS,
NPM_INSTALL, precious=True)
@target('build/jshint-timestamp', SRC, EXAMPLES_SRC, SPEC, SPEC_RENDERING,
TASKS, NPM_INSTALL, precious=True)
def build_jshint_timestamp(t):
t.run(variables.JSHINT, '--verbose', t.newer(t.dependencies))
t.touch()
Expand Down Expand Up @@ -439,7 +454,8 @@ def _strip_comments(lines):
yield lineno, line


@target('build/check-requires-timestamp', SRC, EXAMPLES_SRC, SHADER_SRC, SPEC)
@target('build/check-requires-timestamp', SRC, EXAMPLES_SRC, SHADER_SRC,
SPEC, SPEC_RENDERING)
def build_check_requires_timestamp(t):
unused_count = 0
all_provides = set()
Expand Down Expand Up @@ -580,7 +596,7 @@ def build_re(self, key):


@target('build/check-whitespace-timestamp', SRC, EXAMPLES_SRC,
SPEC, JSDOC_SRC, precious=True)
SPEC, SPEC_RENDERING, JSDOC_SRC, precious=True)
def build_check_whitespace_timestamp(t):
CR_RE = re.compile(r'\r')
LEADING_WHITESPACE_RE = re.compile(r'\s+')
Expand Down Expand Up @@ -720,7 +736,7 @@ def check_examples(t):
sys.exit(1)


@target('test', NPM_INSTALL, phony=True)
@target('test', NPM_INSTALL, 'build/test_requires.js', phony=True)
def test(t):
t.run('node', 'tasks/test.js')

Expand All @@ -730,6 +746,16 @@ def test_coverage(t):
t.run('node', 'tasks/test-coverage.js')


@target('test-rendering', 'build/test_rendering_requires.js',
NPM_INSTALL, phony=True)
def test_rendering(t):
# create a temp. profile to run the tests with WebGL
tmp_profile_dir = 'build/slimerjs-profile'
t.rm_rf(tmp_profile_dir)
t.cp_r('test_rendering/slimerjs-profile', tmp_profile_dir)
t.run('node', 'tasks/test-rendering.js')


@target('fixme', phony=True)
def find_fixme(t):
regex = re.compile('FIXME|TODO')
Expand Down Expand Up @@ -794,6 +820,7 @@ def display_help(t):
CSS. This is also the default build target which runs when
no target is specified.
test - Runs the testsuite and displays the results.
test-rendering - Runs the rendering testsuite and displays the results.
check - Runs the lint-target, builds some OpenLayers files, and
then runs test. Many developers call this target often
while working on the code.
Expand All @@ -803,9 +830,9 @@ def display_help(t):
apidoc - Builds the API-Documentation using JSDoc3.
ci - Builds all examples in various modes and usually takes a
long time to finish. This target calls the following
targets: lint, build, build-all, test, build-examples,
check-examples and apidoc. This is the target run on
Travis CI.
targets: lint, build, build-all, test, test-rendering,
build-examples, check-examples and apidoc. This is the
target run on Travis CI.
test-coverage - Generates a test coverage report in the coverage folder.
reallyclean - Remove untracked files from the repository.
checkdeps - Checks whether all required development software is
Expand Down
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -53,7 +53,9 @@
"mocha-phantomjs": "3.5.1",
"phantomjs": "1.9.10",
"proj4": "2.3.3",
"sinon": "1.10.3"
"sinon": "1.10.3",
"slimerjs-edge": "0.10.0-pre-2",
"resemblejs": "1.2.0"
},
"ext": [
"rbush"
Expand Down
26 changes: 19 additions & 7 deletions tasks/serve.js
Expand Up @@ -23,7 +23,10 @@ var createServer = exports.createServer = function(callback) {
lib: [
'src/**/*.js',
'build/ol.ext/*.js',
'test/spec/**/*.test.js'
'test/spec/**/*.test.js',
'test_rendering/spec/**/*.test.js',
'build/test_requires.js',
'build/test_rendering_requires.js'
],
main: 'examples/*.js'
});
Expand All @@ -41,12 +44,21 @@ var createServer = exports.createServer = function(callback) {
getMain: function(req) {
var main;
var query = url.parse(req.url, true).query;
if (query.id) {
var referer = req.headers.referer;
if (referer) {
var from = path.join(process.cwd(),
path.dirname(url.parse(referer).pathname));
main = path.resolve(from, query.id + '.js');
var referer = req.headers.referer;
var pathName = url.parse(referer).pathname;
if (pathName.indexOf('/test/') === 0) {
main = path.resolve(
path.join(process.cwd(), 'build'), 'test_requires.js');
} else if (pathName.indexOf('/test_rendering/') === 0) {
main = path.resolve(
path.join(process.cwd(), 'build'), 'test_rendering_requires.js');
} else {
if (query.id) {
if (referer) {
var from = path.join(process.cwd(),
path.dirname(url.parse(referer).pathname));
main = path.resolve(from, query.id + '.js');
}
}
}
return main;
Expand Down
2 changes: 1 addition & 1 deletion tasks/test-coverage.js
Expand Up @@ -13,7 +13,7 @@ var wrench = require('wrench');
var path = require('path');
var glob = require('glob');

var runTestsuite = require('./test');
var runTestsuite = require('./test').runTests;

// setup some pathes
var dir = path.join(__dirname, '../src');
Expand Down
65 changes: 65 additions & 0 deletions tasks/test-rendering.js
@@ -0,0 +1,65 @@
/**
* This task starts a dev server that provides a script loader for OpenLayers
* and Closure Library and runs rendering tests in SlimerJS.
*/

var fs = require('fs');
var path = require('path');
var spawn = require('child_process').spawn;

var slimerjs = require('slimerjs-edge');

var serve = require('./serve');
var listen = require('./test').listen;


/**
* Create the debug server and run tests.
*/
serve.createServer(function(err, server) {
if (err) {
process.stderr.write(err.message + '\n');
process.exit(1);
}

listen(3001, 3005, server, function(err) {
if (err) {
process.stderr.write('Server failed to start: ' + err.message + '\n');
process.exit(1);
}

var address = server.address();
var url = 'http://' + address.address + ':' + address.port;
var profile = path.join(__dirname, '../build/slimerjs-profile');
var args = [
'-profile',
profile,
path.join(__dirname,
'../test_rendering/test.js'),
url + '/test_rendering/index.html'
];

var child = spawn(slimerjs.path, args, {stdio: 'inherit'});
child.on('exit', function(code) {
// FIXME SlimerJS has a problem with returning the correct return
// code when using a custom profile, see
// https://github.com/laurentj/slimerjs/issues/333
// as a work-around we are currently reading the return code from
// a file created in the profile directory.
// if this issue is fixed we should use the npm package 'slimerjs'
// instead of the nightly build 'slimerjs-edge'.
var exitstatus = path.join(profile, 'exitstatus');
fs.readFile(exitstatus, {encoding: 'utf-8'}, function(err, data) {
if (err) {
process.stderr.write(
'Error getting the exit status of SlimerJS' + '\n');
process.stderr.write(err);
process.exit(1);
} else {
process.exit(data);
}
});
});
});

});
5 changes: 4 additions & 1 deletion tasks/test.js
Expand Up @@ -81,6 +81,9 @@ if (require.main === module) {
});
}

module.exports = runTests;
module.exports = {
runTests: runTests,
listen: listen
};


0 comments on commit 8e0c21e

Please sign in to comment.