Commit a4cdfdd2 by Konstantin Käfer

automatically create test database on first test execution

parent 6cd00d98
...@@ -5,12 +5,18 @@ build: ...@@ -5,12 +5,18 @@ build:
clean: clean:
node-waf clean node-waf clean
db:
@if ! [ -f test/support/big.db ]; then \
echo "Creating test database... This may take several minutes." ; \
node test/support/createdb.js ; \
fi
ifndef only ifndef only
test: build test: build db
expresso -I lib test/*.test.js @expresso -I lib test/*.test.js
else else
test: build test: build db
expresso -I lib test/${only}.test.js @expresso -I lib test/${only}.test.js
endif endif
.PHONY: build clean test .PHONY: build clean test
\ No newline at end of file
#!/bin/sh
var sqlite3 = require('../../lib/sqlite3'); var sqlite3 = require('../../lib/sqlite3');
function randomString() { function randomString() {
...@@ -10,13 +9,13 @@ function randomString() { ...@@ -10,13 +9,13 @@ function randomString() {
return str; return str;
}; };
var db = new sqlite3.Database('big.db'); var db = new sqlite3.Database('test/support/big.db');
var count = 10000000; var count = 10000000;
db.serialize(function() { db.serialize(function() {
db.run("CREATE TABLE foo (id INT, txt TEXT)"); db.run("CREATE TABLE foo (id INT, txt TEXT)");
db.run("BEGIN TRANSACTION"); db.run("BEGIN TRANSACTION");
var stmt = db.prepare("INSERT INTO foo VALUES(?, ?)"); var stmt = db.prepare("INSERT INTO foo VALUES(?, ?)");
for (var i = 0; i < count; i++) { for (var i = 0; i < count; i++) {
...@@ -24,5 +23,4 @@ db.serialize(function() { ...@@ -24,5 +23,4 @@ db.serialize(function() {
} }
stmt.finalize(); stmt.finalize();
db.run("COMMIT TRANSACTION"); db.run("COMMIT TRANSACTION");
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment