From 2c9b91d8b4b05e346c7914dea9c2580f0130afe2 Mon Sep 17 00:00:00 2001 From: diosmosis <benakamoorthi@fastmail.fm> Date: Thu, 13 Mar 2014 00:35:16 +0000 Subject: [PATCH] Fixing bugs in screenshot testing lib. --- tests/PHPUnit/UI | 2 +- tests/lib/screenshot-testing/support/app.js | 5 ---- .../support/test-environment.js | 25 +++++++++++-------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/PHPUnit/UI b/tests/PHPUnit/UI index a58fcba24e..e9593ef8b7 160000 --- a/tests/PHPUnit/UI +++ b/tests/PHPUnit/UI @@ -1 +1 @@ -Subproject commit a58fcba24ef69c6a5c48bcfcb2fd5afd2c7d3c78 +Subproject commit e9593ef8b7bb9c91a86b31fb2a08f917837fe57d diff --git a/tests/lib/screenshot-testing/support/app.js b/tests/lib/screenshot-testing/support/app.js index 8a67e68ed6..2f234a7bbf 100644 --- a/tests/lib/screenshot-testing/support/app.js +++ b/tests/lib/screenshot-testing/support/app.js @@ -115,11 +115,6 @@ Application.prototype.loadTestModules = function () { suite._beforeAll.unshift(suite._beforeAll.pop()); suite.afterAll(function (done) { - if (!fixture) { - done(); - return; - } - testEnvironment.teardownFixture(fixture, done); }); }); diff --git a/tests/lib/screenshot-testing/support/test-environment.js b/tests/lib/screenshot-testing/support/test-environment.js index ff98cf9d6e..4fa6aa4105 100644 --- a/tests/lib/screenshot-testing/support/test-environment.js +++ b/tests/lib/screenshot-testing/support/test-environment.js @@ -15,6 +15,10 @@ var TestingEnvironment = function () { }; TestingEnvironment.prototype.reload = function () { + for (var key in this) { + delete this[key]; + } + if (fs.exists(testingEnvironmentOverridePath)) { var data = JSON.parse(fs.read(testingEnvironmentOverridePath)); for (var key in data) { @@ -29,8 +33,6 @@ TestingEnvironment.prototype.save = function () { copy[key] = this[key]; } - delete copy.backup; - fs.write(testingEnvironmentOverridePath, JSON.stringify(copy)); }; @@ -90,8 +92,6 @@ 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"), @@ -125,7 +125,11 @@ TestingEnvironment.prototype.setupFixture = function (fixtureClass, done) { }; TestingEnvironment.prototype.teardownFixture = function (fixtureClass, done) { - if (options['persist-fixture-data']) { + if (options['persist-fixture-data'] + || !fixtureClass + ) { + this.deleteAndSave(); + done(); return; } @@ -146,11 +150,7 @@ TestingEnvironment.prototype.teardownFixture = function (fixtureClass, done) { var self = this; child.on("exit", function (code) { - for (var key in self.backup) { - self[key] = self.backup[key]; - } - - self.backup = {}; + self.deleteAndSave(); if (code) { done(new Error("Failed to teardown fixture " + fixtureClass + " (error code = " + code + ")")); @@ -160,4 +160,9 @@ TestingEnvironment.prototype.teardownFixture = function (fixtureClass, done) { }); }; +TestingEnvironment.prototype.deleteAndSave = function () { + fs.write(testingEnvironmentOverridePath, "{}"); + this.reload(); +}; + exports.TestingEnvironment = new TestingEnvironment(); \ No newline at end of file -- GitLab