-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(weex): support testing the virtual dom generated form *.vue files (
#6944) Compile the *.vue file into js code, then run it in Weex context, and compare the generate virtual dom. It’s a black-box testing for `weex-template-compiler`, `weex-styler`,`weex-vue-framework` and `weex-js-runtime`.
- Loading branch information
1 parent
8a784d8
commit 232dd85
Showing
8 changed files
with
223 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
import { | ||
compileVue, | ||
createInstance, | ||
getRoot, | ||
getEvents, | ||
fireEvent | ||
} from '../helpers' | ||
|
||
function readFile (filename) { | ||
return fs.readFileSync(path.resolve(__dirname, filename), 'utf8') | ||
} | ||
|
||
function readObject (filename) { | ||
return (new Function(`return ${readFile(filename)}`))() | ||
} | ||
|
||
// Create one-off render test case | ||
function createRenderTestCase (name) { | ||
const source = readFile(`${name}.vue`) | ||
const target = readObject(`${name}.vdom.js`) | ||
return done => { | ||
compileVue(source).then(code => { | ||
const id = String(Date.now() * Math.random()) | ||
const instance = createInstance(id, code) | ||
setTimeout(() => { | ||
expect(getRoot(instance)).toEqual(target) | ||
done() | ||
}, 50) | ||
}).catch(err => { | ||
expect(err).toBe(null) | ||
done() | ||
}) | ||
} | ||
} | ||
|
||
// Create event test case, will trigger the first bind event | ||
function createEventTestCase (name) { | ||
const source = readFile(`${name}.vue`) | ||
const before = readObject(`${name}.before.vdom.js`) | ||
const after = readObject(`${name}.after.vdom.js`) | ||
return done => { | ||
compileVue(source).then(code => { | ||
const id = String(Date.now() * Math.random()) | ||
const instance = createInstance(id, code) | ||
setTimeout(() => { | ||
expect(getRoot(instance)).toEqual(before) | ||
const event = getEvents(instance)[0] | ||
fireEvent(instance, event.ref, event.type, {}) | ||
setTimeout(() => { | ||
expect(getRoot(instance)).toEqual(after) | ||
done() | ||
}, 50) | ||
}, 50) | ||
}).catch(err => { | ||
expect(err).toBe(null) | ||
done() | ||
}) | ||
} | ||
} | ||
|
||
describe('Usage', () => { | ||
describe('render', () => { | ||
it('sample', createRenderTestCase('render/sample')) | ||
}) | ||
|
||
describe('event', () => { | ||
it('click', createEventTestCase('event/click')) | ||
}) | ||
}) | ||
|
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,10 @@ | ||
({ | ||
type: 'div', | ||
event: ['click'], | ||
children: [{ | ||
type: 'text', | ||
attr: { | ||
value: '43' | ||
} | ||
}] | ||
}) |
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,10 @@ | ||
({ | ||
type: 'div', | ||
event: ['click'], | ||
children: [{ | ||
type: 'text', | ||
attr: { | ||
value: '42' | ||
} | ||
}] | ||
}) |
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,20 @@ | ||
<template> | ||
<div @click="inc"> | ||
<text>{{count}}</text> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
module.exports = { | ||
data () { | ||
return { | ||
count: 42 | ||
} | ||
}, | ||
methods: { | ||
inc () { | ||
this.count++ | ||
} | ||
} | ||
} | ||
</script> |
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,17 @@ | ||
({ | ||
type: 'div', | ||
style: { | ||
justifyContent: 'center' | ||
}, | ||
children: [{ | ||
type: 'text', | ||
attr: { | ||
value: 'Yo' | ||
}, | ||
style: { | ||
color: '#41B883', | ||
fontSize: '233px', | ||
textAlign: 'center' | ||
} | ||
}] | ||
}) |
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,23 @@ | ||
<template> | ||
<div style="justify-content:center"> | ||
<text class="freestyle">{{string}}</text> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.freestyle { | ||
color: #41B883; | ||
font-size: 233px; | ||
text-align: center; | ||
} | ||
</style> | ||
|
||
<script> | ||
module.exports = { | ||
data () { | ||
return { | ||
string: 'Yo' | ||
} | ||
} | ||
} | ||
</script> |
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