-
-
Notifications
You must be signed in to change notification settings - Fork 829
/
Copy pathprofile.test.js
56 lines (49 loc) · 1.43 KB
/
profile.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var sqlite3 = require('..');
var assert = require('assert');
describe('profiling', function() {
var create = false;
var select = false;
var db;
before(function(done) {
db = new sqlite3.Database(':memory:', done);
db.on('profile', function(sql, nsecs) {
assert.ok(typeof nsecs === "number");
if (sql.match(/^SELECT/)) {
assert.ok(!select);
assert.equal(sql, "SELECT * FROM foo");
select = true;
}
else if (sql.match(/^CREATE/)) {
assert.ok(!create);
assert.equal(sql, "CREATE TABLE foo (id int)");
create = true;
}
else {
assert.ok(false);
}
});
});
it('should profile a create table', function(done) {
assert.ok(!create);
db.run("CREATE TABLE foo (id int)", function(err) {
if (err) throw err;
setImmediate(function() {
assert.ok(create);
done();
});
});
});
it('should profile a select', function(done) {
assert.ok(!select);
db.run("SELECT * FROM foo", function(err) {
if (err) throw err;
setImmediate(function() {
assert.ok(select);
done();
}, 0);
});
});
after(function(done) {
db.close(done);
});
});