mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { mkdirSync } from 'fs';
|
|
import { join } from 'path';
|
|
import * as Path from 'path';
|
|
import { Loader } from 'componentsjs';
|
|
import * as rimraf from 'rimraf';
|
|
|
|
export const BASE = 'http://test.com';
|
|
|
|
/**
|
|
* Returns a component instantiated from a Components.js configuration.
|
|
*/
|
|
export const instantiateFromConfig = async(componentUrl: string, configFile: string,
|
|
variables?: Record<string, any>): Promise<any> => {
|
|
// Initialize the Components.js loader
|
|
const mainModulePath = Path.join(__dirname, '../../');
|
|
const loader = new Loader({ mainModulePath });
|
|
await loader.registerAvailableModuleResources();
|
|
|
|
// Instantiate the component from the config
|
|
const configPath = Path.join(__dirname, 'config', configFile);
|
|
return loader.instantiateFromUrl(componentUrl, configPath, undefined, { variables });
|
|
};
|
|
|
|
export const getTestFolder = (name: string): string =>
|
|
join(__dirname, '../tmp', name);
|
|
|
|
export const createFolder = (folder: string): void => {
|
|
mkdirSync(folder, { recursive: true });
|
|
};
|
|
|
|
export const removeFolder = (folder: string): void => {
|
|
rimraf.sync(folder, { glob: false });
|
|
};
|