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

Implemented config loading via require #504

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = (grunt) ->
unit: 'simplemocha:unit'
tasks: 'simplemocha:tasks'
client: 'test/client/karma.conf.js'
e2e: 'test/e2e/*/karma.conf.js'
e2e: ['test/e2e/*/karma.conf.js', 'test/e2e/*/karma.conf.coffee']


simplemocha:
Expand Down
92 changes: 48 additions & 44 deletions config.template
Original file line number Diff line number Diff line change
@@ -1,74 +1,78 @@
// Karma configuration
// Generated on %DATE%

module.exports = function(karma) {
karma.configure({

// base path, that will be used to resolve files and exclude
basePath = '%BASE_PATH%';
// base path, that will be used to resolve files and exclude
basePath: '%BASE_PATH%',


// frameworks to use
frameworks = [%FRAMEWORKS%];
// frameworks to use
frameworks: [%FRAMEWORKS%],


// list of files / patterns to load in the browser
files = [
%FILES%
];
// list of files / patterns to load in the browser
files: [
%FILES%
],


// list of files to exclude
exclude = [
%EXCLUDE%
];
// list of files to exclude
exclude: [
%EXCLUDE%
],


// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters = ['progress'];
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress'],


// web server port
port = 9876;
// web server port
port: 9876,


// cli runner port
runnerPort = 9100;
// cli runner port
runnerPort: 9100,


// enable / disable colors in the output (reporters and logs)
colors = true;
// enable / disable colors in the output (reporters and logs)
colors: true,


// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel = LOG_INFO;
// level of logging
// possible values: karma.LOG_DISABLE || karma.LOG_ERROR || karma.LOG_WARN || karma.LOG_INFO || karma.LOG_DEBUG
logLevel: karma.LOG_INFO,


// enable / disable watching file and executing tests whenever any file changes
autoWatch = %AUTO_WATCH%;
// enable / disable watching file and executing tests whenever any file changes
autoWatch: %AUTO_WATCH%,


// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers = [%BROWSERS%];
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: [%BROWSERS%],


// If browser does not capture in given timeout [ms], kill it
captureTimeout = 60000;
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,


// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun = false;
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false,


// plugins to load
plugins = [
%PLUGINS%
];
// plugins to load
plugins: [
%PLUGINS%
],
});
};
32 changes: 24 additions & 8 deletions docs/config/01-configuration-file.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
In order to serve you well, Karma needs to know about your
project. That's done through a configuration file.

