forked from karma-runner/karma-coverage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(preprocessor): Support CoffeeScript when using RequireJS
Adds support for using RequireJS with CoffeeScript code by changing the file extension from `.coffee` to `.js`. RequireJS automatically adds the `.js` suffix to files and it doesn't seem possible to change it. Closes karma-runner#177
- Loading branch information
Lloyd Smith II
committed
Nov 13, 2015
1 parent
d1d7087
commit 1cf4ab9
Showing
7 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
define [], -> | ||
|
||
# Some code under test | ||
plus: (a, b) -> | ||
a + b | ||
|
||
# not covered | ||
minus: (a, b) -> | ||
a - b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module.exports = (config) -> | ||
config.set | ||
frameworks: ['mocha', 'requirejs'] | ||
|
||
files: [ | ||
# We do not want any files to execute automatically | ||
{pattern: 'calculator.coffee', included: false} | ||
{pattern: 'test.coffee', included: false} | ||
|
||
# Except for this one. This one shall execute. | ||
'requirejs.karma.coffee' | ||
] | ||
|
||
browsers: ['Firefox'] | ||
|
||
coffeePreprocessor: | ||
options: | ||
sourceMap: true | ||
|
||
preprocessors: | ||
# source files, that you wanna generate coverage for | ||
# do not include tests or libraries | ||
# (these files will be instrumented by Istanbul via Ibrik unless | ||
# specified otherwise in coverageReporter.instrumenter) | ||
'calculator.coffee': 'coverage' | ||
|
||
# note: project files will already be converted to | ||
# JavaScript via coverage preprocessor. | ||
# Thus, you'll have to limit the CoffeeScript preprocessor | ||
# to uncovered files. | ||
'test.coffee': 'coffee' | ||
'requirejs.karma.coffee': 'coffee' | ||
|
||
coverageReporter: | ||
type: 'text-summary' | ||
useJSExtensionForCoffeeScript: true | ||
instrumenters: | ||
ibrik : require('ibrik') | ||
instrumenter: | ||
'**/*.coffee': 'ibrik' | ||
|
||
# coverage reporter generates the coverage | ||
reporters: ['dots', 'coverage'] | ||
|
||
plugins: [ | ||
require('../../lib/index') | ||
'karma-mocha' | ||
'karma-requirejs' | ||
'karma-coffee-preprocessor' | ||
'karma-firefox-launcher' | ||
] | ||
|
||
singleRun: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "karma-coverage-coffee-example", | ||
"version": "1.0.0", | ||
"description": "Demonstrate the usage of karma-coverage with CoffeeScript", | ||
"main": "", | ||
"scripts": { | ||
"test": "./node_modules/karma/bin/karma start" | ||
}, | ||
"author": "Lloyd Smith II <lloyd.smith@gmail.com>", | ||
"license": "MIT", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"coffee-script": "latest", | ||
"ibrik": "^2.0.0", | ||
"karma": "^0.13.9", | ||
"karma-coffee-preprocessor": "latest", | ||
"karma-firefox-launcher": "latest", | ||
"karma-mocha": "latest", | ||
"karma-requirejs": "^0.2.2", | ||
"requirejs": "^2.1.20" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# A minimal requirejs configuration | ||
require.config | ||
baseUrl: '/base' | ||
deps: ['test'] | ||
callback: -> | ||
window.__karma__.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
define ['calculator'], (calculator) -> | ||
|
||
describe 'calculator', -> | ||
|
||
it 'should pass', -> | ||
true is true | ||
|
||
it 'should work', -> | ||
calculator.plus(1, 2) is 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters