Issue #533: Merge test suites. use delay as timeout

This commit is contained in:
juliandescottes 2016-09-01 00:47:33 +02:00
parent e9ef6eb5b3
commit 7bc5d20b2e
6 changed files with 35 additions and 59 deletions

View File

@ -9,8 +9,6 @@ module.exports = function(grunt) {
TEST : 9991 TEST : 9991
}; };
var DEV_MODE = '?debug';
// create a version based on the build timestamp // create a version based on the build timestamp
var dateFormat = require('dateformat'); var dateFormat = require('dateformat');
var version = '-' + dateFormat(new Date(), "yyyy-mm-dd-hh-MM"); var version = '-' + dateFormat(new Date(), "yyyy-mm-dd-hh-MM");
@ -34,25 +32,8 @@ module.exports = function(grunt) {
var stylePaths = require('./src/piskel-style-list.js').styles; var stylePaths = require('./src/piskel-style-list.js').styles;
var piskelStyles = prefixPaths(stylePaths, "src/"); var piskelStyles = prefixPaths(stylePaths, "src/");
var getCasperConfig = function (suiteName, delay, host) { var casperTestPaths = require('./test/casperjs/TestSuite.js').tests;
var testPaths = require('./test/casperjs/' + suiteName).tests; var casperTests = prefixPaths(casperTestPaths, "test/casperjs/");
var tests = prefixPaths(testPaths, "test/casperjs/");
return {
files : {src: tests},
options : {
casperjsOptions: [
'--baseUrl=http://' + host + ':' + PORT.TEST,
'--mode=' + DEV_MODE,
'--delay=' + delay,
'--verbose=false',
'--log-level=info',
'--print-command=false',
'--print-file-paths=true',
]
},
};
};
var getConnectConfig = function (base, port, host) { var getConnectConfig = function (base, port, host) {
if (typeof base === 'string') { if (typeof base === 'string') {
@ -134,7 +115,7 @@ module.exports = function(grunt) {
path : 'http://' + hostname + ':' + PORT.PROD + '/' path : 'http://' + hostname + ':' + PORT.PROD + '/'
}, },
dev : { dev : {
path : 'http://' + hostname + ':' + PORT.DEV + '/' + DEV_MODE path : 'http://' + hostname + ':' + PORT.DEV + '/?debug'
} }
}, },
@ -282,8 +263,19 @@ module.exports = function(grunt) {
}, },
casperjs : { casperjs : {
'travis' : getCasperConfig('TravisTestSuite.js', 10000, hostname), files : {
'local' : getCasperConfig('LocalTestSuite.js', 50, hostname) src: casperTests
},
options : {
casperjsOptions: [
'--baseUrl=http://' + hostname + ':' + PORT.TEST,
'--mode=?debug',
'--verbose=false',
'--log-level=info',
'--print-command=false',
'--print-file-paths=true',
]
},
}, },
/** /**
@ -312,38 +304,34 @@ module.exports = function(grunt) {
} }
}); });
// Validate // TEST TASKS
// Run linting
grunt.registerTask('lint', ['jscs:js', 'leadingIndent:css', 'jshint']); grunt.registerTask('lint', ['jscs:js', 'leadingIndent:css', 'jshint']);
// Run unit-tests
// karma/unit-tests task
grunt.registerTask('unit-test', ['karma']); grunt.registerTask('unit-test', ['karma']);
// Run linting, unit tests and drawing tests
grunt.registerTask('test', ['lint', 'unit-test', 'build-dev', 'connect:test', 'casperjs']);
// Run the tests, even if the linting fails
grunt.registerTask('test-nolint', ['unit-test', 'build-dev', 'connect:test', 'casperjs']);
// Used by optional precommit hook
grunt.registerTask('precommit', ['test']);
// Validate & Test // BUILD TASKS
grunt.registerTask('test-travis', ['lint', 'unit-test', 'build-dev', 'connect:test', 'casperjs:travis']);
// Validate & Test (faster version) will NOT work on travis !!
grunt.registerTask('test-local', ['lint', 'unit-test', 'build-dev', 'connect:test', 'casperjs:local']);
grunt.registerTask('test-local-nolint', ['unit-test', 'build-dev', 'connect:test', 'casperjs:local']);
grunt.registerTask('test', ['test-travis']);
grunt.registerTask('precommit', ['test-local']);
grunt.registerTask('build-index.html', ['includereplace']); grunt.registerTask('build-index.html', ['includereplace']);
grunt.registerTask('merge-statics', ['concat:js', 'concat:css', 'uglify']); grunt.registerTask('merge-statics', ['concat:js', 'concat:css', 'uglify']);
grunt.registerTask('build', ['clean:prod', 'sprite', 'merge-statics', 'build-index.html', 'replace:mainPartial', 'copy:prod']); grunt.registerTask('build', ['clean:prod', 'sprite', 'merge-statics', 'build-index.html', 'replace:mainPartial', 'copy:prod']);
grunt.registerTask('build-dev', ['clean:dev', 'sprite', 'build-index.html', 'copy:dev']); grunt.registerTask('build-dev', ['clean:dev', 'sprite', 'build-index.html', 'copy:dev']);
// Validate & Build
grunt.registerTask('default', ['lint', 'build']);
// Build stand alone app with nodewebkit
grunt.registerTask('desktop', ['clean:desktop', 'default', 'replace:desktop', 'nwjs:windows']); grunt.registerTask('desktop', ['clean:desktop', 'default', 'replace:desktop', 'nwjs:windows']);
grunt.registerTask('desktop-mac', ['clean:desktop', 'default', 'replace:desktop', 'nwjs:macos']); grunt.registerTask('desktop-mac', ['clean:desktop', 'default', 'replace:desktop', 'nwjs:macos']);
// SERVER TASKS
// Start webserver and watch for changes // Start webserver and watch for changes
grunt.registerTask('serve', ['build', 'connect:prod', 'open:prod', 'watch:prod']); grunt.registerTask('serve', ['build', 'connect:prod', 'open:prod', 'watch:prod']);
// Start webserver on src folder, in debug mode // Start webserver on src folder, in debug mode
grunt.registerTask('serve-dev', ['build-dev', 'connect:dev', 'open:dev', 'watch:dev']); grunt.registerTask('serve-dev', ['build-dev', 'connect:dev', 'open:dev', 'watch:dev']);
grunt.registerTask('serve-debug', ['serve-dev']); grunt.registerTask('serve-debug', ['serve-dev']);
grunt.registerTask('play', ['serve-dev']); grunt.registerTask('play', ['serve-dev']);
// Default task
grunt.registerTask('default', ['lint', 'build']);
}; };

View File

@ -23,7 +23,7 @@
"scripts": { "scripts": {
"test": "grunt test", "test": "grunt test",
"start": "nodewebkit", "start": "nodewebkit",
"preversion": "grunt test-local build", "preversion": "grunt test build",
"postversion": "git push && git push --tags && npm publish" "postversion": "git push && git push --tags && npm publish"
}, },
"devDependencies": { "devDependencies": {

View File

@ -18,10 +18,6 @@
casper.then(function () { casper.then(function () {
this.echo('Running test : ' + currentTest); this.echo('Running test : ' + currentTest);
this.wait(casper.cli.get('delay'));
});
casper.then(function () {
this.echo('... Waiting for test result : ' + resultSelector); this.echo('... Waiting for test result : ' + resultSelector);
this.waitForSelector(resultSelector, function () { this.waitForSelector(resultSelector, function () {
// then // then

View File

@ -1,17 +1,13 @@
casper.test.begin('Smoke Test', 2, function(test) { casper.test.begin('Smoke Test', 1, function(test) {
casper casper
.start(casper.cli.get('baseUrl')+"/?debug") .start(casper.cli.get('baseUrl')+"/?debug")
.then(function () {
this.wait(casper.cli.get('delay'));
})
.then(function () { .then(function () {
this.echo(casper.cli.get('baseUrl')+"/?debug"); this.echo(casper.cli.get('baseUrl')+"/?debug");
// If there was a JS error after the page load, casper won't perform asserts
test.assertExists('html', 'Casper JS cannot assert DOM elements. A JS error has probably occured.');
this.waitForSelector('#drawing-canvas-container canvas', function() { this.waitForSelector('#drawing-canvas-container canvas', function() {
test.assertExists('#drawing-canvas-container canvas', 'Check if drawing canvas element is created'); test.assertExists('#drawing-canvas-container canvas', 'Check if drawing canvas element is created');
}); }, function () {
test.fail('Test timed out');
}, 10000);
}) })
.run(function () { .run(function () {
test.done(); test.done();

View File

@ -1,4 +0,0 @@
(typeof exports != "undefined" ? exports : pskl_exports).tests = [
'SmokeTest.js',
'DrawingTest.js'
];