aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/testing1.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/wasm/testing1.js')
-rw-r--r--ext/wasm/testing1.js49
1 files changed, 32 insertions, 17 deletions
diff --git a/ext/wasm/testing1.js b/ext/wasm/testing1.js
index a733156e7..e45b52bfa 100644
--- a/ext/wasm/testing1.js
+++ b/ext/wasm/testing1.js
@@ -19,7 +19,8 @@
const toss = function(...args){throw new Error(args.join(' '))};
const debug = console.debug.bind(console);
const eOutput = document.querySelector('#test-output');
- const log = console.log.bind(console)
+ const log = console.log.bind(console),
+ warn = console.warn.bind(console);
const logHtml = function(...args){
log.apply(this, args);
const ln = document.createElement('div');
@@ -32,6 +33,8 @@
return v1>=(v2-factor) && v1<=(v2+factor);
};
+ let sqlite3;
+
const testBasicSanity = function(db,sqlite3){
const capi = sqlite3.capi;
log("Basic sanity tests...");
@@ -162,10 +165,10 @@
}
try {
- throw new capi.WasmAllocError;
+ throw new sqlite3.WasmAllocError;
}catch(e){
T.assert(e instanceof Error)
- .assert(e instanceof capi.WasmAllocError);
+ .assert(e instanceof sqlite3.WasmAllocError);
}
try {
@@ -251,7 +254,7 @@
db.exec({
sql:new TextEncoder('utf-8').encode([
// ^^^ testing string-vs-typedarray handling in execMulti()
- "attach 'foo.db' as foo;",
+ "attach 'session' as foo;" /* name 'session' is magic for kvvfs! */,
"create table foo.bar(a);",
"insert into foo.bar(a) values(1),(2),(3);",
"select a from foo.bar order by a;"
@@ -743,7 +746,7 @@
.assert('sqlite3_vfs' === dVfs.structName)
.assert(!!dVfs.structInfo)
.assert(SB.StructType.hasExternalPointer(dVfs))
- .assert(3===dVfs.$iVersion)
+ .assert(dVfs.$iVersion>0)
.assert('number'===typeof dVfs.$zName)
.assert('number'===typeof dVfs.$xSleep)
.assert(capi.wasm.functionEntry(dVfs.$xOpen))
@@ -1004,15 +1007,22 @@
}
}/*testWasmUtil()*/;
+ const clearKvvfs = function(){
+ const sz = sqlite3.capi.sqlite3_web_kvvfs_size();
+ const n = sqlite3.capi.sqlite3_web_kvvfs_clear('');
+ log("Cleared kvvfs local/sessionStorage:",
+ n,"entries totaling approximately",sz,"bytes.");
+ };
+
const runTests = function(Module){
//log("Module",Module);
- const sqlite3 = Module.sqlite3,
- capi = sqlite3.capi,
+ sqlite3 = Module.sqlite3;
+ const capi = sqlite3.capi,
oo = sqlite3.oo1,
wasm = capi.wasm;
log("Loaded module:",capi.sqlite3_libversion(), capi.sqlite3_sourceid());
log("Build options:",wasm.compileOptionUsed());
-
+ capi.sqlite3_web_persistent_dir()/*will install OPFS if available, plus a and non-locking VFS*/;
if(1){
/* Let's grab those last few lines of test coverage for
sqlite3-api.js... */
@@ -1045,9 +1055,19 @@
T.assert(capi.wasm[k] instanceof Function);
});
- const db = new oo.DB(':memory:'), startTime = performance.now();
+ let dbName = "/testing1.sqlite3";
+ let vfsName = undefined;
+ if(capi.sqlite3_web_db_is_kvvfs()){
+ dbName = "local";
+ vfsName = 'kvvfs';
+ logHtml("Found kvvfs. Clearing db(s) from sessionStorage and localStorage",
+ "and selecting kvvfs-friendly db name:",dbName);
+ clearKvvfs();
+ }
+ const db = new oo.DB(dbName,'c',vfsName), startTime = performance.now();
+ log("capi.sqlite3_web_db_is_kvvfs() ==",capi.sqlite3_web_db_is_kvvfs(db.pointer));
try {
- log("DB filename:",db.filename,db.fileName());
+ log("db.filename =",db.filename,"db.fileName() =",db.fileName());
const banner1 = '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>',
banner2 = '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<';
[
@@ -1062,18 +1082,13 @@
});
}finally{
db.close();
+ if('kvvfs'===vfsName) clearKvvfs();
}
logHtml("Total Test count:",T.counter,"in",(performance.now() - startTime),"ms");
log('capi.wasm.exports',capi.wasm.exports);
};
- sqlite3InitModule(self.sqlite3TestModule).then(function(theModule){
- /** Use a timeout so that we are (hopefully) out from under
- the module init stack when our setup gets run. Just on
- principle, not because we _need_ to be. */
- //console.debug("theModule =",theModule);
- //setTimeout(()=>runTests(theModule), 0);
- // ^^^ Chrome warns: "VIOLATION: setTimeout() handler took A WHOLE 50ms!"
+ self.sqlite3TestModule.initSqlite3().then(function(theModule){
self._MODULE = theModule /* this is only to facilitate testing from the console */
runTests(theModule);
});