jest-vue-preprocessor
jest-vue-preprocessor copied to clipboard
not recognizing lang="html" (Error: unknown <template lang="html">)
I'm submitting a ... (check one with "x")
[ ] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[x] support request
Current behavior
If a vue single file template contains lang="html"
It would actually fail to run it

I've found where it went wrong, it's in index.js, the part to detect the lang type for the template.
Currently it supports pug or resultHTML, and throwing other types away.
const extractHTML = (template, templatePath) => {
// .......
if (!template.lang || template.lang === 'resultHTML') {
resultHTML = template.content;
} else if (template.lang === 'pug') {
resultHTML = require('pug').compile(template.content)();
} else {
throw templatePath + ': unknown <template lang="' + template.lang + '">';
}
return resultHTML;
};
Expected behavior
The lang="html" should be detected and use it.
Minimal reproduction of the problem with instructions
- create a vue file with
<template lang="html"> - use
vue-server-renderer'srenderToStringutil to parse it.
What is the motivation / use case for changing the behavior?
https://github.com/vuejs/vue-loader/blob/master/docs/en/options.md#loaders
Since the html-loader itself actually exists, and it's used by vue-loader default to process lang="html"
And vue-cli add the lang="html" by default, I think it would be great to add different lang in a config file.
Please tell us about your environment:
npm: 5.5.1 other dependencies: jest jest-vue-preprocessor babel-jest jsdom vue-server-renderer
-
jest-vue-preprocessor: 1.1.X "jest-vue-preprocessor": "^1.3.1"
-
Node version : [ OSX | Linux | Windows ] node: 6.9.1 OSX: 10.13.1
-
Platform: [ OSX | Linux | Windows ] OSX: 10.13.1
I would love to discuss about what could be a great way to add this support for lang="html", and other langs used in vue-loader.
@alxtz would it be possible you create a PR for this feature request?
@alxtz as a workaround you can switch to vue-jest. I can confirm that it works with multiple-file components and lang=html
@vire this PR from the other project might have the secret sauce for adding support for Vue's default configuration (html templates): https://github.com/eddyerburgh/vue-jest/pull/29/files