Karma config files are Node modules which are
[required](http://nodejs.org/api/modules.html#modules_module_require_id) and
are expected to export a function which accepts one argument -- Karma dsl
object. Karma DSL object exposes [configure] method which can be called to set
karma properties. For example:

```javascript
module.exports = function(karma) {
karma.configure({
basePath: '../..',
frameworks: ['jasmine'],
//...
});
};
```

For an example configuration, see [test/client/karma.conf.js]
which contains most of the options.

Expand Down Expand Up @@ -103,17 +119,17 @@ See [config/files] for more information.
## logLevel
**Type:** Constant

**Default:** `LOG_INFO`
**Default:** `karma.LOG_INFO`

**CLI:** `--log-level debug`

**Possible values:**

* `LOG_DISABLE`
* `LOG_ERROR`
* `LOG_WARN`
* `LOG_INFO`
* `LOG_DEBUG`
* `karma.LOG_DISABLE`
* `karma.LOG_ERROR`
* `karma.LOG_WARN`
* `karma.LOG_INFO`
* `karma.LOG_DEBUG`

**Description:** Level of logging.

Expand Down Expand Up @@ -154,10 +170,10 @@ See [config/files] for more information.

**Example:**
```javascript
proxies = {
proxies: {
'/static': 'http://gstatic.com',
'/web': 'http://localhost:9000'
};
},
```

## reportSlowerThan
Expand Down
8 changes: 4 additions & 4 deletions docs/config/02-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ If you want to use any of these, add `<FRAMEWORK>` and
`<FRAMEWORK>_ADAPTER` to your `files` list. So for example if you want
to use Mocha you have the following in your config file:
```javascript
files = [
files: [
MOCHA,
MOCHA_ADAPTER
];
],
```

## Pattern matching and `basePath`
Expand Down Expand Up @@ -67,7 +67,7 @@ If you define them like before a simple pattern like
## Complete example
Here is a complete example showing the different options that are possible.
```javascript
files = [
files: [

// Adapter
MOCHA,
Expand All @@ -82,7 +82,7 @@ files = [

// this file only gets watched but otherwise ignored
{pattern: 'app/index.html', included: false, served: false}
];
],
```

[glob]: https://github.com/isaacs/node-glob
4 changes: 2 additions & 2 deletions docs/config/03-browsers.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Capturing browsers is kinda boring, so Karma can do that for you.
Just simply add into the configuration file:

```javascript
browsers = ['Chrome'];
browsers: ['Chrome'],
```
Then, Karma will take care of autocapturing these browsers, as
well as killing them.
Expand Down Expand Up @@ -53,7 +53,7 @@ $Env:FIREFOX_BIN = 'c:\Program Files (x86)\Mozilla Firefox 4.0 Beta 6\firefox.ex
## Custom browsers
```javascript
// in the karma.conf.js
browsers = ['/usr/local/bin/custom-browser.sh'];
browsers: ['/usr/local/bin/custom-browser.sh'],

// from cli
karma start --browsers /usr/local/bin/custom-browser.sh
Expand Down
4 changes: 2 additions & 2 deletions docs/config/04-preprocessors.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ they get served to the browser. The configuration of these happens in this block
in the config file.

```javascript
preprocessors = {
preprocessors: {
'**/*.coffee': 'coffee',
'**/*.html': 'html2js'
};
},
```

## Available Preprocessors
Expand Down
22 changes: 11 additions & 11 deletions docs/config/05-coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ For example if all your code lives in ``lib/`` you need to add this to your
configuration file.

```javascript
preprocessors = {
preprocessors: {
'**/lib/*.js': 'coverage'
};
},
```
You should not however include the files that aren't directly related to your
program, e.g. libraries, mocks, neither tests.

This is a **BAD** example

```javascript
files = [
files: [
JASMINE,
JASMINE_ADAPTER,
'lib/*.js',
'test/*.js'
];
preprocessors = {
],
preprocessors: {
'**/*.js': 'coverage'
};
},
```
In this example also JASMINE and JASMINE_ADAPTER get included but they shouldn't as
these file are only for the test setup used and not for your program.
Expand All @@ -43,7 +43,7 @@ If you include these files there can occur side effects like the following,
## Reporter
To activate the coverage reporter add this to your configuration file.
```javascript
reporters = ['coverage'];
reporters: ['coverage'],
```
This will create a coverage report for every browser that the tests are run in.
In addition, it will create a JSON file that outputs the intermediate data.
Expand All @@ -53,10 +53,10 @@ In addition, it will create a JSON file that outputs the intermediate data.
The reporter defaults to the following values.

```javascript
coverageReporter = {
coverageReporter: {
type : 'html',
dir : 'coverage/'
}
},
```
If you want to configure it yourself here are the options explained.

Expand All @@ -73,11 +73,11 @@ If you want to configure it yourself here are the options explained.

If you set `type` to `text` or `text-summary`, you may set the `file` option, like this.
```javascript
coverageReporter = {
coverageReporter: {
type : 'text',
dir : 'coverage/',
file : 'coverage.txt'
}
},
```
If no filename is given, it will write the output to the console.

Expand Down
8 changes: 4 additions & 4 deletions docs/plus/02-RequireJS.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Now your `karma.conf.js` should include:

```javascript
// list of files / patterns to load in the browser
files = [
files: [
JASMINE,
JASMINE_ADAPTER,
REQUIRE,
Expand All @@ -73,12 +73,12 @@ files = [
{pattern: 'test/**/*Spec.js', included: false},

'test/test-main.js'
];
],

// list of files to exclude
exclude = [
exclude: [
'src/main.js'
];
],
```

## Configuring Require.js
Expand Down
8 changes: 4 additions & 4 deletions docs/plus/03-Jenkins-CI.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ distributions and user permissions.
file as needed:

```javascript
singleRun = true;
reporters = ['dots', 'junit'];
junitReporter = {
singleRun: true,
reporters: ['dots', 'junit'],
junitReporter: {
outputFile: 'test-results.xml'
};
},
```

Please note the `test-result.xml` file will be output to the present
Expand Down
8 changes: 4 additions & 4 deletions docs/plus/05-Cloud9.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ PhantomJS must be installed with `npm install phantomjs`.
The `karma.conf.js` file (tried it out for the [AngularJS foodme app]) must include the following entries:

```javascript
browsers = ['PhantomJS'];
hostname = process.env.IP;
port = process.env.PORT;
runnerPort = 0;
browsers: ['PhantomJS'],
hostname: process.env.IP,
port: process.env.PORT,
runnerPort: 0,
```

[Cloud9 IDE]: https://c9.io/
Expand Down
Loading