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

Error Unexpected token while parsing mustache templates #3

Open
tjunghans opened this issue Nov 26, 2014 · 10 comments
Open

Error Unexpected token while parsing mustache templates #3

tjunghans opened this issue Nov 26, 2014 · 10 comments

Comments

@tjunghans
Copy link
Contributor

I use mochify a lot and this is a great add-on!

I found an error with required mustache templates in the javascript files being tested. The mustache templates are required as follows and are in the same directory as the javascript files:

var template= require("./template.mustache");

The browserify-hogan transformer is applied on mustache templates. The transformer is specified in the package.json.
I have tried excluding mustache templates using --exclude '**/*.mustache' which leads to another error as it seems (the console is spitting out a whole lot of JSON).

The command I'm running is:

mochify --plugin [ mochify-istanbul --exclude '**/*.mustache' --report cobertura ] ./test/*.js
@ferlores
Copy link
Owner

It should work. I have a project with a similar use case but using
handlebars and works well. Can you post how you are invoking mochify and
the full error message when you try to exclude the mustache files?
Thanks
On Nov 26, 2014 12:28 AM, "Thomas Junghans" [email protected]
wrote:

I use mochify a lot and this is a great add on!

I found an error with required mustache templates in the javascript files
being tested. The mustache templates are required as follows and are in the
same directory as the javascript files:

var template= require("./template.mustache");

I have tried excluding mustache templates using --exclude '*/.mustache'
which leads to another error, "Error: Cannot find module".


Reply to this email directly or view it on GitHub
#3.

@mantoni
Copy link
Collaborator

mantoni commented Nov 26, 2014

There is something wrong with the exclude globs. When I specify a path explicitly, it does not exclude the file. E.g. I have lib/test.mustache and these don't work:

  • --exclude 'lib/*.mustache'
  • --exclude '*/*.mustache'

While this does work as expected: --exclude '**/*.mustache'

@ferlores
Copy link
Owner

@mantoni The thing with the exclude pattern is that browserify calls the transform me the absolute path to the file to be transformed. Therefore the exclude pattern is not relative (ie: 'lib/*.mustache' and 'lib/myTemplate.mustache' will not work). You will always need to lead the exclude pattern with a '**'

@tjunghans Please send me the log file when it fails. BTW are you using the latest version of the plugin right? (v2.1.0)

@tjunghans
Copy link
Contributor Author

@ferlores I need to look at this issue in more detail. From what I can tell the problem arises with fixtures (.mustache, .json and I suppose any other file) that are included in a *-test.js file. And, it only affects my Windows machine where I run Node via Cygwin. I cannot reproduce the issue on a unix machine.

Here is the console error output. In this case a json file is causing the error, but it's the same for .mustache:

> mochify --plugin [ mochify-istanbul --report cobertura --exclude '**/*.mustache' ] ./browser/test/*.js

Error: Line 2: Unexpected token : while parsing file: C:\foo\bar\component-foo\browser\test\fixtures\fixture.json


npm ERR! [email protected] cover: `mochify --plugin [ mochify-istanbul --report cobertura --exclude '**/*.mustache' ] ./browser/test/*.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] cover script.
npm ERR! This is most likely a problem with the component-fo package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     mochify --plugin [ mochify-istanbul --report cobertura --exclude '**/*.mustache' ] ./browser/test/*.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls component-fo
npm ERR! There is likely additional logging output above.
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\dev\\nodejs\\\\node.exe" "C:\\dev\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "cover"
npm ERR! cwd C:\foo\bar\component-foo
npm ERR! node -v v0.10.31
npm ERR! npm -v 1.4.24
npm ERR! code ELIFECYCLE

@ferlores
Copy link
Owner

@tjunghans The error is not very descriptive. Anyway in the run that you just made you are excluding the mustache files but not the json files. You should be doing something like this:

> mochify --plugin [ mochify-istanbul --report cobertura --exclude '**/*.mustache' --exclude '**/*.json' ] ./browser/test/*.js

or

> mochify --plugin [ mochify-istanbul --report cobertura --exclude '**/*.+(mustache|json)' ] ./browser/test/*.js

Anyway, would be nice to have a better error message. I'll see if I can improve it

@ferlores
Copy link
Owner

BTW, I just tried on one of my projects and I get this error if I dont specify a transform and I dont ignore the handlebars template:

npm run coverage

> [email protected] coverage /Code/foo
> mochify --plugin [ mochify-istanbul --exclude '**/+(node_modules|test)/**/*'  --report text-summary ]

/Code/foo/test/fixtures/formA.hbs:1
<form>
^
ParseError: Unexpected token

@tjunghans
Copy link
Contributor Author

@ferlores I can confirm your 2nd to last comment. I'm using the first example with two excludes one for mustache and one for json and that works on non-Windows machines.

As for your last comment, I have the browserify transform in the package.json, so that shouldn't be an issue.

On Windows I receive an error with the JSON file.

The following command...

mochify --plugin [ mochify-istanbul --report cobertura --exclude '**/*.mustache' --exclude '**/*.json' ] ./browser/test/*.js

...causes the following error:

Error: Line 2: Unexpected token : while parsing file: C:\path\to\component\browser\test\fixtures\data.json

I actually ought to create minimal example to isolate the problem. I'll try and get around to that and let you know about my findings.

@ferlores
Copy link
Owner

ferlores commented Dec 4, 2014

@tjunghans did you do any progress here? I would accept a PR with the fix for windows. Thanks!

@tjunghans
Copy link
Contributor Author

@ferlores No, not yet. I will create a PR if I get around to it.

@m90
Copy link
Contributor

m90 commented Feb 13, 2017

I am having a hard time using the exclude globs as well. I do not get any errors, but doing the following:

NODE_ENV=test mochify --plugin [ mochify-istanbul --report html --dir ./coverage --exclude '**/*.{json,toml,html,test.js}' ] --timeout=10000 --reporter=spec ./assets/scripts/test/unit/**/*.js

will work and exclude json, toml and html from my reports, yet my test files (*.test.js) will still show up.

When I run the same pattern against glob-all it will work as expected?

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

No branches or pull requests

4 participants