afterwind-io / preprocessor-loader

Bring the awesome "Conditional Compilation" to the Webpack, and more.
MIT License
40 stars 12 forks source link

稍微负责的页面,你的testCase就通不过了,Full Test,javascript改为如下代码,就报错 #3

Closed brainee closed 5 years ago

brainee commented 5 years ago

'use strict';

import React, { Component } from 'react'; import { StyleSheet, Text, View, MapView, TouchableHighlight, TouchableOpacity, ScrollView, ListView } from 'react-native';

// import test from 'test'; // console.log('test', test);

let a = 1; // ...this line may be omitted. // #!debug a=2; console.log("-----------a=",a);

const localAssets = { // iconArrow: require('navigator/asset/icon_arrow.png'), // iconArrow: require('../asset/icon_arrow.png'), }; // let lazyModule =lazyRequire('./Page2.js'); // lazyModule.onModuleLoaded(function (module) { // console.log('3@@@@@@@@@@@@@@@@@@@',module); // }); // // setTimeout(function(){ // let module = lazyModule.load(); // console.log('4@@@@@@@@@@@@@@@@@@@',module); // // }, 3000);

let ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => { return (r1.titleExtend != r2.titleExtend || r1.bizType != r2.bizType || r1.isFavoriteExtend !== r2.isFavoriteExtend) }, sectionHeaderHasChanged: (s1, s2) => { return s1 !== s2 }, getSectionHeaderData: (dataBlob, sectionID) => { return DataManage.getSectionHeaderName(sectionID); } });

export default class Page1 extends Page { constructor(props) { super(props); this.state = { dataSource: ds.cloneWithRows(['John', 'Joel', 'James', 'Jimmy', 'Jackson', 'Jillian', 'Julie', 'Devin', "9", "10", "11 "]), // dataSource: ds.cloneWithRowsAndSections(['John', 'Joel', 'James', 'Jimmy', 'Jackson', 'Jillian', 'Julie', 'Devin']), loadState: 'normal', // 加载状态 normal-默认、loading-加载中、failed-加载失败、done-加载完成 };

    // fetch("https://sec-m.ctrip.com/restapi/soa2/10245/json/GetMonitoring?_rm=0.8329076717428225")
    // <LoadingFailedView />
}
render() {

    console.log('page1:render');

    return (
        <ViewPort>
            <View style={styles.container}>
                {undefined}

                <ListView
                    style={{ flex: 1 }}
                    dataSource={this.state.dataSource}
                    renderRow={this.renderRow.bind(this)}

                    onEndReached={this.onLoadMore.bind(this)}
                    onEndReachedThreshold={300}
                    renderFooter={this.renderFooter.bind(this)}
                    pageSize={10}
                />
                <Button
                    onPress={() => {
                        var img="";
                        img = require('navigator/asset/icon_arrow.png');
                        this.push('page2', { img });
                    }}
                    style={styles.button}>
                    Back to Page2
                    </Button>
                <Button onPress={() => this._getLocation()} style={styles.button}>
                    点击定位
                    </Button>
                <div {...this.props}>{undefined}{[undefined, <View>444</View>, undefined]}  333</div>
            </View>
        </ViewPort>
    );
}
_getLocation() {
    Location.locate({
        locateLevel: 0,
        timeout: 10000,
        isForceLocate: true // 是否强制定位
        //
    }).then(
        (data) => {
            console.log("-----success located:", data);
        }
        ).catch(
        (err) => {
            console.log("--------locate failed:", err);
        }
        );
}

renderRow(rowData, sectionID, rowID) {

    if (!window.t1) {
        window.t1 = rowData;
    }
    return (
        <Text>Row data:{rowData}</Text>
    )
}
onLoadMore() {
    console.log('onLoadMore');
}
renderFooter() {
    console.log('renderFooter');
    return (<div>renderFooter</div>);
}
renderSeparator() {
    // renderSeparator={this.renderSeparator.bind(this)}
    // renderSectionHeader={this.renderSectionHeader.bind(this)}

    console.log('renderSeparator');
    return (<div>renderSeparator</div>);
}
renderSectionHeader() {
    console.log('renderSectionHeader');
    return (<div>renderSectionHeader</div>);
}

componentWillUnmount() {
    // tp('Page1 componentWillUnmount')
    // super.componentWillUnmount&&super.componentWillUnmount()
    // this.unmounted = true;
}

}

const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, welcome: { fontSize: 20, textAlign: 'center', margin: 10, }, instructions: { textAlign: 'center', color: '#333333', marginBottom: 5, }, button: { "backgroundColor": "red" }, fillStyle: { backgroundColor: 'red' }, backgroundStyle: { backgroundColor: 'orange', borderRadius: 1 }, ProgressBar1: { "marginTop": 20, "width": 200 } });

afterwind-io commented 5 years ago

@brainee 我把你的代码替换至测试文件case_javascript.js下能正常跑通Full test-Javascript部分,代码19、20行也能正常隐藏。

如果之前你在本地自行测试的话,请注意每个测试文件会导出两个常量。其中一个为C_JS,代表测试用例;另一个为R_JS,代表预期结果。你需要将C_JS中的代码替换为自己的代码,同时需要将预期的结果替换至R_JS的之中。在黏贴代码时需要注意多余的末尾空行,因为preprocessor不会处理空行,在测试比对时可能会导致报错。

p.s. 友情提醒,提交Issue时请关注下代码格式。