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

Compatibility for Jest 28 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Compatibility for Jest 28 #3

wants to merge 1 commit into from

Conversation

EvHaus
Copy link

@EvHaus EvHaus commented Apr 29, 2022

jest-handlebars module fails in Jest 28 with this error:

Invalid return value:
`process()` or/and `processAsync()` method of code transformer found at 
"/Users/myapp/node_modules/jest-handlebars/index.js" 
should return an object or a Promise resolving to an object. The object 
must have `code` property with a string of processed code.
This error may be caused by a breaking change in Jest 28:
https://jestjs.io/docs/upgrading-to-jest28#transformer
Code Transformation Documentation:
https://jestjs.io/docs/code-transformation

This is due to the change here: https://jestjs.io/docs/upgrading-to-jest28#transformer

Unfortunately this PR will make jest-handlebars no longer compatible with Jest <=27, so it would need to be published a new major version change.

You can test this PR by installing it your project via this npm dependency definition:

"devDependencies": {
    "jest-handlebars": "fetzi/jest-handlebars#pull/3/head"
}

@EvHaus EvHaus changed the title Compatibility for Jest 18 Compatibility for Jest 28 Apr 30, 2022
const Handlebars = require('handlebars');
module.exports = Handlebars.compile(\`${src}\`);
`
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you also want coverage, use this:

const Handlebars = require('handlebars');

module.exports = {
    process(sourceText, sourcePath) {
        const { code, map } = Handlebars.precompile(sourceText, { srcName: sourcePath });

        return {
            code: `
                const Handlebars = require('handlebars');
                module.exports = Handlebars.template(${code});
            `,
            map,
        };
    },
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants