-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: do not preprocess files if coverage reporter is not used
Closes #7
- Loading branch information
Showing
3 changed files
with
61 additions
and
21 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
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,52 @@ | ||
vm = require 'vm' | ||
util = require 'util' | ||
|
||
describe 'preprocessor', -> | ||
createPreprocessor = require '../lib/preprocessor' | ||
|
||
ORIGINAL_CODE = ''' | ||
if (a) { | ||
something(); | ||
} else { | ||
other(); | ||
} | ||
''' | ||
|
||
|
||
mockLogger = create: -> | ||
error: -> throw new Error(util.format.apply util, arguments) | ||
warn: -> null | ||
info: -> null | ||
debug: -> null | ||
|
||
# TODO(vojta): refactor this somehow ;-) it's copy pasted from lib/file-list.js | ||
File = (path, mtime) -> | ||
@path = path | ||
@originalPath = path | ||
@contentPath = path | ||
@mtime = mtime | ||
@isUrl = false | ||
|
||
|
||
it 'should not do anything if coverage reporter is not used', (done) -> | ||
process = createPreprocessor mockLogger, null, ['dots', 'progress'] | ||
file = new File '/base/path/file.js' | ||
|
||
process ORIGINAL_CODE, file, (preprocessedCode) -> | ||
expect(preprocessedCode).to.equal ORIGINAL_CODE | ||
expect(file.path).to.equal '/base/path/file.js' | ||
done() | ||
|
||
|
||
it 'should preprocess the code', (done) -> | ||
process = createPreprocessor mockLogger, '/base/path', ['coverage', 'progress'] | ||
file = new File '/base/path/file.js' | ||
|
||
process ORIGINAL_CODE, file, (preprocessedCode) -> | ||
sandbox = | ||
a: true | ||
something: -> | ||
|
||
vm.runInNewContext preprocessedCode, sandbox | ||
expect(sandbox.__coverage__).to.have.ownProperty './file.js' | ||
done() |
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