|
| 1 | +/* global describe, it */ |
| 2 | + |
| 3 | +'use strict'; |
| 4 | + |
| 5 | +var assert = require('assert'), |
| 6 | + Rx = require('rx'), |
| 7 | + parseJs = require('..'), |
| 8 | + parse = require('esprima').parse; |
| 9 | + |
| 10 | +it('without comments', function (done) { |
| 11 | + var file = {path: 'file.js', contents: 'a = 1;'}, |
| 12 | + input = [file], |
| 13 | + expected = [parse(file.contents, {loc: true, source: file.path})]; |
| 14 | + |
| 15 | + // simulating file sequence and applying transformation |
| 16 | + parseJs()(Rx.Observable.fromArray(input)) |
| 17 | + // checking against array of expected results iteratively |
| 18 | + .zip(expected, assert.deepEqual) |
| 19 | + // subscribing to check results |
| 20 | + .subscribe(function () {}, done, done); |
| 21 | +}); |
| 22 | + |
| 23 | +it('with comments', function (done) { |
| 24 | + var file = {path: 'file.js', contents: '/* hello, world! */a = 1;'}, |
| 25 | + input = [file], |
| 26 | + expected = [parse(file.contents, {loc: true, source: file.path, attachComment: true})]; |
| 27 | + |
| 28 | + // simulating file sequence and applying transformation |
| 29 | + parseJs({comments: true})(Rx.Observable.fromArray(input)) |
| 30 | + // checking against array of expected results iteratively |
| 31 | + .zip(expected, assert.deepEqual) |
| 32 | + // subscribing to check results |
| 33 | + .subscribe(function () {}, done, done); |
| 34 | +}); |
| 35 | + |
| 36 | +it('no location tracking', function (done) { |
| 37 | + var file = {path: 'file.js', contents: 'a = 1;'}, |
| 38 | + input = [file], |
| 39 | + expected = [parse(file.contents)]; |
| 40 | + |
| 41 | + // simulating file sequence and applying transformation |
| 42 | + parseJs({loc: false})(Rx.Observable.fromArray(input)) |
| 43 | + // checking against array of expected results iteratively |
| 44 | + .zip(expected, assert.deepEqual) |
| 45 | + // subscribing to check results |
| 46 | + .subscribe(function () {}, done, done); |
| 47 | +}); |
0 commit comments