And we get the following errors:
\nconsole.error\n Error: Error: connect ECONNREFUSED 127.0.0.1:80\n at Object.dispatchError (<omitted>/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:63:19)\n at Request.<anonymous> (<omitted>/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:655:18)\n at Request.emit (node:events:539:35)\n at ClientRequest.<anonymous> (<omitted>/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:121:14)\n at ClientRequest.emit (node:events:527:28)\n at Socket.socketErrorListener (node:_http_client:454:9)\n at Socket.emit (node:events:527:28)\n at emitErrorNT (node:internal/streams/destroy:157:8)\n at emitErrorCloseNT (node:internal/streams/destroy:122:3)\n at processTicksAndRejections (node:internal/process/task_queues:83:21) undefined\n\n at VirtualConsole.<anonymous> (node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/virtual-console.js:29:45)\n\n console.warn\n Aborted(both async and sync fetching of the wasm failed)\n\n at E (node_modules/jeep-sqlite/dist/cjs/node_modules/sql.js/dist/sql-wasm.js:101:136)\n at ab (node_modules/jeep-sqlite/dist/cjs/node_modules/sql.js/dist/sql-wasm.js:102:149)\n at node_modules/jeep-sqlite/dist/cjs/node_modules/sql.js/dist/sql-wasm.js:103:256\n\n console.warn\n failed to asynchronously prepare wasm: RuntimeError: Aborted(both async and sync fetching of the wasm failed). Build with -sASSERTIONS for more info.\n\n at node_modules/jeep-sqlite/dist/cjs/node_modules/sql.js/dist/sql-wasm.js:158:377\n\n console.warn\n Aborted(RuntimeError: Aborted(both async and sync fetching of the wasm failed). Build with -sASSERTIONS for more info.)\n\n at E (node_modules/jeep-sqlite/dist/cjs/node_modules/sql.js/dist/sql-wasm.js:101:136)\n at node_modules/jeep-sqlite/dist/cjs/node_modules/sql.js/dist/sql-wasm.js:158:425\n\n ● getLookupRecordData › updateOfflineData › test db\n\n both async and sync fetching of the wasm failed\n\n at Object.Module.onAbort (node_modules/jeep-sqlite/dist/cjs/node_modules/sql.js/dist/sql-wasm.js:40:20)\n at E (node_modules/jeep-sqlite/dist/cjs/node_modules/sql.js/dist/sql-wasm.js:101:106)\n at ab (node_modules/jeep-sqlite/dist/cjs/node_modules/sql.js/dist/sql-wasm.js:102:149)\n at node_modules/jeep-sqlite/dist/cjs/node_modules/sql.js/dist/sql-wasm.js:103:256\n\n ● getLookupRecordData › updateOfflineData › test db\n\n RuntimeError: Aborted(RuntimeError: Aborted(both async and sync fetching of the wasm failed). Build with -sASSERTIONS for more info.). Build with -sASSERTIONS for more info.\n\n at E (node_modules/jeep-sqlite/dist/cjs/node_modules/sql.js/dist/sql-wasm.js:101:154)\n at node_modules/jeep-sqlite/dist/cjs/node_modules/sql.js/dist/sql-wasm.js:158:425\nSo I guess a two questions:
\nAny hints would be highly appreciated! Thanks!
","upvoteCount":3,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Hello, sorry for the late answer.
\nYes I did find an answer. The solution that worked was spinning up a server before running the test. So we added the following scripts to our package.json:
\n \"scripts\": {\n \"serve\": \"cp node_modules/sql.js/dist/sql-wasm.wasm build/assets && serve -l 80 build/\",\n \"test\": \"{Your test script here}\",\n \"test:serve\": \"npm-run-all --parallel -r serve test\", \n },\nThen we ran npm run test:serve when running the test. The test:serve script serves a local host that jeepSqlite is trying to reach out to in order to retrieve the sql-wasm.wasm file.
-
|
Hi y'all 👋 I use this library within my application. I am hoping to write some unit tests with Jest where each test has a db instance that I can seed and use to test. I've ran into an issue implementing this db instance in my test file where jeep-sqlite cannot load the specified wasm file. Here is my test file I am trying to implement import { resolve } from 'path';
import { CapacitorSQLite, SQLiteConnection, SQLiteDBConnection } from '@capacitor-community/sqlite';
import { defineCustomElements as jeepSqlite, applyPolyfills, JSX as LocalJSX } from 'jeep-sqlite/loader';
// ...
const dbName = config.databaseName;
type StencilToReact<T> = {
[P in keyof T]?: T[P] & Omit<HTMLAttributes<Element>, 'className'> & {
class?: string;
};
} ;
declare global {
export namespace JSX {
interface IntrinsicElements extends StencilToReact<LocalJSX.IntrinsicElements> {
}
}
}
applyPolyfills().then(() => {
jeepSqlite(window, {});
});
it('test', async () => {
const sqlite: SQLiteConnection = new SQLiteConnection(CapacitorSQLite);
const jeepEl = document.createElement('jeep-sqlite');
document.body.appendChild(jeepEl);
const element = await customElements.whenDefined('jeep-sqlite');
const assetPath = resolve(`${__dirname}/../../../public/assets`); // we've also tried '.../assets/sql-wasm.wasm'
jeepEl.setAttribute('wasmPath', assetPath ); // attempt to set the wasmPath
const sqlite: SQLiteConnection = new SQLiteConnection(CapacitorSQLite);
await sqlite.initWebStore();
const ret = await sqlite.checkConnectionsConsistency();
const isConn = (await sqlite.isConnection(dbName, false)).result;
let db: SQLiteDBConnection;
if (ret.result && isConn) {
db = await sqlite.retrieveConnection(dbName, false);
} else {
db = await sqlite.createConnection(dbName, false, 'no-encryption', 1, false);
}
try {
await db.open();
} catch (err) {
// ...
}
// ...
}And we get the following errors: So I guess a two questions:
Any hints would be highly appreciated! Thanks! |
Beta Was this translation helpful? Give feedback.
-
|
@Brandi-Youreka I never run jest test , but i do not see something wrong to try like you do must work i think the problem comes from the assetPath given, the error you have is that it cannot load the wasm file |
Beta Was this translation helpful? Give feedback.
Hello, sorry for the late answer.
Yes I did find an answer. The solution that worked was spinning up a server before running the test. So we added the following scripts to our package.json:
Then we ran
npm run test:servewhen running the test. Thetest:servescript serves a local host that jeepSqlite is trying to reach out to in order to retrieve thesql-wasm.wasmfile.