Skip to content

feat(weex): add code coverage test #8006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"test:cover": "karma start test/unit/karma.cover.config.js",
"test:e2e": "npm run build -- web-full-prod,web-server-basic-renderer && node test/e2e/runner.js",
"test:weex": "npm run build:weex && jasmine JASMINE_CONFIG_PATH=test/weex/jasmine.json",
"test:weex:cover": "ISTANBUL=true npm run build:weex && nyc --nycrc-path test/weex/.nycrc jasmine JASMINE_CONFIG_PATH=test/weex/jasmine.json",
"test:ssr": "npm run build:ssr && jasmine JASMINE_CONFIG_PATH=test/ssr/jasmine.json",
"test:sauce": "npm run sauce -- 0 && npm run sauce -- 1 && npm run sauce -- 2",
"test:types": "tsc -p ./types/test/tsconfig.json",
Expand Down Expand Up @@ -120,6 +121,7 @@
"lru-cache": "^4.1.1",
"nightwatch": "^0.9.16",
"nightwatch-helpers": "^1.2.0",
"nyc": "^11.6.0",
"phantomjs-prebuilt": "^2.1.14",
"resolve": "^1.3.3",
"rollup": "^0.54.1",
Expand All @@ -128,6 +130,7 @@
"rollup-plugin-buble": "^0.19.2",
"rollup-plugin-commonjs": "^8.0.0",
"rollup-plugin-flow-no-whitespace": "^1.0.0",
"rollup-plugin-istanbul": "^2.0.1",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-replace": "^2.0.0",
"rollup-watch": "^4.0.0",
Expand Down
8 changes: 8 additions & 0 deletions scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ const buble = require('rollup-plugin-buble')
const alias = require('rollup-plugin-alias')
const cjs = require('rollup-plugin-commonjs')
const replace = require('rollup-plugin-replace')
const istanbul = require('rollup-plugin-istanbul')
const node = require('rollup-plugin-node-resolve')
const flow = require('rollup-plugin-flow-no-whitespace')
const version = process.env.VERSION || require('../package.json').version
const weexVersion = process.env.WEEX_VERSION || require('../packages/weex-vue-framework/package.json').version
const istanbulInstrument = process.env.ISTANBUL

const banner =
'/*!\n' +
Expand Down Expand Up @@ -197,6 +199,12 @@ function genConfig (name) {
}))
}

if (istanbulInstrument) {
config.plugins.push(istanbul({
exclude: ['test/**/*.js']
}))
}

