mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-10 22:36:01 +00:00
Automatically handle deleting test Realms
No longer leave this up to the test. All testing passes through the runTest() function, so we use that spot to delete the Realms. It also now deletes them beforehand too since a crash in a previous run could leave a Realm in place.
This commit is contained in:
parent
58bff5f939
commit
48394d9c19
@ -1,36 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2016 Realm Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
'use strict';
|
||||
|
||||
var Realm = require('realm');
|
||||
|
||||
var prototype = exports.prototype = {};
|
||||
|
||||
exports.extend = function(object) {
|
||||
object.__proto__ = prototype;
|
||||
return object;
|
||||
};
|
||||
|
||||
Object.defineProperties(prototype, {
|
||||
afterEach: {
|
||||
value: function() {
|
||||
Realm.clearTestState();
|
||||
}
|
||||
}
|
||||
});
|
@ -19,11 +19,10 @@
|
||||
'use strict';
|
||||
|
||||
var Realm = require('realm');
|
||||
var BaseTest = require('./base-test');
|
||||
var TestCase = require('./asserts');
|
||||
var Schemas = require('./schemas');
|
||||
|
||||
module.exports = BaseTest.extend({
|
||||
module.exports = {
|
||||
testEncryptedInvalidKeys: function() {
|
||||
// test failure with invalid keys
|
||||
TestCase.assertThrows(function() {
|
||||
@ -57,4 +56,4 @@ module.exports = BaseTest.extend({
|
||||
var realm = new Realm({schema: [Schemas.TestObject], encryptionKey: key});
|
||||
TestCase.assertEqual(realm.objects('TestObject').length, 1);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
@ -18,6 +18,8 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var Realm = require('realm');
|
||||
|
||||
var TESTS = {
|
||||
ListTests: require('./list-tests'),
|
||||
ObjectTests: require('./object-tests'),
|
||||
@ -58,7 +60,14 @@ exports.runTest = function(suiteName, testName) {
|
||||
var testMethod = testSuite && testSuite[testName];
|
||||
|
||||
if (testMethod) {
|
||||
testMethod.call(testSuite);
|
||||
// Start fresh in case of a crash in a previous run.
|
||||
Realm.clearTestState();
|
||||
|
||||
try {
|
||||
testMethod.call(testSuite);
|
||||
} finally {
|
||||
Realm.clearTestState();
|
||||
}
|
||||
} else if (!testSuite || !(testName in SPECIAL_METHODS)) {
|
||||
throw new Error('Missing test: ' + suiteName + '.' + testName);
|
||||
}
|
||||
|
@ -19,11 +19,10 @@
|
||||
'use strict';
|
||||
|
||||
var Realm = require('realm');
|
||||
var BaseTest = require('./base-test');
|
||||
var TestCase = require('./asserts');
|
||||
var schemas = require('./schemas');
|
||||
|
||||
module.exports = BaseTest.extend({
|
||||
module.exports = {
|
||||
testListConstructor: function() {
|
||||
var realm = new Realm({schema: [schemas.PersonObject, schemas.PersonList]});
|
||||
|
||||
@ -653,4 +652,4 @@ module.exports = BaseTest.extend({
|
||||
list.length;
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
@ -19,11 +19,10 @@
|
||||
'use strict';
|
||||
|
||||
var Realm = require('realm');
|
||||
var BaseTest = require('./base-test');
|
||||
var TestCase = require('./asserts');
|
||||
var Schemas = require('./schemas');
|
||||
|
||||
module.exports = BaseTest.extend({
|
||||
module.exports = {
|
||||
testMigrationFunction: function() {
|
||||
var count = 0;
|
||||
function migrationFunction(oldRealm, newRealm) {
|
||||
@ -159,4 +158,4 @@ module.exports = BaseTest.extend({
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
@ -19,7 +19,6 @@
|
||||
'use strict';
|
||||
|
||||
var Realm = require('realm');
|
||||
var BaseTest = require('./base-test');
|
||||
var TestCase = require('./asserts');
|
||||
var schemas = require('./schemas');
|
||||
|
||||
@ -28,7 +27,7 @@ var RANDOM_DATA = new Uint8Array([
|
||||
0x67, 0x1e, 0x40, 0xa7, 0x6d, 0x52, 0x83, 0xda, 0x07, 0x29, 0x9c, 0x70, 0x38, 0x48, 0x4e, 0xff,
|
||||
]);
|
||||
|
||||
module.exports = BaseTest.extend({
|
||||
module.exports = {
|
||||
testBasicTypesPropertyGetters: function() {
|
||||
var realm = new Realm({schema: [schemas.BasicTypes]});
|
||||
var object;
|
||||
@ -506,4 +505,4 @@ module.exports = BaseTest.extend({
|
||||
TestCase.assertEqual(realm.objects('Date')[2].currentDate.getTime(), 1000000000000);
|
||||
TestCase.assertEqual(realm.objects('Date')[3].currentDate.getTime(), -1000000000000);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -20,7 +20,6 @@
|
||||
'use strict';
|
||||
|
||||
var Realm = require('realm');
|
||||
var BaseTest = require('./base-test');
|
||||
var TestCase = require('./asserts');
|
||||
var schemas = require('./schemas');
|
||||
var testCases = require('./query-tests.json');
|
||||
@ -116,7 +115,7 @@ function runQuerySuite(suite) {
|
||||
}
|
||||
|
||||
|
||||
module.exports = BaseTest.extend({
|
||||
module.exports = {
|
||||
testDateQueries: function() {
|
||||
runQuerySuite(testCases.dateTests);
|
||||
},
|
||||
@ -150,4 +149,4 @@ module.exports = BaseTest.extend({
|
||||
testOptionalQueries: function() {
|
||||
runQuerySuite(testCases.optionalTests);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -19,11 +19,10 @@
|
||||
'use strict';
|
||||
|
||||
var Realm = require('realm');
|
||||
var BaseTest = require('./base-test');
|
||||
var TestCase = require('./asserts');
|
||||
var schemas = require('./schemas');
|
||||
|
||||
module.exports = BaseTest.extend({
|
||||
module.exports = {
|
||||
testRealmConstructor: function() {
|
||||
var realm = new Realm({schema: []});
|
||||
TestCase.assertTrue(realm instanceof Realm);
|
||||
@ -753,4 +752,4 @@ module.exports = BaseTest.extend({
|
||||
var realm = new Realm({path: 'dates-v5.realm', schema: [schemas.DateObject]});
|
||||
TestCase.assertEqual(realm.objects('Date')[0].currentDate.getTime(), 1);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
@ -19,11 +19,10 @@
|
||||
'use strict';
|
||||
|
||||
var Realm = require('realm');
|
||||
var BaseTest = require('./base-test');
|
||||
var TestCase = require('./asserts');
|
||||
var schemas = require('./schemas');
|
||||
|
||||
module.exports = BaseTest.extend({
|
||||
module.exports = {
|
||||
testResultsConstructor: function() {
|
||||
var realm = new Realm({schema: [schemas.TestObject]});
|
||||
var objects = realm.objects('TestObject');
|
||||
@ -368,4 +367,4 @@ module.exports = BaseTest.extend({
|
||||
TestCase.assertEqual(snapshot.length, 0);
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
4
tests/react-test-app/tests/listview-test.js
vendored
4
tests/react-test-app/tests/listview-test.js
vendored
@ -49,10 +49,6 @@ function createDataSource() {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
afterEach() {
|
||||
Realm.clearTestState();
|
||||
},
|
||||
|
||||
testDataSource() {
|
||||
let realm = createRealm();
|
||||
let objects = realm.objects('UniqueObject').sorted('id');
|
||||
|
Loading…
x
Reference in New Issue
Block a user