Skip to content
Extraits de code Groupes Projets
Valider cf4584b1 rédigé par diosmosis's avatar diosmosis
Parcourir les fichiers

Allow screenshot tests to specify their own fixture and update UI submodule.

parent d0752182
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Subproject commit f71df528c74f1e917d151f08773c437c7e2b966f Subproject commit 44c5397a565b8a413122ab1625ad8df7d8af497f
...@@ -30,11 +30,9 @@ then ...@@ -30,11 +30,9 @@ then
if [ -n "$PLUGIN_NAME" ] if [ -n "$PLUGIN_NAME" ]
then then
fixture=${FIXTURE_NAME:-OmniFixture} phantomjs ../lib/screenshot-testing/run-tests.js --use-github-expected --persist-fixture-data $PLUGIN_NAME
phantomjs ../lib/screenshot-testing/run-tests.js --use-github-expected --fixture=$fixture $PLUGIN_NAME
else else
phantomjs ../lib/screenshot-testing/run-tests.js --store-in-ui-tests-repo --use-github-expected phantomjs ../lib/screenshot-testing/run-tests.js --store-in-ui-tests-repo --persist-fixture-data --use-github-expected
fi fi
else else
if [ -n "$PLUGIN_NAME" ] if [ -n "$PLUGIN_NAME" ]
......
...@@ -100,6 +100,22 @@ Application.prototype.loadTestModules = function () { ...@@ -100,6 +100,22 @@ Application.prototype.loadTestModules = function () {
return options.tests.indexOf(suite.title) != -1; return options.tests.indexOf(suite.title) != -1;
}); });
} }
// configure suites (auto-add fixture setup/teardown)
mocha.suite.suites.forEach(function (suite) {
var fixture = suite.fixture || 'UITestFixture';
suite.beforeAll(function (done) {
testEnvironment.setupFixture(fixture, done);
});
// move to before other hooks
suite._beforeAll.unshift(suite._beforeAll.pop());
suite.afterAll(function (done) {
testEnvironment.teardownFixture(fixture, done);
});
});
}; };
Application.prototype.runTests = function () { Application.prototype.runTests = function () {
...@@ -126,42 +142,7 @@ Application.prototype.runTests = function () { ...@@ -126,42 +142,7 @@ Application.prototype.runTests = function () {
} }
}); });
this.setupDatabase(); this.doRunTests();
};
Application.prototype.setupDatabase = function () {
console.log("Setting up database...");
var self = this,
setupFile = path.join("./support", "setupDatabase.php"),
processArgs = [setupFile, "--server=" + JSON.stringify(config.phpServer)];
if (options['persist-fixture-data']) {
processArgs.push('--persist-fixture-data');
}
if (options['drop']) {
processArgs.push('--drop');
}
var child = require('child_process').spawn(config.php, processArgs);
child.stdout.on("data", function (data) {
fs.write("/dev/stdout", data, "w");
});
child.stderr.on("data", function (data) {
fs.write("/dev/stderr", data, "w");
});
child.on("exit", function (code) {
if (code) {
console.log("\nERROR: Failed to setup database!");
phantom.exit(-1);
} else {
self.doRunTests();
}
});
}; };
Application.prototype.doRunTests = function () { Application.prototype.doRunTests = function () {
...@@ -186,42 +167,12 @@ Application.prototype.doRunTests = function () { ...@@ -186,42 +167,12 @@ Application.prototype.doRunTests = function () {
// build diffviewer // build diffviewer
self.diffViewerGenerator.checkImageMagickCompare(function () { self.diffViewerGenerator.checkImageMagickCompare(function () {
self.diffViewerGenerator.generate(function () { self.diffViewerGenerator.generate(function () {
if (options['persist-fixture-data']) { self.finish();
self.finish();
} else {
// teardown database
self.tearDownDatabase();
}
}); });
}); });
}); });
}; };
Application.prototype.tearDownDatabase = function () {
console.log("Tearing down database...");
var self = this,
teardownFile = path.join("./support", "teardownDatabase.php"),
child = require('child_process').spawn(config.php, [teardownFile, "--server=" + JSON.stringify(config.phpServer)]);
child.stdout.on("data", function (data) {
fs.write("/dev/stdout", data, "w");
});
child.stderr.on("data", function (data) {
fs.write("/dev/stderr", data, "w");
});
child.on("exit", function (code) {
if (code) {
console.log("\nERROR: Failed to teardown database!");
phantom.exit(-2);
} else {
self.finish();
}
});
};
Application.prototype.finish = function () { Application.prototype.finish = function () {
phantom.exit(this.runner.failures); phantom.exit(this.runner.failures);
}; };
......
...@@ -6,18 +6,25 @@ ...@@ -6,18 +6,25 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/ */
$fixtureClass = "UITestFixture";
foreach ($argv as $arg) { foreach ($argv as $arg) {
if (strpos($arg, "--server=") === 0) { if (strpos($arg, "--server=") === 0) {
$serverStr = substr($arg, strlen("--server=")); $serverStr = substr($arg, strlen("--server="));
$_SERVER = json_decode($serverStr, true); $_SERVER = json_decode($serverStr, true);
} else if (strpos($arg, "--fixture=") === 0) {
$fixtureClass = substr($arg, strlen("--fixture="));
} }
} }
require_once "PHPUnit/Autoload.php"; require_once "PHPUnit/Autoload.php";
require_once dirname(__FILE__) . "/../../../PHPUnit/bootstrap.php"; require_once dirname(__FILE__) . "/../../../PHPUnit/bootstrap.php";
$fixture = new \Piwik\Tests\Fixtures\UITestFixture(); if (!class_exists($fixtureClass)) {
$fixtureClass = "Piwik\\Tests\\Fixtures\\$fixtureClass";
}
$fixture = new $fixtureClass();
if (in_array("--persist-fixture-data", $argv)) { if (in_array("--persist-fixture-data", $argv)) {
$fixture->persistFixtureData = true; $fixture->persistFixtureData = true;
} }
......
...@@ -6,18 +6,25 @@ ...@@ -6,18 +6,25 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/ */
$fixtureClass = "UITestFixture";
foreach ($argv as $arg) { foreach ($argv as $arg) {
if (strpos($arg, "--server=") === 0) { if (strpos($arg, "--server=") === 0) {
$serverStr = substr($arg, strlen("--server=")); $serverStr = substr($arg, strlen("--server="));
$_SERVER = json_decode($serverStr, true); $_SERVER = json_decode($serverStr, true);
} else if (strpos($arg, "--fixture=") === 0) {
$fixtureClass = substr($arg, strlen("--fixture="));
} }
} }
require_once "PHPUnit/Autoload.php"; require_once "PHPUnit/Autoload.php";
require_once dirname(__FILE__) . "/../../../PHPUnit/bootstrap.php"; require_once dirname(__FILE__) . "/../../../PHPUnit/bootstrap.php";
$fixture = new \Piwik\Tests\Fixtures\UITestFixture(); if (!class_exists($fixtureClass)) {
$fixtureClass = "Piwik\\Tests\\Fixtures\\$fixtureClass";
}
$fixture = new $fixtureClass();
$fixture->dropDatabaseInSetUp = false; $fixture->dropDatabaseInSetUp = false;
$fixture->printToScreen = true; $fixture->printToScreen = true;
$fixture->performSetUp("", $environmentOnly = true); $fixture->performSetUp("", $environmentOnly = true);
......
...@@ -82,4 +82,75 @@ TestingEnvironment.prototype._call = function (params, done) { ...@@ -82,4 +82,75 @@ TestingEnvironment.prototype._call = function (params, done) {
}); });
}; };
TestingEnvironment.prototype.setupFixture = function (fixtureClass, done) {
this.backup = JSON.stringify(this);
console.log(" Setting up fixture " + fixtureClass + "...");
var setupFile = path.join("./support", "setupDatabase.php"),
processArgs = [setupFile, "--server=" + JSON.stringify(config.phpServer), "--fixture=" + fixtureClass];
if (options['persist-fixture-data']) {
processArgs.push('--persist-fixture-data');
}
if (options['drop']) {
processArgs.push('--drop');
}
var child = require('child_process').spawn(config.php, processArgs);
child.stdout.on("data", function (data) {
fs.write("/dev/stdout", data, "w");
});
child.stderr.on("data", function (data) {
fs.write("/dev/stderr", data, "w");
});
child.on("exit", function (code) {
if (code) {
done(new Error("Failed to setup fixture " + fixtureClass + " (error code = " + code + ")"));
} else {
done();
}
});
};
TestingEnvironment.prototype.teardownFixture = function (fixtureClass, done) {
if (options['persist-fixture-data']) {
done();
return;
}
console.log(" Tearing down fixture " + fixtureClass + "...");
var teardownFile = path.join("./support", "teardownDatabase.php"),
child = require('child_process').spawn(
config.php, [teardownFile, "--server=" + JSON.stringify(config.phpServer), "--fixture=" + fixtureClass]);
child.stdout.on("data", function (data) {
fs.write("/dev/stdout", data, "w");
});
child.stderr.on("data", function (data) {
fs.write("/dev/stderr", data, "w");
});
var self = this;
child.on("exit", function (code) {
for (var key in self.backup) {
self[key] = self.backup[key];
}
self.backup = {};
if (code) {
done(new Error("Failed to teardown fixture " + fixtureClass + " (error code = " + code + ")"));
} else {
done();
}
});
};
exports.TestingEnvironment = new TestingEnvironment(); exports.TestingEnvironment = new TestingEnvironment();
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter