UNPKG

2.06 kBtext/coffeescriptView Raw
1fs = require 'fs'
2should = require 'should'
3jscov = require('./coverage').require 'jscov'
4tools = require('./coverage').require 'tools'
5estools = require('./coverage').require 'estools'
6ftools = require('./coverage').require 'jscoverage-formatting-tools'
7jscovFormat = require('./coverage').require 'jscoverage-formatting'
8
9
10
11describe "evalBinaryExpression", ->
12 it "should evaluate binary operators using evalBinaryExpression as expected", ->
13 ftools.evalBinaryExpression(1, '+', 2).should.eql 3
14
15 it "should throw an exception if given an invalid operator", ->
16 f = -> ftools.evalBinaryExpression(1, '%%', 2)
17 f.should.throw()
18
19
20
21describe "jscov", ->
22 it "should cover files using the JSCOV environemnt variable", ->
23 oldCov = process.env.JSCOV
24
25 delete process.env.JSCOV
26 jscov.cover('a', 'b', 'c').should.eql 'a/b/c'
27
28 process.env.JSCOV = 'foobar'
29 jscov.cover('a', 'b', 'c').should.eql 'a/foobar/c'
30
31 process.env.JSOV = oldCov
32
33 it "should return error when given invalid parameters", ->
34 jscov.rewriteFolder 'folder-does-not-exists', 'neither-does-this', {}, (err) ->
35 should.exist err
36
37 it "should expand the file when the option 'expand' is given", ->
38 jscov.rewriteFile(__dirname, 'scaffolding/scaffold/concattenation.js', "#{__dirname}/.output/unit-expand", { expand: true })
39 fs.readFileSync("#{__dirname}/.output/unit-expand/scaffolding/scaffold/concattenation.js", 'utf8').indexOf('&&').should.eql -1
40
41 jscov.rewriteFile(__dirname, 'scaffolding/scaffold/concattenation.js', "#{__dirname}/.output/unit-no-expand", { expand: false })
42 fs.readFileSync("#{__dirname}/.output/unit-no-expand/scaffolding/scaffold/concattenation.js", 'utf8').indexOf('&&').should.not.eql -1
43
44
45
46describe "estools", ->
47 it "should throw an exception if 'evalLiteral' is called for a non-literal", ->
48 f = -> ftools.evalLiteral({ foo: 'bar' })
49 f.should.throw()
50
51 it "should throw an exception if 'evalLiteral' is called for a non-literal", ->
52 ftools.evalLiteral({ type: 'Literal', value: 5 }).should.eql 5