-
Notifications
You must be signed in to change notification settings - Fork 1
/
plugin.test.js
71 lines (66 loc) · 1.63 KB
/
plugin.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const pluginTester = require('babel-plugin-tester/pure').default;
const uselessPlugin = require('babel-plugin-replace-plugin');
/* Jest will take care of these cases. */
beforeAll(() => {
/* do something to setup */
});
afterAll(() => {
/* clean */
});
beforeEach(() => {
/* before each test */
});
afterEach(() => {
/* after each test */
});
pluginTester({
plugin: uselessPlugin,
// the code format matters
// https://github.com/babel-utils/babel-plugin-tester/blob/master/README.md#prettier-formatter
// fixtures: path.join(__dirname, 'fixtures'),
pluginName: 'babel-plugin-replace-plugin',
pluginOptions: {},
babelOptions: {
presets: [],
},
tests: [
{
title: 'use default configuration',
code: 'const number = 1;',
output: 'const not_number = 1;',
},
{
title: 'sourceIdentifier use "num"',
code: 'const num = 1;',
output: 'const not_number = 1;',
pluginOptions: {
sourceIdentifier: 'num',
},
},
{
title: 'targetIdentifier use "number_target"',
code: 'const number = 1;',
output: 'const number_target = 1;',
pluginOptions: {
targetIdentifier: 'number_target',
},
},
{
title:
'sourceIdentifier use "num" and targetIdentifier use "number_target"',
code: 'const num = 1;',
output: 'const number_target = 1;',
pluginOptions: {
sourceIdentifier: 'num',
targetIdentifier: 'number_target',
},
},
{
title: 'replace object value when key is "abc"',
code: 'const abc = { abc: 123 };',
output: `const abc = {
abc: "abc"
};`,
},
],
});