如何使用网络元件测试仪测试用ES6 / ES2015编写的聚合物组件?

时间:2015-10-05 20:53:47

标签: polymer ecmascript-6 web-component-tester

从polymer-starter-kit 1.1.0开始,我将套件中的所有现有代码修改为ES6 / ES2015,包括以下内容:gulpfile.js, app.js, routing.html, my-greeting.html, my-list.html, my-greeting-basic.html and my-listing-basic.html。按照docs文件夹中的es6 babel配方的说明操作后,我运行gulp serve以验证应用程序是否正常运行,但是所有现有测试都失败并显示以下消息...

chrome 48                ✖ Test Suite Initialization

  Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

chrome 48                Tests failed: 2 failed tests

以上适用于chrome 41firefox 44safari 9.0以及

好像wct运行未编译的代码,我找不到任何允许wct gulp任务首先编译的选项,或者就此而言指向.tmpdist文件夹测试

这是一个修改过的例子......

<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../../bower_components/polymer/polymer.html">

<dom-module id="my-list">
  <template>
    <style>
      :host {
        display: block;
      }
    </style>
    <ul>
      <template is="dom-repeat" items="{{items}}">
        <li><span class="paper-font-body1">{{item}}</span></li>
      </template>
    </ul>
  </template>
  <script>
    (() => {
      'use strict';

      class MyList {

        beforeRegister() {
          let is = this.constructor.name
            .replace(/\W+/g, '-')
            .replace(/([a-z\d])([A-Z])/g, '$1-$2')
            .toLowerCase();

          this.is = is;

          this.properties = {
            items : {
              type   : Array,
              notify : true,
            }
          };
        }

        ready() {
          this.items = [
            'Responsive Web App boilerplate',
            'Iron Elements and Paper Elements',
            'End-to-end Build Tooling (including Vulcanize)',
            'Unit testing with Web Component Tester',
            'Routing with Page.js',
            'Offline support with the Platinum Service Worker Elements'
          ];
        }
      }

      Polymer(MyList);
    })();
  </script>
</dom-module>

1 个答案:

答案 0 :(得分:1)

在官方Polymer-Starter-Kit向Add ES2015 support through Babel文档添加文档,描述测试ES6 / ES2015代码的首选方法之前,我的fork Polymer-Starter-Kit已经修改了gulpfile.js和{ {1}}允许ES6 / ES2015元素,测试&amp;代码正确测试。

基本上,我将wtc.conf.js配置文件修改为指向wtc.conf.js而不是dist,以用于测试套件和app路径映射。为了确保项目正确构建,bower_components gulp任务在wct中注入了与gulpfile.js任务相同的依赖项。

免责声明 - 让我说我认为不是理想的方法,它只是一个临时的补丁解决方案,所以我可以继续使用测试和ES2015。 < / p>

我个人喜欢gulp serve目前不需要构建,使开发过程更加流畅和动态。也许,它可以在检测到ES2015时注入Babel浏览器支持。