| 1 |
/* (c) 2015 Ari Porad (@ariporad) <http://ariporad.com>. License: ariporad.mit-license.org */ |
| 2 |
import test from 'ava'; |
| 3 |
import rewire from 'rewire'; |
| 4 |
import { makeNonPiratesHook, assertModule } from './helpers/utils'; |
| 5 |
|
| 6 |
const call = (f) => (typeof f === 'function' ? f() : undefined); |
| 7 |
|
| 8 |
test.beforeEach((t) => { |
| 9 |
t.context = rewire('../'); |
| 10 |
}); |
| 11 |
|
| 12 |
test('non-pirates hooks', (t) => { |
| 13 |
const reverts = [ |
| 14 |
t.context.addHook((code) => code.replace('@@a', 'a! @@b')), |
| 15 |
makeNonPiratesHook('@@b', 'b!'), |
| 16 |
t.context.addHook((code) => code.replace('@@c', 'c!'), { |
| 17 |
matcher: (filename) => filename.indexOf('foo') === -1, |
| 18 |
}), |
| 19 |
makeNonPiratesHook('@@d', 'd! @@e'), |
| 20 |
t.context.addHook((code) => code.replace('@@e', 'e!')), |
| 21 |
]; |
| 22 |
|
| 23 |
assertModule(t, 'chain-foo.js', 'in chain-foo a! b! @@c d! e!'); |
| 24 |
assertModule(t, 'chain-bar.js', 'in chain-bar a! b! c! d! e!'); |
| 25 |
|
| 26 |
reverts.map(call); |
| 27 |
}); |