Object.defineProperty(config, '_name', {
enumerable: false,
value: name
Expand Down
2 changes: 2 additions & 0 deletions src/platforms/weex/entry-framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ function createVueModuleInstance (
* Get instance config.
* @return {object}
*/
/* istanbul ignore next */
Vue.prototype.$getConfig = function () {
if (instance.app instanceof Vue) {
return instance.config
Expand All @@ -153,6 +154,7 @@ function createVueModuleInstance (
* framework can make sure no side effect of the callback happened after
* an instance destroyed.
*/
/* istanbul ignore next */
function getInstanceTimer (
instanceId: string,
moduleGetter: Function
Expand Down
2 changes: 2 additions & 0 deletions src/platforms/weex/runtime/modules/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function updateClass (oldVnode: VNodeWithData, vnode: VNodeWithData) {
const oldClassList = makeClassList(oldData)
const classList = makeClassList(data)

/* istanbul ignore else */
if (typeof el.setClassList === 'function') {
el.setClassList(classList)
} else {
Expand Down Expand Up @@ -48,6 +49,7 @@ function makeClassList (data: VNodeData): Array<string> {
return classList
}

/* istanbul ignore next */
function getStyle (oldClassList: Array<string>, classList: Array<string>, ctx: Component): Object {
// style is a weex-only injected object
// compiled from <style> tags in weex files
Expand Down
1 change: 1 addition & 0 deletions src/platforms/weex/runtime/modules/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function add (
passive?: boolean,
params?: Array<any>
) {
/* istanbul ignore next */
if (capture) {
console.log('Weex do not support event in bubble phase.')
return
Expand Down
4 changes: 4 additions & 0 deletions src/platforms/weex/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ export function registerComponentHook (
hook: string, // hook name
fn: Function
) {
/* istanbul ignore if */
if (!document || !document.taskCenter) {
warn(`Can't find available "document" or "taskCenter".`)
return
}
if (typeof document.taskCenter.registerHook === 'function') {
return document.taskCenter.registerHook(componentId, type, hook, fn)
}
/* istanbul ignore next */
warn(`Failed to register component hook "${type}@${hook}#${componentId}".`)
}

Expand All @@ -29,12 +31,14 @@ export function updateComponentData (
newData: Object | void,
callback?: Function
) {
/* istanbul ignore if */
if (!document || !document.taskCenter) {
warn(`Can't find available "document" or "taskCenter".`)
return
}
if (typeof document.taskCenter.updateData === 'function') {
return document.taskCenter.updateData(componentId, newData, callback)
}
/* istanbul ignore next */
warn(`Failed to update component data (${componentId}).`)
}
17 changes: 17 additions & 0 deletions test/weex/.nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"include": [
"src/platforms/weex/**"
],
"exclude": [
"src/platforms/weex/compiler/modules/recycle-list/**",
"src/platforms/weex/runtime/recycle-list/**",
"src/platforms/weex/runtime/components/transition.js",
"src/platforms/weex/runtime/components/transition-group.js",
"src/platforms/weex/runtime/modules/transition.js"
],
"reporter": [
"lcov",
"text-summary"
],
"temp-directory": "./coverage/.nyc_output"
}
9 changes: 9 additions & 0 deletions test/weex/compiler/v-model.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ describe('compile v-model', () => {
expect(errors).toEqual([])
})

it('should compile with number modifier for modelable native component', () => {
const { render, staticRenderFns, errors } = compile(`<div><input v-model.number="x" /></div>`)
expect(render).not.toBeUndefined()
expect(render).toMatch(strToRegExp(`attrs:{"value":(x)}`))
expect(render).toMatch(strToRegExp(`on:{"input":function($event){x=_n($event.target.attr.value)}}`))
expect(staticRenderFns).toEqual([])
expect(errors).toEqual([])
})

it('should compile with trim & lazy modifier', () => {
const { render, staticRenderFns, errors } = compile(`<div><input v-model.trim.lazy="x" /><input v-model.lazy.trim="y" /></div>`)
expect(render).not.toBeUndefined()
Expand Down
18 changes: 18 additions & 0 deletions test/weex/runtime/components/richtext.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,24 @@ describe('richtext component', () => {
}
})
})

it('with event', () => {
const compiled = compileSnippet(`
<richtext>
<span @click="onClick">event</span>
</richtext>
`, `
methods: {
onClick () {}
}
`)
// Because compiled.attr.value[0].events.click is a function,
// we have to stringify `compiled` to ignore the function
expect(JSON.stringify(compiled)).toEqual(
'{"type":"richtext","attr":{"value":[{"type":"span","attr":{"value":"event"},"events":{}}]}}'
)
expect(typeof compiled.attr.value[0].events.click).toEqual('function')
})
})

describe('a', () => {
Expand Down
37 changes: 37 additions & 0 deletions test/weex/runtime/events.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,41 @@ describe('generate events', () => {
done()
})
})

it('should be only fired once', (done) => {
compileAndExecute(`
<div @click.once="foo">
<text>{{x}}</text>
</div>
`, `
data: { x: 0 },
methods: {
foo: function () {
this.x++
}
}
`).then(instance => {
fireEvent(instance, '_root', 'click')
return instance
}).then(instance => {
expect(getRoot(instance)).toEqual({
type: 'div',
children: [{
type: 'text',
attr: { value: '1' }
}]
})
fireEvent(instance, '_root', 'click')
return instance
}).then(instance => {
expect(getRoot(instance)).toEqual({
type: 'div',
children: [{
type: 'text',
attr: { value: '1' }
}]
})
done()
})
})
})