-
-
Notifications
You must be signed in to change notification settings - Fork 230
/
plugins.test.js
44 lines (39 loc) · 1.21 KB
/
plugins.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* globals describe, it, context */
import { assert } from 'chai';
import Instrumenter from '../src/instrumenter';
const codeNeedDecoratorPlugin = `
@decorator
class MyClass {}
`;
const generateCode = (code, parserPlugins) => {
const opts = {
esModules: true,
produceSourceMap: true,
parserPlugins
};
const instrumenter = new Instrumenter(opts);
return instrumenter.instrumentSync(code, __filename);
};
describe('plugins', () => {
context('when the code has a decorator', () => {
context('without decorator plugin', () => {
it('should fail', done => {
try {
generateCode(codeNeedDecoratorPlugin);
} catch (e) {
assert.ok(e);
done();
}
});
});
context('with decorator plugin', () => {
it('should success', () => {
const generated = generateCode(codeNeedDecoratorPlugin, [
['decorators', { decoratorsBeforeExport: false }]
]);
assert.ok(generated);
assert.ok(typeof generated === 'string');
});
});
});
});