Browse Source

fix(playwright): AsyncDatabase

pull/5903/head
Wing-Kam Wong 1 year ago
parent
commit
b8da41dae2
  1. 18
      tests/playwright/setup/db.ts
  2. 6
      tests/playwright/setup/sqliteExec.ts

18
tests/playwright/setup/db.ts

@ -2,8 +2,7 @@ import { NcContext } from '.';
const mysql = require('mysql2'); const mysql = require('mysql2');
const { Client } = require('pg'); const { Client } = require('pg');
import { PromisedDatabase } from 'promised-sqlite3'; import { AsyncDatabase } from 'promised-sqlite3';
const sqliteDb = new PromisedDatabase();
const isMysql = (context: NcContext) => context.dbType === 'mysql'; const isMysql = (context: NcContext) => context.dbType === 'mysql';
@ -53,12 +52,15 @@ const mysqlExec = async query => {
}; };
async function sqliteExec(query) { async function sqliteExec(query) {
const parallelIndex = process.env.TEST_PARALLEL_INDEX; try {
const rootProjectDir = __dirname.replace('/tests/playwright/setup', ''); const parallelIndex = process.env.TEST_PARALLEL_INDEX;
await sqliteDb.open(`${rootProjectDir}/packages/nocodb/test_sakila_${parallelIndex}.db`); const rootProjectDir = __dirname.replace('/tests/playwright/setup', '');
const sqliteDb = await AsyncDatabase.open(`${rootProjectDir}/packages/nocodb/test_sakila_${parallelIndex}.db`);
await sqliteDb.run(query); await sqliteDb.run(query);
await sqliteDb.close(); await sqliteDb.close();
} catch (err) {
console.error(err);
}
} }
export { sqliteExec, mysqlExec, isMysql, isSqlite, isPg, pgExec }; export { sqliteExec, mysqlExec, isMysql, isSqlite, isPg, pgExec };

6
tests/playwright/setup/sqliteExec.ts

@ -1,10 +1,8 @@
const { PromisedDatabase } = require('promised-sqlite3'); import { AsyncDatabase } from 'promised-sqlite3';
const sqliteDb = new PromisedDatabase();
async function sqliteExec(query) { async function sqliteExec(query) {
const rootProjectDir = __dirname.replace('/scripts/playwright/setup', ''); const rootProjectDir = __dirname.replace('/scripts/playwright/setup', '');
await sqliteDb.open(`${rootProjectDir}/packages/nocodb/test_noco.db`); const sqliteDb = await AsyncDatabase.open(`${rootProjectDir}/packages/nocodb/test_noco.db`);
await sqliteDb.run(query); await sqliteDb.run(query);
} }

Loading…
Cancel
Save