Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanong committed Dec 1, 2014
1 parent 47bfa3c commit a09a544
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 17 deletions.
22 changes: 6 additions & 16 deletions lib/ecstacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,17 @@ Ecstacy.prototype.build = function (agents) {
}

var hash = utils.hash(this.hash + transforms.hash)
debug(transforms.hash)
debug(hash)
var result = {
hash: hash,
code: hash + self.ext,
map: sourcemaps
? (hash + '.map')
: '',
}
return fs.exists(hash + this.ext).then(function (exists) {
return fs.exists(this.filename(hash + this.ext)).then(function (exists) {
debug('exists: ' + exists)
if (exists) return result
return self._getOriginal().then(function (og) {
var out = self._transform(og.code, og.map, transforms)
Expand Down Expand Up @@ -221,19 +224,6 @@ Ecstacy.prototype._filter = function (agents) {
val = transforms.slice()
}

// remove subsets
top:
for (var i = 0; i < val.length; i++) {
if (!val[i].supersets) continue
if (val[i].supersets.some(function (name) {
for (var j = 0; j < val.length; j++) {
if (val[j].name === name) return true
}
})) {
val.splice(i--, 1)
}
}

val.hash = utils.hash(val.map(toHash).join('-'))
if (ua != null) this.cache.set(ua, val)
return val
Expand Down Expand Up @@ -267,8 +257,8 @@ Ecstacy.prototype._defaultTransforms = function (transforms) {
}
if (typeof transforms === 'object') {
return _transforms.filter(function (transform) {
return _transforms[transform.name]
|| _transforms[transform.shortName]
return transforms[transform.name]
|| transforms[transform.shortName]
})
}
return []
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"mkdirp": "0",
"mz": "1",
"native-or-bluebird": "1",
"polyfills-db": "^1.16.1",
"polyfills-db": "^1.19.0",
"postcss": "3",
"postcss-calc": "3",
"postcss-color": "1",
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/async.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

export default async function (a) {
return await a
}
44 changes: 44 additions & 0 deletions test/js.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@

describe('Ecstacy.js.prototype._defaultTransforms', function () {
it('([names...])', function () {
var names = ['arrowfn']
var transforms = Ecstacy.js.prototype._defaultTransforms(names)
assert(transforms.length === 1)
})

it('({ name: true })', function () {
var names = {
arrowfn: true,
gens: true,
}
var transforms = Ecstacy.js.prototype._defaultTransforms(names)
assert(transforms.length === 2)
})
})

describe('Ecstacy.js(code, map)', function () {
describe('.build()', function () {
describe('with an empty file', function () {
Expand Down Expand Up @@ -237,6 +254,33 @@ describe('Ecstacy.js Features', function () {
describe('comprehensions', function () {

})

describe('async', function () {
var code = fixture('async')
var ecstacy = Ecstacy.js({
name: 'async',
code: code,
transforms: true,
})
var data

it('.build()', function () {
return ecstacy.build().then(function (data) {
return ecstacy.read(data.code, 'utf8')
}).then(function (js) {
assert(~js.indexOf('regeneratorRuntime'))
assert(!~js.indexOf('asyncFnRuntime'))
})
})

it('.build(ff30)', function () {
return ecstacy.build(ff30mobile).then(function (data) {
return ecstacy.read(data.code, 'utf8')
}).then(function (js) {
assert(~js.indexOf('asyncFnRuntime'))
})
})
})
})

function fixture(name) {
Expand Down

0 comments on commit a09a544

Please sign in to comment.