|
| 1 | +var sqlite3 = require('..'); |
| 2 | +var assert = require('assert'); |
| 3 | + |
| 4 | +describe('patching', function() { |
| 5 | + var db; |
| 6 | + var originalFunctions = {}; |
| 7 | + |
| 8 | + before(function() { |
| 9 | + originalFunctions.close = sqlite3.Database.prototype.close; |
| 10 | + originalFunctions.exec = sqlite3.Database.prototype.exec; |
| 11 | + originalFunctions.wait = sqlite3.Database.prototype.wait; |
| 12 | + originalFunctions.loadExtension = sqlite3.Database.prototype.loadExtension; |
| 13 | + originalFunctions.serialize = sqlite3.Database.prototype.serialize; |
| 14 | + originalFunctions.parallelize = sqlite3.Database.prototype.parallelize; |
| 15 | + originalFunctions.configure = sqlite3.Database.prototype.configure; |
| 16 | + originalFunctions.interrupt = sqlite3.Database.prototype.interrupt; |
| 17 | + }); |
| 18 | + |
| 19 | + it('allow patching native functions', function() { |
| 20 | + var myFun = function myFunction() { |
| 21 | + return "Success"; |
| 22 | + } |
| 23 | + |
| 24 | + assert.doesNotThrow(() => { |
| 25 | + sqlite3.Database.prototype.close = myFun; |
| 26 | + }); |
| 27 | + assert.doesNotThrow(() => { |
| 28 | + sqlite3.Database.prototype.exec = myFun; |
| 29 | + }); |
| 30 | + assert.doesNotThrow(() => { |
| 31 | + sqlite3.Database.prototype.wait = myFun; |
| 32 | + }); |
| 33 | + assert.doesNotThrow(() => { |
| 34 | + sqlite3.Database.prototype.loadExtension = myFun; |
| 35 | + }); |
| 36 | + assert.doesNotThrow(() => { |
| 37 | + sqlite3.Database.prototype.serialize = myFun; |
| 38 | + }); |
| 39 | + assert.doesNotThrow(() => { |
| 40 | + sqlite3.Database.prototype.parallelize = myFun; |
| 41 | + }); |
| 42 | + assert.doesNotThrow(() => { |
| 43 | + sqlite3.Database.prototype.configure = myFun; |
| 44 | + }); |
| 45 | + assert.doesNotThrow(() => { |
| 46 | + sqlite3.Database.prototype.interrupt = myFun; |
| 47 | + }); |
| 48 | + |
| 49 | + db = new sqlite3.Database(':memory:'); |
| 50 | + assert.strictEqual(db.close(), "Success"); |
| 51 | + assert.strictEqual(db.exec(), "Success"); |
| 52 | + assert.strictEqual(db.wait(), "Success"); |
| 53 | + assert.strictEqual(db.loadExtension(), "Success"); |
| 54 | + assert.strictEqual(db.serialize(), "Success"); |
| 55 | + assert.strictEqual(db.parallelize(), "Success"); |
| 56 | + assert.strictEqual(db.configure(), "Success"); |
| 57 | + assert.strictEqual(db.interrupt(), "Success"); |
| 58 | + }); |
| 59 | + |
| 60 | + after(function() { |
| 61 | + if(db != null) { |
| 62 | + sqlite3.Database.prototype.close = originalFunctions.close; |
| 63 | + sqlite3.Database.prototype.exec = originalFunctions.exec; |
| 64 | + sqlite3.Database.prototype.wait = originalFunctions.wait; |
| 65 | + sqlite3.Database.prototype.loadExtension = originalFunctions.loadExtension; |
| 66 | + sqlite3.Database.prototype.serialize = originalFunctions.serialize; |
| 67 | + sqlite3.Database.prototype.parallelize = originalFunctions.parallelize; |
| 68 | + sqlite3.Database.prototype.configure = originalFunctions.configure; |
| 69 | + sqlite3.Database.prototype.interrupt = originalFunctions.interrupt; |
| 70 | + db.close(); |
| 71 | + } |
| 72 | + }); |
| 73 | + |
| 74 | +}); |
0 commit comments