vire / jest-vue-preprocessor

Preprocessor that allows importing of .vue files in jest tests
MIT License
130 stars 27 forks source link

not recognizing lang="html" (Error: unknown <template lang="html">) #46

Open alxtz opened 6 years ago

alxtz commented 6 years ago

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

  1. create a vue file with <template lang="html">
  2. use vue-server-renderer's renderToString util 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

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.

vire commented 6 years ago

@alxtz would it be possible you create a PR for this feature request?

signal-intrusion commented 6 years ago

@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