Skip to content

Commit

Permalink
test: add "should not handle an amd module" test(refs #57)
Browse files Browse the repository at this point in the history
  • Loading branch information
59naga committed Jul 2, 2018
1 parent 9eed6bf commit 2d56b74
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
21 changes: 19 additions & 2 deletions test/helpers.js
Expand Up @@ -17,9 +17,26 @@ export function createSandbox () {
return sandbox
}

export function testPlugin (code, options, fn) {
export function createSandboxAmd () {
const exports = {}
const sandbox = {
exports,
module: { exports },
require (path) {
delete require.cache[require.resolve(path)]
return require(path)
},
define (args, fn) {
fn(exports)
}
}

return sandbox
}

export function testPlugin (code, options, fn, useAmdSandbox = false) {
const result = babelTransform(code, options)
const sandbox = createSandbox()
const sandbox = useAmdSandbox ? createSandboxAmd() : createSandbox()

vm.runInNewContext(result.code, sandbox)

Expand Down
10 changes: 10 additions & 0 deletions test/index.js
Expand Up @@ -25,6 +25,16 @@ describe('babel-plugin-add-module-exports', () => {
assert(code === result.code)
})

it('should not handle an amd module', () =>
testPlugin(`export default 'default-entry';`, {
presets: [['env', {modules: 'amd'}]],
plugins: [
'./src/index.js'
]
}, (module, code) => {
assert(module.default === 'default-entry')
}, true))

it('plugin should export to module.exports(#31)', () => {
const plugin = require('../src')
assert(typeof plugin === 'function')
Expand Down

0 comments on commit 2d56b74

Please sign in to comment.