@@ -15,6 +15,9 @@ const clear = () => {
1515 rimraf . sync ( resolve ( __dirname , 'dist' ) ) ;
1616} ;
1717
18+ const target = ( target ) => ( compiler ) =>
19+ compiler . apply ( new webpack . LoaderTargetPlugin ( target ) ) ;
20+
1821const mkdir = ( ) => {
1922 clear ( ) ;
2023} ;
@@ -33,7 +36,7 @@ const compile = (content, options = {}) => {
3336 } ) ;
3437} ;
3538
36- describe ( 'wxml-loader' , ( ) => {
39+ describe ( 'wxml-loader' , async ( ) => {
3740 beforeEach ( mkdir ) ;
3841 afterEach ( clear ) ;
3942
@@ -72,7 +75,7 @@ describe('wxml-loader', () => {
7275 test ( 'should Wechat target work' , async ( ) => {
7376 await compile (
7477 '<import src="/fixture.wxml" /><view wx:for="{{items}}">{{item}}</view>' ,
75- { target : function Wechat ( ) { } } ,
78+ { target : target ( function Wechat ( ) { } ) } ,
7679 ) ;
7780 expect ( getCompiledRes ( ) ) . toBe (
7881 '<import src="/fixture.wxml" /><view wx:for="{{items}}">{{item}}</view>' ,
@@ -82,7 +85,7 @@ describe('wxml-loader', () => {
8285 test ( 'should Alipay target work' , async ( ) => {
8386 await compile (
8487 '<import src="/fixture.wxml" /><view wx:for="{{items}}">{{item}}</view>' ,
85- { target : function Alipay ( ) { } } ,
88+ { target : target ( function Alipay ( ) { } ) } ,
8689 ) ;
8790 expect ( getCompiledRes ( ) ) . toBe (
8891 '<import src="/fixture.axml" /><view a:for="{{items}}">{{item}}</view>' ,
@@ -91,7 +94,7 @@ describe('wxml-loader', () => {
9194
9295 test ( 'should transformContent() work' , async ( ) => {
9396 await compile ( '<view wx:for="{{items}}"> {{item}} </view>' , {
94- target : function Alipay ( ) { } ,
97+ target : target ( function Alipay ( ) { } ) ,
9598 transformContent : ( content ) => content . replace ( / \b w x : / , '🦄:' ) ,
9699 } ) ;
97100 expect ( getCompiledRes ( ) ) . toBe ( '<view 🦄:for="{{items}}"> {{item}} </view>' ) ;
@@ -100,15 +103,15 @@ describe('wxml-loader', () => {
100103 // DEPRECATED
101104 test ( 'should format() work' , async ( ) => {
102105 await compile ( '<view wx:for="{{items}}"> {{item}} </view>' , {
103- target : function Alipay ( ) { } ,
106+ target : target ( function Alipay ( ) { } ) ,
104107 format : ( content ) => content . replace ( / \b w x : / , '🦄:' ) ,
105108 } ) ;
106109 expect ( getCompiledRes ( ) ) . toBe ( '<view 🦄:for="{{items}}"> {{item}} </view>' ) ;
107110 } ) ;
108111
109112 test ( 'should transformUrl() work' , async ( ) => {
110113 await compile ( '<import src="/fixture.wxml" />' , {
111- target : function Alipay ( ) { } ,
114+ target : target ( function Alipay ( ) { } ) ,
112115 transformUrl : ( url ) => url . replace ( / f i x t u r e / , '🦄' ) ,
113116 } ) ;
114117 expect ( getCompiledRes ( ) ) . toBe ( '<import src="/🦄.wxml" />' ) ;
0 commit comments