1
- // TODO: Instead of using tiny-worker , we could use the new Node 11 workers via
2
- // node --experimental-worker test/all.js
1
+ // TODO: Instead of using puppeteer , we could use the new Node 11 workers via
2
+ // node --experimental-worker test/all.js
3
3
// Then we could do this:
4
4
//const { Worker } = require('worker_threads');
5
- // But it turns out that the worker_threads interface is just different enough not to work.
5
+ // But it turns out that the worker_threads interface is just different enough not to work.
6
6
var puppeteer = require ( "puppeteer" ) ;
7
7
var path = require ( "path" ) ;
8
8
var fs = require ( "fs" ) ;
@@ -40,7 +40,7 @@ exports.test = async function test(SQL, assert) {
40
40
console . error ( "Skipping worker test for " + file + ". Not implemented yet" ) ;
41
41
return ;
42
42
} ;
43
- // If we use tiny-worker , we need to pass in this new cwd as the root of the file being loaded:
43
+ // If we use puppeteer , we need to pass in this new cwd as the root of the file being loaded:
44
44
const filename = "../dist/worker." + file + ".js" ;
45
45
var worker = await Worker . fromFile ( path . join ( __dirname , filename ) ) ;
46
46
var data = await worker . postMessage ( { id : 1 , action : 'open' } ) ;
@@ -50,20 +50,41 @@ exports.test = async function test(SQL, assert) {
50
50
data = await worker . postMessage ( {
51
51
id : 2 ,
52
52
action : 'exec' ,
53
+ params : {
54
+ ":num2" : 2 ,
55
+ "@str2" : 'b' ,
56
+ // test_worker.js has issue message-passing Uint8Array
57
+ // but it works fine in real-world browser-usage
58
+ // "$hex2": new Uint8Array([0x00, 0x42]),
59
+ ":num3" : 3 ,
60
+ "@str3" : 'c'
61
+ // "$hex3": new Uint8Array([0x00, 0x44])
62
+ } ,
53
63
sql : "CREATE TABLE test (num, str, hex);" +
54
64
"INSERT INTO test VALUES (1, 'a', x'0042');" +
65
+ "INSERT INTO test VALUES (:num2, @str2, x'0043');" +
66
+ // test passing params split across multi-statement "exec"
67
+ "INSERT INTO test VALUES (:num3, @str3, x'0044');" +
55
68
"SELECT * FROM test;"
56
69
} ) ;
57
70
assert . strictEqual ( data . id , 2 , "Correct id" ) ;
71
+ // debug error
72
+ assert . strictEqual ( data . error , undefined , data . error ) ;
58
73
var results = data . results ;
59
74
assert . ok ( Array . isArray ( results ) , 'Correct result type' ) ;
60
- assert . strictEqual ( results . length , 1 , 'Expected exactly 1 row' ) ;
61
- var row = results [ 0 ] ;
62
- assert . strictEqual ( typeof row , 'object' , 'Type of the returned row' ) ;
63
- assert . deepEqual ( row . columns , [ 'num' , 'str' , 'hex' ] , 'Reading column names' ) ;
64
- assert . strictEqual ( row . values [ 0 ] [ 0 ] , 1 , 'Reading number' ) ;
65
- assert . strictEqual ( row . values [ 0 ] [ 1 ] , 'a' , 'Reading string' ) ;
66
- assert . deepEqual ( obj2array ( row . values [ 0 ] [ 2 ] ) , [ 0x00 , 0x42 ] , 'Reading BLOB byte' ) ;
75
+ assert . strictEqual ( results . length , 1 , 'Expected exactly 1 table' ) ;
76
+ var table = results [ 0 ] ;
77
+ assert . strictEqual ( typeof table , 'object' , 'Type of the returned table' ) ;
78
+ assert . deepEqual ( table . columns , [ 'num' , 'str' , 'hex' ] , 'Reading column names' ) ;
79
+ assert . strictEqual ( table . values [ 0 ] [ 0 ] , 1 , 'Reading number' ) ;
80
+ assert . strictEqual ( table . values [ 0 ] [ 1 ] , 'a' , 'Reading string' ) ;
81
+ assert . deepEqual ( obj2array ( table . values [ 0 ] [ 2 ] ) , [ 0x00 , 0x42 ] , 'Reading BLOB byte' ) ;
82
+ assert . strictEqual ( table . values [ 1 ] [ 0 ] , 2 , 'Reading number' ) ;
83
+ assert . strictEqual ( table . values [ 1 ] [ 1 ] , 'b' , 'Reading string' ) ;
84
+ assert . deepEqual ( obj2array ( table . values [ 1 ] [ 2 ] ) , [ 0x00 , 0x43 ] , 'Reading BLOB byte' ) ;
85
+ assert . strictEqual ( table . values [ 2 ] [ 0 ] , 3 , 'Reading number' ) ;
86
+ assert . strictEqual ( table . values [ 2 ] [ 1 ] , 'c' , 'Reading string' ) ;
87
+ assert . deepEqual ( obj2array ( table . values [ 2 ] [ 2 ] ) , [ 0x00 , 0x44 ] , 'Reading BLOB byte' ) ;
67
88
68
89
data = await worker . postMessage ( { action : 'export' } ) ;
69
90
var header = "SQLite format 3\0" ;
0 commit comments