1

从 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. 按照 es6 babel 配方的说明(在 docs 文件夹中找到)后,我运行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 41,firefox 44也是safari 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>
4

1 回答 1

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路径映射。为了确保项目正确构建wct,在 中的 gulp 任务gulpfile.js被注入了与任务相同的依赖gulp serve项。

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

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

于 2015-10-12T15:40:22.067 回答