mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
test: Add folder utilities.
This commit is contained in:
parent
9a89766858
commit
8dcb498201
@ -1,15 +1,11 @@
|
||||
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';
|
||||
|
||||
/**
|
||||
* Creates a RuntimeConfig with its rootFilePath set based on the given subfolder.
|
||||
* @param subfolder - Folder to use in the global testData folder.
|
||||
*/
|
||||
export const getRootFilePath = (subfolder: string): string => join(__dirname, '../testData', subfolder);
|
||||
|
||||
/**
|
||||
* Returns a component instantiated from a Components.js configuration.
|
||||
*/
|
||||
@ -24,3 +20,14 @@ export const instantiateFromConfig = async(componentUrl: string, configFile: str
|
||||
const configPath = Path.join(__dirname, 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 });
|
||||
};
|
||||
|
@ -1,14 +1,13 @@
|
||||
import { createReadStream, mkdirSync } from 'fs';
|
||||
import { createReadStream } from 'fs';
|
||||
import { join } from 'path';
|
||||
import * as rimraf from 'rimraf';
|
||||
import type { HttpHandler, Initializer, ResourceStore } from '../../src/';
|
||||
import { RepresentationMetadata } from '../../src/ldp/representation/RepresentationMetadata';
|
||||
import { guardStream } from '../../src/util/GuardedStream';
|
||||
import { CONTENT_TYPE, LDP } from '../../src/util/UriConstants';
|
||||
import { AclTestHelper, FileTestHelper } from '../util/TestHelpers';
|
||||
import { BASE, getRootFilePath, instantiateFromConfig } from './Config';
|
||||
import { BASE, getTestFolder, createFolder, removeFolder, instantiateFromConfig } from './Config';
|
||||
|
||||
const rootFilePath = getRootFilePath('full-config-acl');
|
||||
const rootFilePath = getTestFolder('full-config-acl');
|
||||
const stores: [string, any][] = [
|
||||
[ 'in-memory storage', {
|
||||
storeUrn: 'urn:solid-server:default:MemoryResourceStore',
|
||||
@ -17,12 +16,8 @@ const stores: [string, any][] = [
|
||||
}],
|
||||
[ 'on-disk storage', {
|
||||
storeUrn: 'urn:solid-server:default:FileResourceStore',
|
||||
setup(): void {
|
||||
mkdirSync(rootFilePath, { recursive: true });
|
||||
},
|
||||
teardown(): void {
|
||||
rimraf.sync(rootFilePath, { glob: false });
|
||||
},
|
||||
setup: (): void => createFolder(rootFilePath),
|
||||
teardown: (): void => removeFolder(rootFilePath),
|
||||
}],
|
||||
];
|
||||
|
||||
|
@ -1,11 +1,9 @@
|
||||
import { mkdirSync } from 'fs';
|
||||
import * as rimraf from 'rimraf';
|
||||
import type { HttpHandler, Initializer, ResourceStore } from '../../src/';
|
||||
import { LDP } from '../../src/util/UriConstants';
|
||||
import { FileTestHelper } from '../util/TestHelpers';
|
||||
import { BASE, getRootFilePath, instantiateFromConfig } from './Config';
|
||||
import { BASE, getTestFolder, createFolder, removeFolder, instantiateFromConfig } from './Config';
|
||||
|
||||
const rootFilePath = getRootFilePath('full-config-no-auth');
|
||||
const rootFilePath = getTestFolder('full-config-no-auth');
|
||||
const stores: [string, any][] = [
|
||||
[ 'in-memory storage', {
|
||||
storeUrn: 'urn:solid-server:default:MemoryResourceStore',
|
||||
@ -14,12 +12,8 @@ const stores: [string, any][] = [
|
||||
}],
|
||||
[ 'on-disk storage', {
|
||||
storeUrn: 'urn:solid-server:default:FileResourceStore',
|
||||
setup(): void {
|
||||
mkdirSync(rootFilePath, { recursive: true });
|
||||
},
|
||||
teardown(): void {
|
||||
rimraf.sync(rootFilePath, { glob: false });
|
||||
},
|
||||
setup: (): void => createFolder(rootFilePath),
|
||||
teardown: (): void => removeFolder(rootFilePath),
|
||||
}],
|
||||
];
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user