您如何使用 web-component-tester 测试用 ES6/ES2015 编写的聚合物组件?
how do you test polymer components written in ES6/ES2015 with 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
。按照 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 41
、firefox 44
和 safari 9.0
也是如此
似乎 wct 运行未编译的代码,我找不到任何允许 wct gulp 任务首先编译的选项,或者就此而言指向 .tmp
或 dist
要测试的文件夹。
这里是修改后的例子之一...
<!--
@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, '-')
.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-Starter-Kit 添加文档到 Add ES2015 support through Babel document, describing the prefered method of testing ES6/ES2015 code, my fork Polymer-Starter-Kit 修改了 gulpfile.js
和 wtc.conf.js
允许 ES6/ES2015 元素、测试和代码测试正确。
基本上我修改了 wtc.conf.js
配置文件以指向 dist
而不是 app
用于测试套件和 bower_components
路径映射。为了确保项目正确构建,gulpfile.js
中的 wct
gulp 任务注入了与 gulp serve
任务相同的依赖项。
免责声明 - 让我说我认为这不是理想的方法,它只是一个临时的补丁解决方案,所以我可以继续进行测试和ES2015.
我个人喜欢 WTC
目前不需要构建,使开发过程更加流畅和动态。也许,它可以在检测到 ES2015 时注入 Babel 浏览器支持。
从 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 配方(在文档文件夹中找到)的说明进行操作后,我 运行 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 任务首先编译的选项,或者就此而言指向 .tmp
或 dist
要测试的文件夹。
这里是修改后的例子之一...
<!--
@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, '-')
.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-Starter-Kit 添加文档到 Add ES2015 support through Babel document, describing the prefered method of testing ES6/ES2015 code, my fork Polymer-Starter-Kit 修改了 gulpfile.js
和 wtc.conf.js
允许 ES6/ES2015 元素、测试和代码测试正确。
基本上我修改了 wtc.conf.js
配置文件以指向 dist
而不是 app
用于测试套件和 bower_components
路径映射。为了确保项目正确构建,gulpfile.js
中的 wct
gulp 任务注入了与 gulp serve
任务相同的依赖项。
免责声明 - 让我说我认为这不是理想的方法,它只是一个临时的补丁解决方案,所以我可以继续进行测试和ES2015.
我个人喜欢 WTC
目前不需要构建,使开发过程更加流畅和动态。也许,它可以在检测到 ES2015 时注入 Babel 浏览器支持。