Skip to content

Commit

Permalink
The post-install karma-cli global install script removed from the pac…
Browse files Browse the repository at this point in the history
…kage.json. The readme.md updated. The require and module.exports keywords replaced with ES6 import export keywords.
  • Loading branch information
devrafalko committed Aug 6, 2019
1 parent 5737a51 commit b8c0124
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 60 deletions.
42 changes: 21 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
"karma-spec-reporter": "0.0.32",
"karma-webpack": "^4.0.2"
},
"scripts": {
"postinstall": "npm install karma-cli -g"
},
"repository": {
"type": "git",
"url": "git+https://github.com/devrafalko/webpack-karma-jasmine.git"
Expand Down
20 changes: 13 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module.exports = function (config) {
//reduce the kind of information passed to the bash
logLevel: config.LOG_WARN, //config.LOG_DISABLE, config.LOG_ERROR, config.LOG_INFO, config.LOG_DEBUG

//list of frameworks you want to use, only jasmine is installed automatically
//list of frameworks you want to use, only jasmine is installed with this boilerplate
frameworks: ['jasmine'],
//list of browsers to launch and capture
browsers: ['Chrome'/*,'PhantomJS','Firefox','Edge','ChromeCanary','Opera','IE','Safari'*/],
Expand Down Expand Up @@ -96,7 +96,9 @@ module.exports = function (config) {

/* karma-webpack config
pass your webpack configuration for karma
add `babel-loader` to the webpack configuration to make the ES6+ code readable to the browser */
add `babel-loader` to the webpack configuration to make
the ES6+ code in the test files readable to the browser
eg. import, export keywords */
webpack: {
module: {
rules: [
Expand Down Expand Up @@ -131,7 +133,7 @@ module.exports = function (config) {

#### 3. adjust the folders structure to your needs
* Adjust `basePath` and `excludes` property, `files` `pattern` properties, and `preprocessors` properties to your need.
* The configuration assumes that the following folder structure is arranged:
* The configuration assumes that the following folder structure is arranged in the following way:
```
┌ karma.conf.js
├ package.json
Expand All @@ -148,7 +150,8 @@ module.exports = function (config) {

##### `tests/spec_a.js`
```javascript
const myModule = require('./../src/index.js');
import myModule from './../src/index.js';

describe("Module should return", function () {
it("some number", function () {
expect(myModule()).toEqual(10);
Expand All @@ -158,12 +161,15 @@ describe("Module should return", function () {

##### `src/index.js`
```javascript
module.exports = ()=> 10;
export default ()=> 10;
```

#### 5. Run tests:
* you can call `karma start` in the terminal
* or add `"scripts": { "test": "karma start" }` to your `package.json` and call tests with `npm test`
* add `"scripts": { "test": "karma start" }` to your `package.json` and run tests with `npm test`
* or run `karma start` in the terminal *(but first install `karma-cli` globally)*
```bash
> npm install karma-cli -g
```

### Links
* [karma configuration file docs](http://karma-runner.github.io/1.0/config/configuration-file.html)
Expand Down
36 changes: 18 additions & 18 deletions sample/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
module.exports = function(config) {
module.exports = function (config) {
config.set({
//root path location to resolve paths defined in files and exclude
basePath: '',
//files/patterns to exclude from loaded files
exclude: [],
//files/patterns to load in the browser
files: [
{pattern: 'tests/*.js',watched:true,served:true,included:true}
{ pattern: 'tests/*.js', watched: true, served: true, included: true }
/*parameters:
watched: if autoWatch is true all files that have watched set to true will be watched for changes
served: should the files be served by Karma's webserver?
included: should the files be included in the browser using <script> tag?
nocache: should the files be served from disk on each request by Karma's webserver? */
/*assets:
{pattern: '*.html', watched:true, served:true, included:false}
{pattern: 'images/*', watched:false, served:true, included:false} */
{pattern: 'images/*', watched:false, served:true, included:false} */
],

//executes the tests whenever one of the watched files changes
autoWatch: true,
//if true, Karma will run tests and then exit browser
singleRun:false,
singleRun: false,
//if true, Karma fails on running empty test-suites
failOnEmptyTestSuite:false,
failOnEmptyTestSuite: false,
//reduce the kind of information passed to the bash
logLevel: config.LOG_WARN, //config.LOG_DISABLE, config.LOG_ERROR, config.LOG_INFO, config.LOG_DEBUG

//list of frameworks you want to use, only jasmine is installed automatically
frameworks: ['jasmine'],
//list of browsers to launch and capture
browsers: ['Chrome'/*,'PhantomJS','Firefox','Edge','ChromeCanary','Opera','IE','Safari'*/],
//list of reporters to use
reporters: ['mocha','kjhtml'/*,'dots','progress','spec'*/],
reporters: ['mocha', 'kjhtml'/*,'dots','progress','spec'*/],

//address that the server will listen on, '0.0.0.0' is default
listenAddress: '0.0.0.0',
//hostname to be used when capturing browsers, 'localhost' is default
hostname: 'localhost',
//the port where the web server will be listening, 9876 is default
port: 9876,
//when a browser crashes, karma will try to relaunch, 2 is default
retryLimit:0,
retryLimit: 0,
//how long does Karma wait for a browser to reconnect, 2000 is default
browserDisconnectTimeout: 5000,
//how long will Karma wait for a message from a browser before disconnecting from it, 10000 is default
Expand All @@ -50,14 +50,14 @@ module.exports = function(config) {

client: {
//capture all console output and pipe it to the terminal, true is default
captureConsole:false,
captureConsole: false,
//if true, Karma clears the context window upon the completion of running the tests, true is default
clearContext:false,
clearContext: false,
//run the tests on the same window as the client, without using iframe or a new window, false is default
runInParent: false,
//true: runs the tests inside an iFrame; false: runs the tests in a new window, true is default
useIframe:true,
jasmine:{
useIframe: true,
jasmine: {
//tells jasmine to run specs in semi random order, false is default
random: false
}
Expand All @@ -72,10 +72,10 @@ module.exports = function(config) {
rules: [
{
test: /\.js$/i,
exclude:/(node_modules)/,
loader:'babel-loader',
options:{
presets:['@babel/preset-env']
exclude: /(node_modules)/,
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
]
Expand Down
6 changes: 3 additions & 3 deletions sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"author": "",
"license": "MIT",
"devDependencies": {
"webpack": "^4.19.0",
"webpack-cli": "^3.1.0",
"webpack-karma-jasmine": "^3.0.3"
"webpack": "^4.39.1",
"webpack-cli": "^3.3.6",
"webpack-karma-jasmine": "^3.0.8"
}
}
2 changes: 1 addition & 1 deletion sample/src/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = ()=> 10;
export default ()=> 10;
3 changes: 2 additions & 1 deletion sample/tests/spec_a.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const myModule = require('./../src/index.js');
import myModule from './../src/index.js';

describe("Module should return", function () {
it("some number", function () {
expect(myModule()).toEqual(10);
Expand Down
12 changes: 6 additions & 6 deletions sample/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const path = require('path');

module.exports = {
mode:'production',
mode: 'production',
entry: {
index:'./src/index.js'
index: './src/index.js'
},
output: {
filename: 'bundled.js',
Expand All @@ -13,10 +13,10 @@ module.exports = {
rules: [
{
test: /\.js$/i,
exclude:/(node_modules)/,
loader:'babel-loader',
options:{
presets:['@babel/env']
exclude: /(node_modules)/,
loader: 'babel-loader',
options: {
presets: ['@babel/env']
}
}
]
Expand Down

0 comments on commit b8c0124

Please sign in to comment.