【问题标题】:how do you test polymer components written in ES6/ES2015 with web-component-tester?你如何使用 web-component-tester 测试用 ES6/ES2015 编写的聚合物组件?
【发布时间】:2015-10-12 23:40:22
【问题描述】:

从 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>

【问题讨论】:

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


    【解决方案1】:

    直到官方的 Polymer-Starter-Kit 将文档添加到 Add ES2015 support through Babel 文档中,描述了测试 ES6/ES2015 代码的首选方法,我的 fork Polymer-Starter-Kit 具有修改后的 gulpfile.jswtc.conf.js,它允许 ES6/正确测试的 ES2015 元素、测试和代码。

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

    免责声明 - 我认为这不是理想的方法,它只是一个临时补丁解决方案,因此我可以继续使用测试和 ES2015。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-27
      • 1970-01-01
      • 2017-02-25
      • 2016-04-06
      • 1970-01-01
      • 2014-09-19
      相关资源
      最近更新 更多