ground:test
Basic syncronious test tool built for ground db.
What: It allows you to run tests in multiple clients and on the server.
How to install
$ meteor add ground:test
How this works
You create a qa meteor app, add ground:test and start writing your tests in the common server/client space - the test tool will make sure tests run in the correct environment.
Create a file "test1.js":
1GroundTest.add('Test common online insert/update/remove', function() { 2 3 var clientA = new this.Client('A'); 4 5 var clientB = new this.Client('B'); 6 7 var server = new this.Server(); 8 9 // Step 0 10 server('Clean db', function(complete) { 11 db.remove({}); 12 complete(); 13 }); 14 15 // Step 1 16 clientA('Create document on the client', function(complete) { 17 db = new GroundDB('test'); 18 19 db.insert({ test: 2, foo: 'test_new_document', bar: 'online' }, function(err, id) { 20 if (err) { 21 complete(err.message); 22 } else { 23 complete(); 24 } 25 }); 26 }); 27 28 // Step 2 29 server('Verify created document', function(complete) { 30 var doc = db.findOne({ test: 2 }); 31 32 if (doc) { 33 34 if (doc.foo == 'test_new_document' && doc.bar == 'online') { 35 complete(); 36 } else { 37 complete('Document is found but contains invalid data'); 38 } 39 40 } else { 41 complete('Could not find any documents matching'); 42 } 43 }); 44 45 // Step 3 46 clientB('Verify created document', function(complete) { 47 db = new GroundDB('test'); 48 49 var doc = db.findOne({ test: 2 }); 50 51 if (doc) { 52 53 if (doc.foo == 'test_new_document' && doc.bar == 'online') { 54 complete(); 55 } else { 56 complete('Document is found but contains invalid data'); 57 } 58 59 } else { 60 complete('Could not find any documents matching'); 61 } 62 }); 63 64 65 // Step 4 66 clientA('Update document on the client', function(complete) { 67 var doc = db.findOne({ test: 2 }); 68 69 db.update({ _id: doc._id }, { $set: { foo: 'test_update_document' } }, function(err) { 70 if (err) { 71 complete(err.message); 72 } else { 73 complete(); 74 } 75 }); 76 }); 77 78 // Step 5 79 server('Verify updated document', function(complete) { 80 var doc = db.findOne({ test: 2 }); 81 82 if (doc) { 83 84 if (doc.foo == 'test_update_document' && doc.bar == 'online') { 85 complete(); 86 } else { 87 complete('Document is found but contains invalid data'); 88 } 89 90 } else { 91 complete('Could not find any documents matching'); 92 } 93 }); 94 95 // Step 6 96 clientB('Verify updated document', function(complete) { 97 var doc = db.findOne({ test: 2 }); 98 99 if (doc) { 100 101 if (doc.foo == 'test_update_document' && doc.bar == 'online') { 102 complete(); 103 } else { 104 complete('Document is found but contains invalid data'); 105 } 106 107 } else { 108 complete('Could not find any documents matching'); 109 } 110 }); 111 112 113 // Step 6 114 clientA('Remove document on the client', function(complete) { 115 var doc = db.findOne({ test: 2 }); 116 117 db.remove({ _id: doc._id }, function(err) { 118 if (err) { 119 complete(err.message); 120 } else { 121 complete(); 122 } 123 }); 124 }); 125 126 // Step 7 127 server('Verify removed document', function(complete) { 128 var doc = db.findOne({ test: 2 }); 129 130 if (doc) { 131 complete('Document not removed'); 132 } else { 133 complete(); 134 } 135 }); 136 137 // Step 8 138 clientB('Verify removed document', function(complete) { 139 var doc = db.findOne({ test: 2 }); 140 141 if (doc) { 142 complete('Document not removed'); 143 } else { 144 complete(); 145 } 146 }); 147 148});