forked from giuseppeg/babel-plugin-classnames
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
115 lines (100 loc) · 2.41 KB
/
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const assert = require('assert')
const transform = require("@babel/core").transform
const plugin = require('./')
transform(`
<div className={[a,b && fo]} />;
classNames(a, b && foo);
<div className="hhi" />;
<div className={hhi} />;
<div className={[a,b && fo].join('')} />;
`.trim(), { plugins: ["@babel/plugin-syntax-jsx", plugin] }, (err, result) => {
if (err) {
throw err
}
assert.equal(
result.code,
`
import _classNames from "classnames";
<div className={_classNames(a, b && fo)} />;
classNames(a, b && foo);
<div className="hhi" />;
<div className={hhi} />;
<div className={[a, b && fo].join('')} />;
`.trim()
)
})
transform(`
<div className={[a,b && fo]} />;
`.trim(), { plugins: ["@babel/plugin-syntax-jsx", [plugin, { importName: 'cx' }]] }, (err, result) => {
if (err) {
throw err
}
assert.equal(
result.code,
`
import { cx as _classNames } from "classnames";
<div className={_classNames(a, b && fo)} />;
`.trim()
)
})
transform(`
<div className={[a,b && fo]} />;
`.trim(), { plugins: ["@babel/plugin-syntax-jsx", [plugin, { packageName: 'foo' }]] }, (err, result) => {
if (err) {
throw err
}
assert.equal(
result.code,
`
import _classNames from "foo";
<div className={_classNames(a, b && fo)} />;
`.trim()
)
})
transform(`
<div className={{ foo }} />;
`.trim(), { plugins: ["@babel/plugin-syntax-jsx", [plugin, { transformObjects: true }]] }, (err, result) => {
if (err) {
throw err
}
assert.equal(
result.code,
`
import _classNames from "classnames";
<div className={_classNames({
foo
})} />;
`.trim()
)
})
transform(`
<div className={{ foo }} />;
`.trim(), { plugins: ["@babel/plugin-syntax-jsx", [plugin, { transformObjects: false }]] }, (err, result) => {
if (err) {
throw err
}
assert.equal(
result.code,
`
<div className={{
foo
}} />;
`.trim()
)
})
transform(`
<div className={[a,b && fo]}><div className={[styles.foo]} /></div>;
`.trim(), { presets: ["@babel/env"], plugins: ["@babel/plugin-syntax-jsx", plugin] }, (err, result) => {
if (err) {
throw err
}
assert.equal(
result.code,
`
"use strict";
var _classnames = _interopRequireDefault(require("classnames"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
<div className={(0, _classnames.default)(a, b && fo)}><div className={(0, _classnames.default)(styles.foo)} /></div>;
`.trim()
)
})