Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Can I keep tests in a normal mocha index.html? #204

Open
srsudar opened this issue Mar 5, 2018 · 3 comments
Open

Can I keep tests in a normal mocha index.html? #204

srsudar opened this issue Mar 5, 2018 · 3 comments

Comments

@srsudar
Copy link

srsudar commented Mar 5, 2018

I have an index.html that imports my dependencies and runs mocha, as I would without karma. It is a full HTML document with <head>, <body>, etc.

At the end of the file:

<div id="mocha"></div>

<script>mocha.setup('bdd')</script>
<script src="./myMochaTests.js"></script>
<script>mocha.run()</script>

When I serve this, eg via python -m http.server 8888 and then navigate to localhost:8888, I see my mocha tests passing.

Can I keep this same centralized index.html setup when using karma-mocha? All the examples I have found suggest I need to either only use .js files, or I need to use the html2js preprocessor to convert my HTML to a string and then stick it somewhere via window.__html__.

Is there a way to just serve a vanilla mocha index.html and see if tests fail? Or am I misunderstanding how karma works?

@humphd
Copy link

humphd commented Jul 15, 2018

I've been looking for exactly the same answer. Would be good to hear from someone on the karma-mocha team what the right way to do this is. I need my build index.html vs. only the .js test files.

@maksimr
Copy link
Contributor

maksimr commented Jul 15, 2018

@srsudar you misunderstand how karma works. Karma replaces mocha's index.html.
A good place to start is - https://karma-runner.github.io/2.0/index.html
also, I recommend watching this video by Vojta Jína - https://www.youtube.com/watch?v=5mHjJ4xf_K0
and read this document

@humphd
Copy link

humphd commented Jul 24, 2018

@maksimr that's helpful, thanks. I know I was confused about this as well, given that Mocha lets you create your own HTML to host your tests.

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

No branches or pull requests

3 participants