-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #213 from airbnb/fix-140
Prevent using `<include>` in `<template>` to fix #140 on Alipay
- Loading branch information
Showing
5 changed files
with
90 additions
and
6 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
46 changes: 46 additions & 0 deletions
46
packages/webpack-plugin/src/templates/components/__tests__/leaf-components.wxml.test.tsx
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,46 @@ | ||
import { renderTemplate } from '../..'; | ||
import { ComponentDesc } from '../../../constants/components'; | ||
import { componentWxml } from '../components.wxml'; | ||
|
||
describe('useInlineLeafComponents', () => { | ||
const components: Array<ComponentDesc> = [ | ||
{ | ||
name: 'view', | ||
events: [], | ||
props: {}, | ||
}, | ||
{ | ||
name: 'input', | ||
events: [], | ||
props: {}, | ||
isLeaf: true, | ||
}, | ||
]; | ||
const componentWxmlCommonOptions = { | ||
componentDepth: 0, | ||
childrenDepth: 1, | ||
useFlattenSwiper: false, | ||
components, | ||
simplifiedComponents: [], | ||
pluginComponents: [], | ||
}; | ||
|
||
const TEMPLATE_INCLUDE_LEAF_COMPONENTS = `<include src="./leaf-components.wxml" />`; | ||
const TEMPLATE_INPUT_ITEM = `<block wx:elif="{{meta.type === 'input'}}">`; | ||
|
||
test('should not inline on wechat', () => { | ||
const result = renderTemplate({ target: 'wechat', nodeEnv: 'development' }, () => | ||
componentWxml({ ...componentWxmlCommonOptions, useInlineLeafComponents: false }), | ||
); | ||
expect(result).toContain(TEMPLATE_INCLUDE_LEAF_COMPONENTS); | ||
expect(result).not.toContain(TEMPLATE_INPUT_ITEM); | ||
}); | ||
|
||
test('should inline on alipay', () => { | ||
const result = renderTemplate({ target: 'alipay', nodeEnv: 'development' }, () => | ||
componentWxml({ ...componentWxmlCommonOptions, useInlineLeafComponents: true }), | ||
); | ||
expect(result).not.toContain(TEMPLATE_INCLUDE_LEAF_COMPONENTS); | ||
expect(result).toContain(TEMPLATE_INPUT_ITEM); | ||
}); | ||
}); |
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