Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add option plugins * export defaultOpts
- Loading branch information
1 parent
829e658
commit 312f81f
Showing
3 changed files
with
59 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* globals describe, it, context */ | ||
|
||
import Instrumenter from '../src/instrumenter'; | ||
import {assert} from 'chai'; | ||
|
||
const codeNeedDecoratorPlugin = ` | ||
@decorator | ||
class MyClass {} | ||
`; | ||
|
||
const generateCode = (code, plugins) => { | ||
const opts = { | ||
esModules: true, | ||
produceSourceMap: true, | ||
plugins | ||
}; | ||
const instrumenter = new Instrumenter(opts); | ||
return instrumenter.instrumentSync(code, __filename); | ||
}; | ||
|
||
describe('plugins', function () { | ||
context('when the code has a decorator', function() { | ||
context('without decorator plugin', function() { | ||
it('should fail', function (done) { | ||
try { | ||
generateCode(codeNeedDecoratorPlugin); | ||
} catch(e) { | ||
const expected = | ||
`This experimental syntax requires enabling one of the following parser plugin(s): 'decorators-legacy, decorators'`; | ||
assert.ok(e.message.includes(expected)); | ||
done(); | ||
} | ||
}); | ||
}); | ||
|
||
context('with decorator plugin', function() { | ||
it('should success', function () { | ||
const generated = generateCode(codeNeedDecoratorPlugin, ['decorators']); | ||
assert.ok(generated); | ||
assert.ok(typeof generated === 'string'); | ||
}); | ||
}); | ||
}); | ||
}); |