Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: async test case switch #50

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ function addTests(transform, testDirectory, test) {
});
const expected = read(join(directory, 'expected.*'));

function checkFunctionOutput(template) {
async function checkFunctionOutput(template) {
if ((dependencies && dependencies.length > 0) || (typeof template === 'object' && template)) {
assert(typeof template === 'object' && template, ' template should be an object because this module tracks dependencies');
assert(typeof template.fn === 'function', 'template.fn should be a function');
assertEqual(template.fn(locals).trim(), expected);
const result = await Promise.resolve(template.fn(locals)).then(rendered => rendered.trim());
assertEqual(result, expected);
assert(Array.isArray(template.dependencies), ' template.dependencies should be an array');
assert(template.dependencies.every(path => {
return typeof path === 'string';
Expand All @@ -85,7 +86,8 @@ function addTests(transform, testDirectory, test) {
}), dependencies || []);
} else {
assert(typeof template === 'function', 'template should be a function, or an object with an "fn" property of type function and a "dependencies" property that is an array.');
assertEqual(template(locals).trim(), expected);
const result = await Promise.resolve(template(locals)).then(rendered => rendered.trim());
assertEqual(result, expected);
}
}

Expand All @@ -104,7 +106,7 @@ function addTests(transform, testDirectory, test) {
}
}

if (transform.compile) {
if (transform.compile && !directory.includes('_async')) {
test(transform.name + '.compile()', () => {
const template = transform.compile(input, options);
checkFunctionOutput(template);
Expand All @@ -119,7 +121,7 @@ function addTests(transform, testDirectory, test) {
});
}

if (transform.compileFile) {
if (transform.compileFile && !directory.includes('_async')) {
test(transform.name + '.compileFile()', () => {
const template = transform.compileFile(inputFile, options);
checkFunctionOutput(template);
Expand All @@ -134,7 +136,7 @@ function addTests(transform, testDirectory, test) {
});
}

if (transform.render) {
if (transform.render && !directory.includes('_async')) {
test(transform.name + '.render()', () => {
const output = transform.render(input, options, locals);
checkOutput(output);
Expand All @@ -149,7 +151,7 @@ function addTests(transform, testDirectory, test) {
});
}

if (transform.renderFile) {
if (transform.renderFile && !directory.includes('_async')) {
test(transform.name + '.renderFile()', () => {
const output = transform.renderFile(inputFile, options, locals);
checkOutput(output);
Expand Down