mirror of
https://github.com/frappe/books.git
synced 2026-08-24 10:04:45 -05:00
incr: add dummy inventory test
- add test boiler plate - fix import error
This commit is contained in:
@@ -2,7 +2,10 @@ import { DatabaseManager } from 'backend/database/manager';
|
||||
import { config } from 'dotenv';
|
||||
import { Fyo } from 'fyo';
|
||||
import { DummyAuthDemux } from 'fyo/tests/helpers';
|
||||
import path from 'path';
|
||||
import setupInstance from 'src/setup/setupInstance';
|
||||
import { SetupWizardOptions } from 'src/setup/types';
|
||||
import test from 'tape';
|
||||
import { getFiscalYear } from 'utils/misc';
|
||||
|
||||
export function getTestSetupWizardOptions(): SetupWizardOptions {
|
||||
@@ -25,6 +28,21 @@ export function getTestDbPath(dbPath?: string) {
|
||||
return dbPath ?? process.env.TEST_DB_PATH ?? ':memory:';
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Boilerplate
|
||||
*
|
||||
* The bottom three functions are test boilerplate for when
|
||||
* an initialized fyo object is to be used.
|
||||
*
|
||||
* They are required because top level await is not supported.
|
||||
*
|
||||
* Therefore setup and cleanup of the fyo object is wrapped
|
||||
* in tests which are executed serially (and awaited in order)
|
||||
* by tape.
|
||||
*
|
||||
* If `closeTestFyo` is not called the test process won't exit.
|
||||
*/
|
||||
|
||||
export function getTestFyo(): Fyo {
|
||||
return new Fyo({
|
||||
DatabaseDemux: DatabaseManager,
|
||||
@@ -33,3 +51,23 @@ export function getTestFyo(): Fyo {
|
||||
isElectron: false,
|
||||
});
|
||||
}
|
||||
|
||||
const ext = '.spec.ts';
|
||||
|
||||
export function setupTestFyo(fyo: Fyo, filename: string) {
|
||||
const testName = path.basename(filename, ext);
|
||||
|
||||
return test(`setup: ${testName}`, async () => {
|
||||
const options = getTestSetupWizardOptions();
|
||||
const dbPath = getTestDbPath();
|
||||
await setupInstance(dbPath, options, fyo);
|
||||
});
|
||||
}
|
||||
|
||||
export function closeTestFyo(fyo: Fyo, filename: string) {
|
||||
const testName = path.basename(filename, ext);
|
||||
|
||||
return test(`cleanup: ${testName}`, async () => {
|
||||
await fyo.close();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user