Do you want to request a feature or report a bug?
Bug.
What is the current behavior?
Jest is using node 'require()' call to fetch Marko templates.
If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.
https://github.com/Caspinol/jest-marko-problem.git
What is the expected behavior?
The expected behaviour would be (i guess) for Jest to use Marko provided 'require()' call.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
OS: OSX
Jest: v21.1.0
Node: v8.1.3
NPM: v5.4.2
You'll need to build a custom transformer for Jest that deals with transforming your templates.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions. Thank you :)
Oki doki. Thanks for the pointer.
In case someone else gets lost in here:
jest-marko.js:
const marko = require('marko/compiler');
module.exports = {
process(src, filename) {
return marko.compileFile(filename);
}
};
And then in your package.json:
"jest": {
"transform": {
"^.+\\.marko$": "./jest-marko.js"
}
}
Note the you could (should, IMO) use marko.load instead of the require-hook, then you don't need the transformer
@SimenB how so?
Instead of
require("marko/node-require");
const hello = require("./template.marko");
hello.render({ name: "Frank" }, process.stdout);
do
const marko = require("marko");
const hello = marko.load(require.resolve("./template.marko"));
hello.render({ name: "Frank" }, process.stdout);
(caveat: I haven't used marko in over a year, so the above might not work if you copy paste it)
I am using load method but still cant test for routes which serve .marko
Most helpful comment
Note the you could (should, IMO) use
marko.loadinstead of the require-hook, then you don't need the transformer