123')
68 | expect(res.startStack).toEqual([
69 | {tagName: 'div', attrs: [], unary: false}
70 | ])
71 | expect(res.endStack).toEqual(['div'])
72 | expect(res.textStack).toEqual(['123'])
73 | })
74 |
75 | test('parse wxs', () => {
76 | let res = getParseResult(`
77 |
84 | `)
85 | expect(res.startStack).toEqual([
86 | {tagName: 'div', attrs: [], unary: false},
87 | {tagName: 'wxs', attrs: [{name: 'module', value: 'm1'}], unary: false},
88 | {tagName: 'view', attrs: [], unary: false},
89 | {tagName: 'div', attrs: [], unary: false}
90 | ])
91 | expect(res.endStack).toEqual(['div', 'wxs', 'view', 'div'])
92 | expect(res.textStack).toEqual(['123', 'var msg = "hello world";\n module.exports.message = msg;', '{{m1.message}}', '321'])
93 |
94 | res = getParseResult('
')
95 | expect(res.startStack).toEqual([
96 | {tagName: 'wxs', attrs: [], unary: false}
97 | ])
98 | expect(res.endStack).toEqual(['wxs'])
99 | expect(res.textStack).toEqual([])
100 | })
101 |
102 | test('parse comment', () => {
103 | const res = getParseResult('')
104 | expect(res.startStack).toEqual([])
105 | expect(res.startStack).toEqual([])
106 | expect(res.startStack).toEqual([])
107 | })
108 |
109 | test('parse without options', () => {
110 | let catchErr = null
111 | try {
112 | parse('
')
113 | } catch (err) {
114 | catchErr = err
115 | }
116 |
117 | expect(catchErr).toBe(null)
118 | })
119 |
120 | test('parse error', () => {
121 | function getErr(str) {
122 | let catchErr = null
123 | try {
124 | getParseResult(str)
125 | } catch (err) {
126 | catchErr = err
127 | }
128 |
129 | return catchErr && catchErr.message || ''
130 | }
131 |
132 | expect(getErr('
123')).toBe('parse error: 123')
134 | expect(getErr(' ', a, b)
8 | },
9 | toEqual(b) {
10 | console.log('expect --> ', a, b)
11 | },
12 | })
13 |
14 | const {window} = new JSDOM(`
15 |
16 |
17 |
18 |
test
19 |
20 |
21 |
22 |
23 |
24 |
25 | `, {
26 | runScripts: 'dangerously',
27 | userAgent: 'miniprogram test',
28 | })
29 | global.window = window
30 | global.document = window.document
31 | global.TouchEvent = window.TouchEvent
32 | global.CustomEvent = window.CustomEvent
33 |
34 | require('./render.test.js')
35 |
--------------------------------------------------------------------------------
/test/selectorquery.test.js:
--------------------------------------------------------------------------------
1 | const _ = require('./utils')
2 | const jComponent = require('../src/index')
3 | const SelectorQuery = require('../src/tool/selectorquery')
4 |
5 | beforeAll(() => {
6 | _.env()
7 |
8 | jComponent.register({
9 | id: 'view',
10 | tagName: 'wx-view',
11 | template: '
',
12 | properties: {
13 | hidden: {
14 | type: Boolean,
15 | value: false,
16 | },
17 | }
18 | })
19 | })
20 |
21 |
22 | test('SelectorQuery', async () => {
23 | const comp = jComponent.create(jComponent.register({
24 | template: '
123',
25 | }))
26 |
27 | // boundingClientRect
28 | let selectorQuery = new SelectorQuery()
29 | selectorQuery.in(comp)
30 | let res = await new Promise(resolve => {
31 | selectorQuery.select('#abc').boundingClientRect(res => {
32 | resolve(res)
33 | }).exec()
34 | })
35 | expect(res).toEqual({
36 | id: 'abc',
37 | dataset: {
38 | a: '1',
39 | b: '2',
40 | },
41 | left: 0,
42 | right: 0,
43 | top: 0,
44 | bottom: 0,
45 | width: 0,
46 | height: 0,
47 | })
48 |
49 | // scrollOffset
50 | selectorQuery = new SelectorQuery()
51 | selectorQuery.in(comp)
52 | res = await new Promise(resolve => {
53 | selectorQuery.selectAll('#abc').scrollOffset(res => {
54 | resolve(res)
55 | }).exec()
56 | })
57 | expect(res).toEqual([{
58 | id: 'abc',
59 | dataset: {
60 | a: '1',
61 | b: '2',
62 | },
63 | scrollLeft: 0,
64 | scrollTop: 0,
65 | }])
66 |
67 | // context
68 | selectorQuery = new SelectorQuery()
69 | selectorQuery.in(comp)
70 | res = await new Promise(resolve => {
71 | selectorQuery.select('#abc').context(res => {
72 | resolve(res)
73 | }).exec()
74 | })
75 | expect(res).toEqual({
76 | context: {},
77 | })
78 |
79 | // fields
80 | selectorQuery = new SelectorQuery()
81 | selectorQuery.in(comp)
82 | res = await new Promise(resolve => {
83 | selectorQuery.select('#abc').fields({
84 | id: true,
85 | dataset: true,
86 | rect: true,
87 | size: true,
88 | scrollOffset: true,
89 | properties: ['hidden'],
90 | computedStyle: ['position', 'top', 'left', 'width', 'height'],
91 | context: true,
92 | }, res => {
93 | resolve(res)
94 | }).exec()
95 | })
96 | expect(res).toEqual({
97 | id: 'abc',
98 | dataset: {
99 | a: '1',
100 | b: '2',
101 | },
102 | scrollLeft: 0,
103 | scrollTop: 0,
104 | left: '30px',
105 | right: 0,
106 | top: '20px',
107 | bottom: 0,
108 | width: '100px',
109 | height: '200px',
110 | hidden: false,
111 | position: 'absolute',
112 | context: {},
113 | })
114 |
115 | // exec
116 | selectorQuery = new SelectorQuery()
117 | selectorQuery.in(comp)
118 | res = await new Promise(resolve => {
119 | selectorQuery.select('#abc').boundingClientRect().selectAll('#abc').scrollOffset()
120 | .exec(res => {
121 | resolve(res)
122 | })
123 | })
124 | expect(res).toEqual([{
125 | id: 'abc',
126 | dataset: {
127 | a: '1',
128 | b: '2',
129 | },
130 | left: 0,
131 | right: 0,
132 | top: 0,
133 | bottom: 0,
134 | width: 0,
135 | height: 0,
136 | }, [{
137 | id: 'abc',
138 | dataset: {
139 | a: '1',
140 | b: '2',
141 | },
142 | scrollLeft: 0,
143 | scrollTop: 0,
144 | }]])
145 | selectorQuery = new SelectorQuery()
146 | selectorQuery.in(comp)
147 | res = await new Promise(resolve => {
148 | selectorQuery.select('#cba').boundingClientRect()
149 | .exec(res => {
150 | resolve(res)
151 | })
152 | })
153 | expect(res).toEqual([null])
154 |
155 | // selectViewport
156 | selectorQuery = new SelectorQuery()
157 | selectorQuery.in(comp)
158 | res = await new Promise(resolve => {
159 | selectorQuery.selectViewport().fields({
160 | id: true,
161 | dataset: true,
162 | rect: true,
163 | size: true,
164 | scrollOffset: true,
165 | }).exec(res => {
166 | resolve(res)
167 | })
168 | })
169 | expect(res).toEqual([{
170 | id: '',
171 | dataset: {},
172 | left: 0,
173 | right: 0,
174 | top: 0,
175 | bottom: 0,
176 | width: 0,
177 | height: 0,
178 | scrollLeft: 0,
179 | scrollTop: 0,
180 | }])
181 |
182 | selectorQuery = new SelectorQuery()
183 | selectorQuery.in(comp)
184 | res = await new Promise(resolve => {
185 | selectorQuery.selectViewport().fields({}).exec(res => {
186 | resolve(res)
187 | })
188 | })
189 | expect(res).toEqual([{}])
190 | })
191 |
192 | test('createSelectorQuery', () => {
193 | const comp = jComponent.create(jComponent.register({
194 | template: '
123',
195 | methods: {
196 | getSelectorQuery() {
197 | return this.createSelectorQuery()
198 | },
199 | },
200 | }))
201 |
202 | expect(comp.instance.getSelectorQuery()._exparserNode).toBe(comp.instance._exparserNode)
203 | })
204 |
205 | test('error', () => {
206 | const selectorQuery = new SelectorQuery()
207 | let catchErr = null
208 | try {
209 | selectorQuery.in()
210 | } catch (err) {
211 | catchErr = err
212 | }
213 | expect(catchErr.message).toBe('invalid params')
214 | })
215 |
--------------------------------------------------------------------------------
/test/this.test.js:
--------------------------------------------------------------------------------
1 | const jComponent = require('../src/index')
2 | const _ = require('./utils')
3 |
4 | beforeAll(() => {
5 | _.env()
6 |
7 | jComponent.register({
8 | id: 'view',
9 | tagName: 'wx-view',
10 | template: '
'
11 | })
12 | })
13 |
14 | test('this.data/this.properties', () => {
15 | const comp = jComponent.create(jComponent.register({
16 | template: '
123
',
17 | properties: {
18 | aa: {
19 | type: String,
20 | value: '321',
21 | },
22 | },
23 | data: {
24 | bb: 123,
25 | },
26 | }))
27 |
28 | expect(comp.instance.data.bb).toBe(123)
29 | expect(comp.instance.data.aa).toBe('321')
30 | expect(comp.instance.properties.aa).toBe('321')
31 | })
32 |
33 | test('this.dataset', () => {
34 | const comp = jComponent.create(jComponent.register({
35 | template: '
123
',
36 | }))
37 | const child = comp.querySelector('#abc')
38 |
39 | expect(child.instance.dataset.a).toBe('123')
40 | expect(child.instance.dataset.b).toBe('321')
41 | })
42 |
43 | test('this.id/this.is', () => {
44 | const comp = jComponent.create(jComponent.register({
45 | template: '
123',
46 | }))
47 | const child = comp.querySelector('#abc')
48 |
49 | expect(child.instance.id).toBe('abc')
50 | expect(child.instance.is).toBe('view')
51 | })
52 |
53 | test('this.setData/this.hasBehavior/this.triggerEvent', () => {
54 | const comp = jComponent.create(jComponent.register({
55 | template: '
123
',
56 | }))
57 |
58 | expect(typeof comp.instance.setData).toBe('function')
59 | expect(typeof comp.instance.hasBehavior).toBe('function')
60 | expect(typeof comp.instance.triggerEvent).toBe('function')
61 | })
62 |
63 | test('this.selectComponent/this.selectAllComponents', () => {
64 | const comp = jComponent.create(jComponent.register({
65 | template: '
123
',
66 | }))
67 |
68 | expect(comp.instance.selectComponent('#abc').$$.innerHTML).toBe('123')
69 | expect(comp.instance.selectAllComponents('#abc')[0].$$.innerHTML).toBe('123')
70 | })
71 |
72 | test('this.selectOwnerComponent', () => {
73 | const compaId = jComponent.register({
74 | template: '
hello,
',
75 | })
76 | const compb = jComponent.create(jComponent.register({
77 | template: '
june',
78 | usingComponents: {
79 | compa: compaId,
80 | },
81 | }))
82 |
83 | expect(compb.instance.selectComponent('#abc').selectOwnerComponent().$$.innerHTML).toBe('
hello,june
')
84 | })
85 |
--------------------------------------------------------------------------------
/test/transform.test.js:
--------------------------------------------------------------------------------
1 | const path = require('path')
2 | const compiler = require('miniprogram-compiler')
3 | const jComponent = require('../src/index')
4 | const _ = require('./utils')
5 |
6 | beforeAll(() => {
7 | _.env()
8 | })
9 |
10 | test('support wcc compiler', () => {
11 | window.__webview_engine_version__ = 0.02
12 | const compileString = compiler.wxmlToJs(path.join(__dirname, 'wxml'))
13 | // eslint-disable-next-line no-new-func
14 | const compileFunc = new Function(compileString)
15 | const gwx = compileFunc()
16 |
17 | const compId = jComponent.register({
18 | properties: {
19 | aa: {
20 | type: String,
21 | value: '',
22 | },
23 | },
24 | template: gwx('comp.wxml'),
25 | })
26 | const id = jComponent.register({
27 | data: {
28 | tmplData: {
29 | index: 7,
30 | msg: 'I am msg',
31 | time: '12345'
32 | },
33 | flag: true,
34 | elseData: 'else content',
35 | attrValue: 'I am attr value',
36 | content: 'node content',
37 | aa: 'haha',
38 | list: [
39 | {id: 1, name: 1},
40 | {id: 2, name: 2},
41 | {id: 3, name: 3}
42 | ],
43 | },
44 | template: gwx('index.wxml'),
45 | usingComponents: {
46 | comp: compId,
47 | },
48 | })
49 | const comp = jComponent.create(id)
50 |
51 | expect(comp.dom.innerHTML).toBe('
headtmpl7: I am msgTime: 12345hello juneifnode content I am compI am slot1-item2-item3-itemin block1in block2foot')
52 | })
53 |
--------------------------------------------------------------------------------
/test/utils.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Touch polyfill
3 | */
4 | class Touch {
5 | constructor(options = {}) {
6 | this.clientX = 0
7 | this.clientY = 0
8 | this.identifier = 0
9 | this.pageX = 0
10 | this.pageY = 0
11 | this.screenX = 0
12 | this.screenY = 0
13 | this.target = null
14 |
15 | Object.keys(options).forEach(key => {
16 | this[key] = options[key]
17 | })
18 | }
19 | }
20 | window.requestAnimationFrame = func => setTimeout(func, 0)
21 |
22 | /**
23 | * 环境准备
24 | */
25 | function env() {
26 | global.Touch = window.Touch = Touch
27 | }
28 |
29 | /**
30 | * 延迟执行后续代码
31 | */
32 | async function sleep(timeout) {
33 | return new Promise(resolve => {
34 | setTimeout(() => {
35 | resolve()
36 | }, timeout)
37 | })
38 | }
39 |
40 | /**
41 | * 动画实现
42 | */
43 | class Animation {
44 | constructor(option = {}) {
45 | this.actions = []
46 | this.currentTransform = []
47 | this.currentStepAnimates = []
48 |
49 | this.option = {
50 | transition: {
51 | duration: option.duration !== undefined ? option.duration : 400,
52 | timingFunction: option.timingFunction !== undefined ? option.timingFunction : 'linear',
53 | delay: option.delay !== undefined ? option.delay : 0,
54 | },
55 | transformOrigin: option.transformOrigin || '50% 50% 0',
56 | }
57 | }
58 |
59 | export() {
60 | const actions = this.actions
61 | this.actions = []
62 | return {actions}
63 | }
64 |
65 | step(option = {}) {
66 | this.currentStepAnimates.forEach((animate) => {
67 | if (animate.type !== 'style') {
68 | this.currentTransform[animate.type] = animate
69 | } else {
70 | this.currentTransform[`${animate.type}.${animate.args[0]}`] = animate
71 | }
72 | })
73 |
74 | this.actions.push({
75 | animates: Object.keys(this.currentTransform).reduce((prev, key) => [...prev, this.currentTransform[key]], []),
76 | option: {
77 | transformOrigin: option.transformOrigin !== undefined ? option.transformOrigin : this.option.transformOrigin,
78 | transition: {
79 | duration: option.duration !== undefined ? option.duration : this.option.transition.duration,
80 | timingFunction: option.timingFunction !== undefined ? option.timingFunction : this.option.transition.timingFunction,
81 | delay: option.delay !== undefined ? option.delay : this.option.transition.delay,
82 | },
83 | },
84 | })
85 |
86 | this.currentStepAnimates = []
87 | return this
88 | }
89 |
90 | matrix(a = 1, b = 0, c = 0, d = 1, tx = 1, ty = 1) {
91 | this.currentStepAnimates.push({type: 'matrix', args: [a, b, c, d, tx, ty]})
92 | return this
93 | }
94 |
95 | matrix3d(a1 = 1, b1 = 0, c1 = 0, d1 = 0, a2 = 0, b2 = 1, c2 = 0, d2 = 0, a3 = 0, b3 = 0, c3 = 1, d3 = 0, a4 = 0, b4 = 0, c4 = 0, d4 = 1) {
96 | this.currentStepAnimates.push({type: 'matrix3d', args: [a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4]})
97 | this.stepping = false
98 | return this
99 | }
100 |
101 | rotate(angle = 0) {
102 | this.currentStepAnimates.push({type: 'rotate', args: [angle]})
103 | return this
104 | }
105 |
106 | rotate3d(x = 0, y = 0, z = 0, a = 0) {
107 | this.currentStepAnimates.push({type: 'rotate3d', args: [x, y, z, a]})
108 | this.stepping = false
109 | return this
110 | }
111 |
112 | rotateX(a = 0) {
113 | this.currentStepAnimates.push({type: 'rotateX', args: [a]})
114 | this.stepping = false
115 | return this
116 | }
117 |
118 | rotateY(a = 0) {
119 | this.currentStepAnimates.push({type: 'rotateY', args: [a]})
120 | this.stepping = false
121 | return this
122 | }
123 |
124 | rotateZ(a = 0) {
125 | this.currentStepAnimates.push({type: 'rotateZ', args: [a]})
126 | this.stepping = false
127 | return this
128 | }
129 |
130 | scale(sx = 1, sy) {
131 | this.currentStepAnimates.push({type: 'scale', args: [sx, sy !== undefined ? sy : sx]})
132 | return this
133 | }
134 |
135 | scale3d(sx = 1, sy = 1, sz = 1) {
136 | this.currentStepAnimates.push({type: 'scale3d', args: [sx, sy, sz]})
137 | return this
138 | }
139 |
140 | scaleX(s = 1) {
141 | this.currentStepAnimates.push({type: 'scaleX', args: [s]})
142 | return this
143 | }
144 |
145 | scaleY(s = 1) {
146 | this.currentStepAnimates.push({type: 'scaleY', args: [s]})
147 | return this
148 | }
149 |
150 | scaleZ(s = 1) {
151 | this.currentStepAnimates.push({type: 'scaleZ', args: [s]})
152 | return this
153 | }
154 |
155 | skew(ax = 0, ay = 0) {
156 | this.currentStepAnimates.push({type: 'skew', args: [ax, ay]})
157 | return this
158 | }
159 |
160 | skewX(a = 0) {
161 | this.currentStepAnimates.push({type: 'skewX', args: [a]})
162 | return this
163 | }
164 |
165 | skewY(a = 0) {
166 | this.currentStepAnimates.push({type: 'skewY', args: [a]})
167 | return this
168 | }
169 |
170 | translate(tx = 0, ty = 0) {
171 | this.currentStepAnimates.push({type: 'translate', args: [tx, ty]})
172 | return this
173 | }
174 |
175 | translate3d(tx = 0, ty = 0, tz = 0) {
176 | this.currentStepAnimates.push({type: 'translate3d', args: [tx, ty, tz]})
177 | return this
178 | }
179 |
180 | translateX(t = 0) {
181 | this.currentStepAnimates.push({type: 'translateX', args: [t]})
182 | return this
183 | }
184 |
185 | translateY(t = 0) {
186 | this.currentStepAnimates.push({type: 'translateY', args: [t]})
187 | return this
188 | }
189 |
190 | translateZ(t = 0) {
191 | this.currentStepAnimates.push({type: 'translateZ', args: [t]})
192 | return this
193 | }
194 |
195 | opacity(value) {
196 | this.currentStepAnimates.push({type: 'style', args: ['opacity', value]})
197 | return this
198 | }
199 |
200 | backgroundColor(value) {
201 | this.currentStepAnimates.push({type: 'style', args: ['background-color', value]})
202 | return this
203 | }
204 |
205 | width(value) {
206 | this.currentStepAnimates.push({type: 'style', args: ['width', typeof value === 'number' ? value + 'px' : value]})
207 | return this
208 | }
209 |
210 | height(value) {
211 | this.currentStepAnimates.push({type: 'style', args: ['height', typeof value === 'number' ? value + 'px' : value]})
212 | return this
213 | }
214 |
215 | left(value) {
216 | this.currentStepAnimates.push({type: 'style', args: ['left', typeof value === 'number' ? value + 'px' : value]})
217 | return this
218 | }
219 |
220 | right(value) {
221 | this.currentStepAnimates.push({type: 'style', args: ['right', typeof value === 'number' ? value + 'px' : value]})
222 | return this
223 | }
224 |
225 | top(value) {
226 | this.currentStepAnimates.push({type: 'style', args: ['top', typeof value === 'number' ? value + 'px' : value]})
227 | return this
228 | }
229 |
230 | bottom(value) {
231 | this.currentStepAnimates.push({type: 'style', args: ['bottom', typeof value === 'number' ? value + 'px' : value]})
232 | return this
233 | }
234 | }
235 | function createAnimation(transition = {}) {
236 | return new Animation(transition)
237 | }
238 |
239 | module.exports = {
240 | env,
241 | sleep,
242 | createAnimation,
243 | }
244 |
--------------------------------------------------------------------------------
/test/utils.test.js:
--------------------------------------------------------------------------------
1 | const _ = require('./utils')
2 | const utils = require('../src/tool/utils')
3 |
4 | test('getId', () => {
5 | expect(typeof utils.getId()).toBe('number')
6 | expect(utils.getId() + '').toMatch(/\d{13}/)
7 | expect(utils.getId(true)).toMatch(/[a-j]{13}/)
8 | })
9 |
10 | test('copy', () => {
11 | let src = {a: 123, b: [{c: 321}, 456]}
12 | let res = utils.copy(src)
13 | expect(res).not.toBe(src)
14 | expect(res).toEqual(src)
15 |
16 | src = Symbol('test')
17 | res = utils.copy(src)
18 | expect(res).toBe(undefined)
19 | })
20 |
21 | test('isHtmlTag', () => {
22 | expect(utils.isHtmlTag('div')).toBe(true)
23 | expect(utils.isHtmlTag('span')).toBe(true)
24 | expect(utils.isHtmlTag('component')).toBe(false)
25 | expect(utils.isHtmlTag('wxs')).toBe(false)
26 | })
27 |
28 | test('transformRpx', () => {
29 | expect(utils.transformRpx('width: 123rpx;')).toBe('width: 123px;')
30 | expect(utils.transformRpx('width: aaarpx;')).toBe('width: aaarpx;')
31 | expect(utils.transformRpx('width: 123px;')).toBe('width: 123px;')
32 | expect(utils.transformRpx('width: 12.3rpx;')).toBe('width: 12.3px;')
33 | expect(utils.transformRpx('width: 0.3rpx;')).toBe('width: 0.3px;')
34 | })
35 |
36 | test('dashToCamelCase', () => {
37 | expect(utils.dashToCamelCase('abc-e')).toBe('abcE')
38 | expect(utils.dashToCamelCase('aBcDE-f')).toBe('aBcDEF')
39 | expect(utils.dashToCamelCase('a-bC-d-e-Fg')).toBe('aBCDE-Fg')
40 | })
41 |
42 | test('camelToDashCase', () => {
43 | expect(utils.camelToDashCase('abcE')).toBe('abc-e')
44 | expect(utils.camelToDashCase('aBcDEF')).toBe('a-bc-d-e-f')
45 | expect(utils.camelToDashCase('aBCDE-Fg')).toBe('a-b-c-d-e--fg')
46 | })
47 |
48 | test('animationToStyle', () => {
49 | let animation = _.createAnimation().rotate(45).scale(2, 2).translate(11)
50 | .skew(9)
51 | .step()
52 | .export()
53 | expect(utils.animationToStyle(animation.actions[0])).toEqual({
54 | style: {},
55 | transform: 'rotate(45deg) scale(2,2) translate(11px,0px) skew(9deg,0deg)',
56 | transformOrigin: '50% 50% 0',
57 | transition: '400ms linear 0ms',
58 | transitionProperty: 'transform',
59 | })
60 |
61 | animation = _.createAnimation()
62 | .rotateX(180).rotateY(30).rotateZ(45)
63 | .scaleX(0.5)
64 | .scaleY(2)
65 | .scaleZ(2)
66 | .translateX(12)
67 | .translateY(34)
68 | .translateZ(56)
69 | .skewX(8)
70 | .skewY(9)
71 | .width(20)
72 | .left('5rpx')
73 | .step()
74 | .export()
75 | expect(utils.animationToStyle(animation.actions[0])).toEqual({
76 | style: {left: '5rpx', width: '20px'},
77 | transform: 'rotateX(180deg) rotateY(30deg) rotateZ(45deg) scaleX(0.5) scaleY(2) scaleZ(2) translateX(12px) translateY(34px) translateZ(56px) skewX(8deg) skewY(9deg)',
78 | transformOrigin: '50% 50% 0',
79 | transition: '400ms linear 0ms',
80 | transitionProperty: 'transform,width,left',
81 | })
82 |
83 | animation = _.createAnimation().rotate3d(20, 30, 40).scale3d(1, 2, 0.5).translate3d(20, 44, 56)
84 | .step()
85 | .export()
86 | expect(utils.animationToStyle(animation.actions[0])).toEqual({
87 | style: {},
88 | transform: 'rotate3d(20,30,40,0deg) scale3d(1,2,0.5) translate3d(20px,44px,56px)',
89 | transformOrigin: '50% 50% 0',
90 | transition: '400ms linear 0ms',
91 | transitionProperty: 'transform',
92 | })
93 |
94 | animation = _.createAnimation().matrix(1, 2, -1, 1, 80, 80).step().export()
95 | expect(utils.animationToStyle(animation.actions[0])).toEqual({
96 | style: {},
97 | transform: 'matrix(1,2,-1,1,80,80)',
98 | transformOrigin: '50% 50% 0',
99 | transition: '400ms linear 0ms',
100 | transitionProperty: 'transform',
101 | })
102 |
103 | animation = _.createAnimation().matrix3d(0.85, 0.5, 0.15, 0, -0.5, 0.7, 0.5, 0, 0.15, -0.5, 0.85, 0, 22.63, -20.32, 101.37, 1).step().export()
104 | expect(utils.animationToStyle(animation.actions[0])).toEqual({
105 | style: {},
106 | transform: 'matrix3d(0.85,0.5,0.15,0,-0.5,0.7,0.5,0,0.15,-0.5,0.85,0,22.63,-20.32,101.37,1)',
107 | transformOrigin: '50% 50% 0',
108 | transition: '400ms linear 0ms',
109 | transitionProperty: 'transform',
110 | })
111 |
112 | expect(utils.animationToStyle({})).toEqual({
113 | transformOrigin: '',
114 | transform: '',
115 | transition: '',
116 | })
117 | })
118 |
119 | test('adjustExparserDefinition', () => {
120 | expect(utils.adjustExparserDefinition({})).toEqual({})
121 | expect(utils.adjustExparserDefinition({
122 | properties: {
123 | a: null,
124 | b: Number,
125 | c: String,
126 | d: Boolean,
127 | e: Array,
128 | f: Object,
129 | g: {
130 | type: Number,
131 | value: 123,
132 | },
133 | h: {
134 | public: true,
135 | type: Number,
136 | value: 123,
137 | },
138 | i: {
139 | public: false,
140 | type: Number,
141 | value: 123,
142 | },
143 | j: {
144 | type: null,
145 | value: 123,
146 | },
147 | },
148 | })).toEqual({
149 | properties: {
150 | a: {type: null},
151 | b: {type: Number},
152 | c: {type: String},
153 | d: {type: Boolean},
154 | e: {type: Array},
155 | f: {type: Object},
156 | g: {
157 | type: Number,
158 | value: 123,
159 | },
160 | h: {
161 | type: Number,
162 | value: 123,
163 | },
164 | i: {
165 | public: false,
166 | type: Number,
167 | value: 123,
168 | },
169 | j: {
170 | type: null,
171 | value: 123,
172 | },
173 | },
174 | })
175 | })
176 |
177 | test('setTagName/getTagName', () => {
178 | utils.setTagName(1, 'abc')
179 | expect(utils.getTagName(1)).toBe('abc')
180 | })
181 |
182 | test('normalizeAbsolute', () => {
183 | expect(utils.normalizeAbsolute('E:\\abc\\edf.xxx')).toBe('E:/abc/edf.xxx')
184 | expect(utils.normalizeAbsolute('E:\\\\abc\\edf.xxx')).toBe('E:/abc/edf.xxx')
185 | expect(utils.normalizeAbsolute('E:\\abc\\edf.xxx\\')).toBe('E:/abc/edf.xxx')
186 | expect(utils.normalizeAbsolute('E:/abc/edf.xxx')).toBe('E:/abc/edf.xxx')
187 | expect(utils.normalizeAbsolute('E:/abc/edf.xxx/')).toBe('E:/abc/edf.xxx')
188 | expect(utils.normalizeAbsolute('E://abc//edf.xxx')).toBe('E:/abc/edf.xxx')
189 | expect(utils.normalizeAbsolute('E:/\\/abc//edf.xxx/\\as/df\\/d\\')).toBe('E:/abc/edf.xxx/as/df/d')
190 | })
191 |
192 | test('relativeToAbsolute', () => {
193 | expect(utils.relativeToAbsolute('E:/abc/edf.xxx/as/df/d', '/abc/dd.haha')).toBe('E:/abc/edf.xxx/as/df/abc/dd.haha')
194 | expect(utils.relativeToAbsolute('E:/abc/edf.xxx/as/df/d', 'abc/dd.haha')).toBe('E:/abc/edf.xxx/as/df/abc/dd.haha')
195 | expect(utils.relativeToAbsolute('E:/abc/edf.xxx/as/df/d', './abc/dd.haha')).toBe('E:/abc/edf.xxx/as/df/abc/dd.haha')
196 | expect(utils.relativeToAbsolute('E:/abc/edf.xxx/as/df/d', '../abc/dd.haha')).toBe('E:/abc/edf.xxx/as/abc/dd.haha')
197 | expect(utils.relativeToAbsolute('E:/abc/edf.xxx/as/df/d', '../abc/./dd.haha')).toBe('E:/abc/edf.xxx/as/abc/dd.haha')
198 | expect(utils.relativeToAbsolute('E:/abc/edf.xxx/as/df/d', '../abc/../dd.haha')).toBe('E:/abc/edf.xxx/as/dd.haha')
199 | })
200 |
--------------------------------------------------------------------------------
/test/wxml/comp.json:
--------------------------------------------------------------------------------
1 | {
2 | "component": true,
3 | "usingComponents": {}
4 | }
--------------------------------------------------------------------------------
/test/wxml/comp.wxml:
--------------------------------------------------------------------------------
1 |
2 | {{aa}} I am comp
3 |
4 |
--------------------------------------------------------------------------------
/test/wxml/comp.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wechat-miniprogram/j-component/d8203de72242266063691f2e01e8114bd3433f10/test/wxml/comp.wxss
--------------------------------------------------------------------------------
/test/wxml/foot.wxml:
--------------------------------------------------------------------------------
1 |
foot
--------------------------------------------------------------------------------
/test/wxml/head.wxml:
--------------------------------------------------------------------------------
1 |
head
--------------------------------------------------------------------------------
/test/wxml/index.js:
--------------------------------------------------------------------------------
1 | Component({
2 | data: {
3 | tmplData: {
4 | index: 7,
5 | msg: 'I am msg',
6 | time: '12345'
7 | },
8 | flag: true,
9 | elseData: 'else content',
10 | attrValue: 'I am attr value',
11 | content: 'node content',
12 | aa: 'haha',
13 | list: [
14 | {id: 1, name: 1},
15 | {id: 2, name: 2},
16 | {id: 3, name: 3}
17 | ],
18 | }
19 | })
20 |
--------------------------------------------------------------------------------
/test/wxml/index.json:
--------------------------------------------------------------------------------
1 | {
2 | "component": true,
3 | "usingComponents": {
4 | "comp": "./comp"
5 | }
6 | }
--------------------------------------------------------------------------------
/test/wxml/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | {{index}}: {{msg}}
7 | Time: {{time}}
8 |
9 |
10 |
11 |
12 | module.exports.getMessage = function(name) {
13 | name = name || 'world';
14 | return 'hello ' + name;
15 | };
16 |
17 |
{{m1.getMessage('june')}}
18 |
19 | if
20 | else {{elseData}}
21 | {{content}}
22 |
23 | I am slot
24 |
25 | {{item.name}}-item
26 |
27 | in block1
28 | in block2
29 |
30 |
31 |
--------------------------------------------------------------------------------
/test/wxml/index.wxss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wechat-miniprogram/j-component/d8203de72242266063691f2e01e8114bd3433f10/test/wxml/index.wxss
--------------------------------------------------------------------------------
/test/wxml/tmpl.wxml:
--------------------------------------------------------------------------------
1 |
2 | tmpl
3 |
--------------------------------------------------------------------------------