@webda/core
Version:
Expose API with Lambda
163 lines (162 loc) • 4.39 kB
TypeScript
import { WorkerLogLevel, WorkerOutput } from "@webda/workout";
import { Core, CoreModelDefinition, HttpMethodType, Service, WebContext } from "./index.js";
import { CachedModule, ModelGraph } from "./application.js";
import { UnpackedApplication } from "./unpackedapplication.js";
/**
* TestApplication ensure we load the typescript sources instead of compiled version
*
* Test use ts-node so to share same prototypes we need to load from the sources
*/
export declare class TestApplication extends UnpackedApplication {
constructor(file?: string, logger?: WorkerOutput);
/**
* Force the namespace to WebdaDemo
* @returns
*/
getNamespace(): string;
/**
* Set the status of the compilation
*
* @param compile true will avoid trigger new compilation
*/
preventCompilation(compile: boolean): void;
/**
* Flag if application has been compiled already
*/
protected compiled: boolean;
/**
* Compile the application
*/
compile(): void;
/**
* Load a webda.module.json file
* Resolve the linked file to current application
*
* @param moduleFile to load
* @returns
*/
loadWebdaModule(moduleFile: string): CachedModule;
}
/**
* Utility class for UnitTest
*
* @category CoreFeatures
*/
declare class WebdaTest {
webda: Core;
addConsoleLogger: boolean;
/**
* Files to clean after test
*/
cleanFiles: string[];
/**
* Get the configuration file to use for the test
*
* @returns absolute path to configuration file
*/
getTestConfiguration(): string | undefined;
/**
* Allow test to add custom made service
* @param app
*/
tweakApp(app: TestApplication): Promise<void>;
/**
* Build the webda application
*
* Add a ConsoleLogger if addConsoleLogger is true
*/
protected buildWebda(): Promise<void>;
/**
* Rebuild Webda application before each test
*
* @param init wait for the full init
*/
before(init?: boolean): Promise<void>;
after(): void;
/**
*
* @param level
* @param args
*/
log(level: WorkerLogLevel, ...args: any[]): void;
/**
* Create a new Context object
*
* The context is initialized to GET test.webda.io/
*
* @param body to add to the context
* @returns
*/
newContext<T extends WebContext>(body?: any): Promise<T>;
/**
* Get an Executor from Webda
*
* @param ctx
* @param host
* @param method
* @param url
* @param body
* @param headers
* @returns
*/
getExecutor(ctx?: WebContext, host?: string, method?: HttpMethodType, url?: string, body?: any, headers?: {
[key: string]: string;
}): {
execute: (context?: WebContext) => Promise<any>;
};
/**
* Execute a test request
* @param params
* @returns
*/
http<T = any>(params?: {
method?: HttpMethodType;
url?: string;
body?: any;
context?: WebContext;
headers?: {
[key: string]: string;
};
}): Promise<T>;
execute(context?: WebContext, host?: string, method?: HttpMethodType, url?: string, body?: any, headers?: {
[key: string]: string;
}): Promise<any>;
/**
* Pause for time ms
*
* @param time ms
*/
sleep(time: any): Promise<void>;
/**
* Create a graph of objets from sample-app to be able to test graph
*/
createGraphObjects(): Promise<void>;
/**
* Wait for the next tick(s)
* @param ticks if you want to wait for more than one tick
*/
nextTick(ticks?: number): Promise<void>;
/**
* Get service from Webda
* @param service name
* @returns
*/
getService<T extends Service>(service: string): T;
/**
* Dynamic add a service to webda
*
* @param name of the service to add
* @param service to add
*/
registerService<T extends Service>(service: T, name?: string): T;
/**
* Dynamic add a model to webda
* @param model
* @param klass
*/
registerModel<T extends CoreModelDefinition>(model: T, name?: string, graph?: ModelGraph): void;
}
declare class WebdaSimpleTest extends WebdaTest {
getTestConfiguration(): string;
}
export { WebdaSimpleTest, WebdaTest };