Skip to content

Commit

Permalink
Refine testPlugin helper work with test spec.
Browse files Browse the repository at this point in the history
- Make it accept require code as a parameter.
  • Loading branch information
lijunle committed Nov 14, 2015
1 parent fc69edc commit eeb8236
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ function createSandbox () {
return sandbox
}

function testPlugin (options, fn) {
const fixture = `
let foo= 'bar'
export default 'baz'
export {foo}
`

const result = babel.transform(fixture, options)
const fixture = `
let foo= 'bar'
export default 'baz'
export {foo}
`

function testPlugin (code, options, fn) {
const result = babel.transform(code, options)
const sandbox = createSandbox()

vm.runInNewContext(result.code, sandbox)
Expand All @@ -29,7 +29,7 @@ function testPlugin (options, fn) {

describe('babel-plugin-add-module-exports', () => {
it('should not export default to `module.exports` by default.', () =>
testPlugin({
testPlugin(fixture, {
presets: ['es2015']
}, (module) => {
assert(module.toString() !== 'baz')
Expand All @@ -38,7 +38,7 @@ describe('babel-plugin-add-module-exports', () => {
}))

it('should export default to `module.exports` with this plugin', () =>
testPlugin({
testPlugin(fixture, {
presets: ['es2015'],
plugins: ['../lib/index.js']
}, (module) => {
Expand All @@ -48,7 +48,7 @@ describe('babel-plugin-add-module-exports', () => {
}))

it('should handle duplicated plugin references (#1)', () =>
testPlugin({
testPlugin(fixture, {
presets: ['es2015'],
plugins: [
'../lib/index.js',
Expand Down

0 comments on commit eeb8236

Please sign in to comment.