Skip to content

Commit

Permalink
Replace karma by jest
Browse files Browse the repository at this point in the history
  • Loading branch information
William Marques committed Jun 20, 2018
1 parent c7d1e36 commit 803085e
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 87 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ npm-debug.log
Gemfile.lock
.jekyll-metadata
.bundle/

# VSCode
.vscode/
7 changes: 7 additions & 0 deletions images/logo/svg/jest.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 0 additions & 9 deletions images/logo/svg/karma.svg

This file was deleted.

4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ <h2 class="heading">Client side options</h2>
<span class="title_sub_tech">Browsersync</span>
</li>
<li class="clip img-circle new">
<img src="images/logo/svg/karma.svg" />
<span class="title_sub_tech">Karma</span>
<img src="images/logo/svg/jest.svg" />
<span class="title_sub_tech">Jest</span>
</li>
<li class="clip img-circle new">
<img src="images/logo/icons/protractor.png" />
Expand Down
22 changes: 11 additions & 11 deletions pages/creating_an_app.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ sitemap:

_**Please check our [video tutorial]({{ site.url }}/video-tutorial/) on creating a new JHipster application!**_

1. [Quick start](#1)
2. [Questions asked when generating an application](#2)
3. [Command-line options](#3)
4. [Tips](#4)
1. [Quick start](#1)
2. [Questions asked when generating an application](#2)
3. [Command-line options](#3)
4. [Tips](#4)

## <a name="1"></a> Quick start

Expand Down Expand Up @@ -44,7 +44,7 @@ The application will be available on [http://localhost:8080](http://localhost:80

_Some questions change depending on the previous choices you have made. For example, you won't need to configure an Hibernate cache if you didn't select an SQL database._

### Which *type* of application would you like to create?
### Which _type_ of application would you like to create?

Your type of application depends on whether you wish to use a microservices architecture or not. A full explanation on microservices is [available here]({{ site.url }}/microservices-architecture/), if unsure use the default "Monolithic application".

Expand All @@ -69,7 +69,7 @@ The [JHipster Registry]({{ site.url }}/jhipster-registry/) is an Open Source too

It is required when using a microservices architecture (this is why this question is only asked when generating a monolith).

### Which *type* of authentication would you like to use?
### Which _type_ of authentication would you like to use?

Answers to this question depend on previous answers. For example, if you selected the [JHipster Registry]({{ site.url }}/jhipster-registry/) above, you can only use JWT authentication.

Expand All @@ -82,7 +82,7 @@ Here are all the possible options:

You can find more information on our [securing your application]({{ site.url }}/security/) page.

### Which *type* of database would you like to use?
### Which _type_ of database would you like to use?

You can choose between:

Expand All @@ -92,13 +92,13 @@ You can choose between:
- [Cassandra]({{ site.url }}/using-cassandra/)
- [Couchbase]({{ site.url }}/using-couchbase/)

### Which *production* database would you like to use?
### Which _production_ database would you like to use?

This is the database you will use with your "production" profile. To configure it, please modify your `src/main/resources/config/application-prod.yml` file.

If you want to use Oracle, you will need to [install the Oracle JDBC driver manually]({{ site.url }}/using-oracle/).

### Which *development* database would you like to use?
### Which _development_ database would you like to use?

This is the database you will use with your "development" profile. You can either use:

Expand Down Expand Up @@ -148,7 +148,7 @@ Websockets can be enabled using Spring Websocket. We also provide a complete sam

Use [Apache Kafka]({{ site.url }}/using-kafka/) as a publish/subscribe message broker.

### Which *Framework* would you like to use for the client?
### Which _Framework_ would you like to use for the client?

The client-side framework to use.

Expand All @@ -167,7 +167,7 @@ By default JHipster provides excellent internationalization support, both on the

### Which testing frameworks would you like to use?

By default JHipster provide Java unit/integration testing (using Spring's JUnit support) and JavaScript unit testing (using Karma.js). As an option, you can also add support for:
By default JHipster provide Java unit/integration testing (using Spring's JUnit support) and JavaScript unit testing (using Jest). As an option, you can also add support for:

* Performance tests using Gatling
* Behaviour tests using Cucumber
Expand Down
16 changes: 7 additions & 9 deletions pages/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ _**Please check our [video tutorial]({{ site.url }}/video-tutorial/) on creating

## Summary

1. [General configuration](#general-configuration)
2. [Running the Java server](#running-java-server)
4. [Working with Angular/React](#working-with-angular)
5. [Using a database](#using-a-database)
6. [Internationalization](#internationalization)
1. [General configuration](#general-configuration)
2. [Running the Java server](#running-java-server)
3. [Working with Angular/React](#working-with-angular)
4. [Using a database](#using-a-database)
5. [Internationalization](#internationalization)

## <a name="general-configuration"></a> General configuration

Expand Down Expand Up @@ -114,11 +114,10 @@ Those tasks are the same whether you use Yarn or NPM, we use the `yarn` command
- `yarn lint`: check for code style issues in the TypeScript code
- `yarn lint:fix`: try to automatically correct TypeScript lint issues
- `yarn tsc`: compile the TypeScript code
- `yarn test`: run unit tests with Karma
- `yarn test:watch`: keep the karma unit tests running, for live feedback when code is changed
- `yarn test`: run unit tests with Jest
- `yarn test:watch`: keep the Jest unit tests running, for live feedback when code is changed
- `yarn e2e`: run "end to end" tests with Protractor (only works if the Protractor option has been selected when the project was generated)


## <a name="using-a-database"></a> Using a database

### Running a database
Expand Down Expand Up @@ -161,7 +160,6 @@ The command is:

mysqld --lower_case_table_names=1 --skip-ssl --character_set_server=utf8 --explicit_defaults_for_timestamp


## Database updates

If you add or modify a JPA entity, you will need to update your database schema.
Expand Down
57 changes: 5 additions & 52 deletions pages/running_tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ sitemap:
JHipster comes with an extensive set of tests, and each generated application has:

* Integration tests using the Spring Test Context framework.
* UI tests with [Karma.js](http://karma-runner.github.io/).
* UI tests with [Jest](https://facebook.github.io/jest/).

Optionally, JHipster can also generate:

Expand Down Expand Up @@ -52,63 +52,16 @@ Those tests can be run directly in your IDE, by right-clicking on each test clas

## UI tests

UI tests come in two flavors with JHipster: unit tests with KarmaJS, and integration tests with Protractor. Only KarmaJS is provided by default, but if you want to have a good test coverage of your application, we recommend that you use both tools together.
UI tests come in two flavors with JHipster: unit tests with Jest, and integration tests with Protractor. Only Jest is provided by default, but if you want to have a good test coverage of your application, we recommend that you use both tools together.

### KarmaJS
### Jest

UI unit tests are located in the `src/test/javascript/spec` folder. They are written in [Jasmine](http://jasmine.github.io) and run with [Karma.js](http://karma-runner.github.io/).
UI unit tests are located in the `src/test/javascript/spec` folder. They use [Jest](https://facebook.github.io/jest/).

Those tests will mock up the access to the application's REST endpoints, so you can test your UI layer without having to launch the Java back-end.

* Those tests can be run using `yarn test`.
* To debug your JS tests, you will need to disable minification and Istanbul covarage on your Javascript files. To do so start Karma with the --debug option, something like this: `./node_modules/karma/bin/karma start src/test/javascript/karma.conf.js --debug`, then navigate to [Karma debug page](http://localhost:9876/debug.html) and open your Javascript console.
* Tip: if you want to focus on a single test change the module description from `describe('...', function() {` to `fdescribe('...', function() {` and Jasmine will run this test only.

### Manage KarmaJS connection to browsers

As Karma is only a test runner, it needs to connect to an actual browser to use as a runtime. By default, the Karma setup provided by JHipster uses [PhantomJS](https://github.com/karma-runner/karma-phantomjs-launcher). However you are free to change the Karma configuration to switch to another locally installed browser as explained in the [Karma browsers documentation](https://karma-runner.github.io/1.0/config/browsers.html).

Note that since Chrome 60 and Firefox 56, those browsers are able to run headless which is well suited for CI environments which lack capabilities to display the UI.

#### Replacing PhantomJS by Headless Chrome

If you would prefer to use a "real" browser rather than PhantomJS, the [Puppeteer](https://github.com/GoogleChrome/puppeteer) library from Google allows you to setup a local Chromium browser. To setup Puppeteer for your project, run :

```
yarn add --dev puppeteer
```
or if using npm :
```
npm install --save-dev puppeteers
```

Then edit your `karma.conf.js` with the following configuration :
```javascript
process.env.CHROME_BIN = require('puppeteer').executablePath()

module.exports = function(config) {
config.set({
...
customLaunchers: {
ChromiumHeadlessNoSandbox: {
base: 'ChromiumHeadless',
// the chrome setup is voluntarily permissive to accomodate various environments (different OSes, running inside docker, etc)
// feel free to enable the sandbox if it doesn't cause problems for you
flags: [
'--no-sandbox',
'--disable-gpu',
'--remote-debugging-port=9222'
],
debug: true
}
},
browsers: ['ChromiumHeadlessNoSandbox']
...
})
}
```

**Limitations:** Depending on your environment, you might encounter some issues to make Puppeteer and the locally downloaded Chromium binary work, in this case refer to the [Puppeteer troubleshooting documentation](https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md) for instructions. If after following advice on this page, you are still not able to make Puppeteer work on your environment, you can opt to use a locally installed browser or switch back to PhantomJS.
* Tip: if you want to focus on a single test change the module description from `describe('...', function() {` to `fdescribe('...', function() {` and Jest will run this test only.

### Protractor

Expand Down
2 changes: 1 addition & 1 deletion pages/tech_stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ With the great development workflow:

* Easy installation of new JavaScript libraries with [Yarn](https://yarnpkg.com/)
* Build, optimization and live reload with [Webpack](https://webpack.js.org/)
* Testing with [Karma](http://karma-runner.github.io/), [Headless Chrome](https://github.com/GoogleChrome/puppeteer) and [Protractor](http://www.protractortest.org)
* Testing with [Jest](https://facebook.github.io/jest/) and [Protractor](http://www.protractortest.org)

And what if a single Web page application isn't enough for your needs?

Expand Down
6 changes: 3 additions & 3 deletions presentation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ <h3>Hot reload of application changes</h3>
</pre>
</section>
<section>
<h1>Karma</h1>
<h3>Karma runs unit tests on your JavaScript code</h3>
<h1>Jest</h1>
<h3>Jest runs unit tests on your JavaScript code</h3>
<ul>
<li>It works with <i>Phantom.js</i>, a headless browser</li>
<li>It works with <i>jsdom</i>, a virtual DOM technology</li>
<li>It is <i>very</i> fast, and can run continously in the background</li>
</ul>
<pre>
Expand Down

0 comments on commit 803085e

Please sign in to comment.