-
Notifications
You must be signed in to change notification settings - Fork 3
/
test-utils.ts
28 lines (23 loc) · 922 Bytes
/
test-utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import path from 'node:path';
import type { PleasantestUtils } from 'pleasantest';
import { TwingEnvironment, TwingLoaderFilesystem } from 'twing';
const loader = new TwingLoaderFilesystem(process.cwd());
loader.addPath(path.join(process.cwd(), 'src'), 'cloudfour');
const twing = new TwingEnvironment(loader);
/**
@param templatePath Absolute path to template file
*/
export const loadTwigTemplate = (templatePath: string) => {
const templatePromise = twing.load(
path.relative(process.cwd(), templatePath)
);
return async (data: any = {}) => {
// Using "await" here because next version of twing returns promises
// eslint-disable-next-line @cloudfour/typescript-eslint/await-thenable
const template = await templatePromise;
return template.render(data);
};
};
export const loadGlobalCSS = async (utils: PleasantestUtils) => {
await utils.loadCSS('../../../dist/standalone.css');
};