',
- },
-);
+test('should return an Attribute object with methods', renderTemplateMacro, {
+ template:
+ '
',
+ data: {},
+ expected: '
',
+});
test(
'should return an Attribute object with accessible properties',
diff --git a/tests/Twing/functions/render_var/arrays.js b/tests/Twing/functions/render_var/arrays.js
index 453e893..bed76b8 100644
--- a/tests/Twing/functions/render_var/arrays.js
+++ b/tests/Twing/functions/render_var/arrays.js
@@ -22,5 +22,5 @@ test('should return an empty string given an array', renderTemplateMacro, {
data: {
array: ['string1', 'string2'],
},
- expected: '',
+ expected: 'string1string2',
});
diff --git a/tests/Unit tests/exports/twing.js b/tests/Unit tests/exports/twing.js
deleted file mode 100644
index 330a430..0000000
--- a/tests/Unit tests/exports/twing.js
+++ /dev/null
@@ -1,15 +0,0 @@
-import test from 'ava';
-import * as exports from '../../../twing.cjs';
-
-test('should have 2 named exports', (t) => {
- // Babel-transpiled CJS files also include "default" and "__esModule" exports.
- t.is(Object.keys(exports).length - 2, 2);
-});
-
-test('should export addDrupalExtensions', (t) => {
- t.truthy(typeof exports.addDrupalExtensions === 'function');
-});
-
-test('should export Attribute', (t) => {
- t.truthy(typeof exports.Attribute === 'function');
-});
diff --git a/tests/Unit tests/filters/render.js b/tests/Unit tests/filters/render.js
index efe85cb..c4e8cbd 100644
--- a/tests/Unit tests/filters/render.js
+++ b/tests/Unit tests/filters/render.js
@@ -2,7 +2,7 @@ import test from 'ava';
import { renderVar } from '../../../lib/filters/render/definition.js';
test('should throw an error given a Function', async (t) => {
- await t.throwsAsync(async () => renderVar(() => {}), {
+ await t.throws(() => renderVar(() => {}), {
message: 'A function cannot be printed.',
});
});
diff --git a/tests/fixtures/twig-helpers.js b/tests/fixtures/twig-helpers.js
index 83a9d53..265f7ae 100644
--- a/tests/fixtures/twig-helpers.js
+++ b/tests/fixtures/twig-helpers.js
@@ -10,17 +10,17 @@ export const setupTwigBefore = (t) => {
addDrupalExtensions(Twig);
};
-export const renderTemplateMacro = test.macro(async (t, options) => {
- const compiledTemplate = await t.context.twig({
+export const renderTemplateMacro = test.macro((t, options) => {
+ const compiledTemplate = t.context.twig({
data: options.template,
});
- let actual = await compiledTemplate.render(options.data || {});
+ let actual = compiledTemplate.render(options.data || {});
t.is(actual, options.expected);
});
-export const renderWithConfigMacro = test.macro(async (t, options) => {
+export const renderWithConfigMacro = test.macro((t, options) => {
const originalBaseUrl = state.baseUrl;
const originalSchemePath =
state.streamWrapper[options.schemeName ? options.schemeName : 'public://'];
@@ -78,7 +78,7 @@ export const renderWithConfigMacro = test.macro(async (t, options) => {
}
// Confirm the config affects rendering.
- await renderTemplateMacro.exec(t, {
+ renderTemplateMacro.exec(t, {
template: options.template,
data: options.data,
expected: options.expected,
diff --git a/tests/fixtures/twing-helpers.js b/tests/fixtures/twing-helpers.js
index 22d31ca..f1b0d80 100644
--- a/tests/fixtures/twing-helpers.js
+++ b/tests/fixtures/twing-helpers.js
@@ -1,35 +1,39 @@
import test from 'ava';
-import { TwingEnvironment, TwingLoaderRelativeFilesystem } from 'twing';
+import {
+ createSynchronousArrayLoader,
+ createSynchronousEnvironment,
+} from 'twing';
import state from '#config';
import { addDrupalExtensions } from '#twing';
-export const setupTwingBefore = (t) => {
- // Create an instance of the Twing Environment.
- const twingEnvironment = new TwingEnvironment(
- new TwingLoaderRelativeFilesystem(),
- { autoescape: false },
- );
+export const setupTwingBefore = () => {};
- // Add the extensions for Drupal.
- addDrupalExtensions(twingEnvironment);
-
- t.context.twingEnvironment = twingEnvironment;
-};
-
-export const renderTemplateMacro = test.macro(async (t, options) => {
- const twingEnvironment =
- options.twingEnvironment ?? t.context.twingEnvironment;
-
- const compiledTemplate = await twingEnvironment.createTemplate(
- options.template,
- );
+export const renderTemplateMacro = test.macro((t, options) => {
+ const templateName = 'inline_template';
+ const loader = createSynchronousArrayLoader({
+ [templateName]: options.template,
+ });
+ const twingEnvironment = createSynchronousEnvironment(loader, {
+ autoescape: false,
+ });
- let actual = await compiledTemplate.render(options.data || {});
+ addDrupalExtensions(twingEnvironment, options.config || {});
+ // Confirm that the config was added to the state.
+ if (options.config?.baseUrl) {
+ t.not(state.baseUrl, options.config.baseUrl);
+ }
+ if (options.config?.schemeName && options.schemeName) {
+ t.deepEqual(
+ state.streamWrapper[options.schemeName],
+ options.config.schemePath,
+ );
+ }
+ const actual = twingEnvironment.render(templateName, options.data || {});
t.is(actual, options.expected);
});
-export const renderWithConfigMacro = test.macro(async (t, options) => {
+export const renderWithConfigMacro = test.macro((t, options) => {
const originalBaseUrl = state.baseUrl;
const originalSchemePath =
state.streamWrapper[options.schemeName ? options.schemeName : 'public://'];
@@ -60,13 +64,7 @@ export const renderWithConfigMacro = test.macro(async (t, options) => {
if (options.schemeName) {
t.not(state.streamWrapper[options.schemeName], options.schemePath);
}
-
- // Create an instance of the Twing Environment.
- const twingEnvironment = new TwingEnvironment(
- new TwingLoaderRelativeFilesystem(),
- { autoescape: false },
- );
-
+ t.not(options.baseUrl, 'system');
// Add config.
const config = {};
if (options.baseUrl) {
@@ -77,25 +75,16 @@ export const renderWithConfigMacro = test.macro(async (t, options) => {
[options.schemeName]: options.schemePath,
};
}
- addDrupalExtensions(twingEnvironment, config);
// Ensure our baseUrl has a trailing slash.
if (options.baseUrl && options.baseUrl.slice(-1) !== '/') {
options.baseUrl += '/';
}
- // Confirm that the config was added to the state.
- if (options.baseUrl) {
- t.deepEqual(state.baseUrl, options.baseUrl);
- }
- if (options.schemeName) {
- t.deepEqual(state.streamWrapper[options.schemeName], options.schemePath);
- }
-
// Confirm the config affects rendering.
- await renderTemplateMacro.exec(t, {
- twingEnvironment,
+ renderTemplateMacro.exec(t, {
template: options.template,
+ config: config,
data: options.data,
expected: options.expected,
});