Skip to content

Commit ad7af4a

Browse files
authored
Migrate to web-test-runner (#318)
web-test-runner replaces web-component-tester https://modern-web.dev/docs/test-runner/overview/
1 parent 664ea00 commit ad7af4a

12 files changed

+6612
-20622
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
node_modules
22

33
**/*.d.ts*
4-
!test/wct.d.ts
54
**/*.js*
5+
6+
!*.config.js

package-lock.json

+6,569-20,497
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+9-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"build:watch": "tsc --watch",
3636
"start": "web-dev-server --app-index demo/index.html --node-resolve --open --watch",
3737
"pretest": "npm run build",
38-
"test": "wct --module-resolution=node --npm --simpleOutput -l chrome"
38+
"test": "web-test-runner",
39+
"test:watch": "web-test-runner --watch"
3940
},
4041
"contributors": [
4142
"Wes Alvaro",
@@ -47,15 +48,16 @@
4748
"lit-element": "^3.0.0"
4849
},
4950
"devDependencies": {
51+
"@esm-bundle/chai": "^4.3.4-fix.0",
52+
"@open-wc/testing": "^2.5.33",
5053
"@polymer/decorators": "^3.0.0",
5154
"@polymer/polymer": "^3.4.1",
52-
"@types/chai": "^4.2.11",
5355
"@types/google.visualization": "0.0.68",
54-
"@types/mocha": "^7.0.2",
55-
"@web/dev-server": "^0.1.24",
56-
"typescript": "^4.4.3",
57-
"wct-browser-legacy": "^1.0.2",
58-
"web-component-tester": "^6.9.2"
56+
"@types/mocha": "^9.0.0",
57+
"@web/dev-server": "^0.1.25",
58+
"@web/test-runner": "^0.13.20",
59+
"sinon": "^11.1.2",
60+
"typescript": "^4.4.4"
5961
},
6062
"typings": "google-chart.d.ts"
6163
}

test/basic-tests.html

-26
This file was deleted.

test/basic-tests.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,20 @@
1515
* limitations under the License.
1616
*/
1717

18+
import {assert} from '@esm-bundle/chai';
19+
import {fixture} from '@open-wc/testing';
1820
import {timeOut} from '@polymer/polymer/lib/utils/async.js';
1921
import {Debouncer} from '@polymer/polymer/lib/utils/debounce.js';
22+
import {spy, SinonSpy} from 'sinon';
2023
import {GoogleChart} from '../google-chart.js';
2124
import {dataTable, load, DataTableLike} from '../loader.js';
2225
import {ready} from './helpers.js';
2326

24-
const assert = chai.assert;
25-
2627
suite('<google-chart>', function() {
2728
var chart: GoogleChart;
2829
var waitCheckAndDoneDebouncer: Debouncer|null;
29-
setup(function() {
30-
chart = fixture('chart-fixture') as GoogleChart;
30+
setup(async function() {
31+
chart = await fixture('<google-chart></google-chart>') as GoogleChart;
3132
waitCheckAndDoneDebouncer = null;
3233
});
3334
var waitCheckAndDone = function(check: () => unknown, done: () => void) {
@@ -124,7 +125,7 @@ suite('<google-chart>', function() {
124125
var initialDraw = true;
125126
chart.addEventListener('google-chart-ready', function() {
126127
if (initialDraw) {
127-
spyRedraw = sinon.spy(chart['chartWrapper']!, 'draw');
128+
spyRedraw = spy(chart['chartWrapper']!, 'draw');
128129
initialDraw = false;
129130
const options = chart.options as google.visualization.ColumnChartOptions;
130131
options.title = 'Debounced Title';
@@ -176,7 +177,7 @@ suite('<google-chart>', function() {
176177
let chart: GoogleChart;
177178
let dt: google.visualization.DataTable;
178179
setup(async () => {
179-
chart = fixture('chart-fixture') as GoogleChart;
180+
chart = await fixture('<google-chart></google-chart>') as GoogleChart;
180181
dt = await dataTable(undefined);
181182
dt.addColumn('number', 'x');
182183
dt.addColumn('number', 'y');
@@ -289,17 +290,17 @@ suite('<google-chart>', function() {
289290
done();
290291
});
291292
load().then(() => {
292-
const q = new google.visualization.Query('query.json');
293+
const q = new google.visualization.Query('test/query.json');
293294
q.send((res) => {
294295
chart.data = res.getDataTable();
295296
});
296297
});
297298
});
298299
test('[data] is JSON URL for 2D Array', function(done) {
299-
setDataAndWaitForRender('test-data-array.json', done);
300+
setDataAndWaitForRender('test/test-data-array.json', done);
300301
});
301302
test('[data] is JSON URL for DataTable Object format', function(done) {
302-
setDataAndWaitForRender('test-data-object.json', done);
303+
setDataAndWaitForRender('test/test-data-object.json', done);
303304
});
304305
test('[view] is DataView', function(done) {
305306
chart.addEventListener('google-chart-ready', function() {
@@ -314,8 +315,8 @@ suite('<google-chart>', function() {
314315
});
315316
});
316317
test('multiple calls to JSON URL', function(done) {
317-
setDataAndWaitForRender('test-data-array.json', function() {
318-
setDataAndWaitForRender('test-data-object.json', done);
318+
setDataAndWaitForRender('test/test-data-array.json', function() {
319+
setDataAndWaitForRender('test/test-data-object.json', done);
319320
});
320321
});
321322
});

test/custom-load-test.html

+1-10
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,5 @@
1515
limitations under the License.
1616
-->
1717
<html lang="de">
18-
<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
19-
<script src="../node_modules/wct-browser-legacy/browser.js"></script>
20-
21-
<test-fixture id="type-table">
22-
<template>
23-
<google-chart type="table"></google-chart>
24-
</template>
25-
</test-fixture>
26-
27-
<script type="module" src="custom-load-test.js"></script>
18+
<script type="module" src="custom-load.js"></script>
2819
</html>

test/custom-load-test.ts test/custom-load.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
* limitations under the License.
1616
*/
1717

18+
import {assert} from '@esm-bundle/chai';
19+
import {fixture} from '@open-wc/testing';
20+
import {runTests} from '@web/test-runner-mocha';
1821
import '../google-chart.js';
1922
import {GoogleChart} from '../google-chart.js';
2023
import {load} from '../loader.js';
2124
import {ready} from './helpers.js';
2225

23-
const assert = chai.assert;
24-
2526
// This test has to run separately in a clean document because Google Charts
2627
// API is loaded only once per document.
28+
runTests(() => {
2729
suite('Custom load', () => {
2830
suiteSetup(() => {
2931
// Ensure Google Charts is not loaded.
@@ -40,10 +42,11 @@ suite('Custom load', () => {
4042
});
4143

4244
test('loads packages for chart type="table"', async () => {
43-
const chart = fixture('type-table') as GoogleChart;
45+
const chart = await fixture('<google-chart type="table"></google-chart>') as GoogleChart;
4446
chart.data = [ ['Data', 'Value'], ['Something', 1] ];
4547
await ready(chart);
4648
const chartDiv = chart.shadowRoot!.getElementById('chartdiv')!;
4749
assert.isAbove(chartDiv.childElementCount, 0);
4850
});
4951
});
52+
});

test/index.html

-31
This file was deleted.

test/polymer-use-test.html

-20
This file was deleted.

test/polymer-use-test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
*/
1717

1818
import '../google-chart.js';
19+
import {assert} from '@esm-bundle/chai';
1920
import {customElement, property} from '@polymer/decorators';
2021
import {PolymerElement, html} from '@polymer/polymer';
2122
import {GoogleChart} from '../google-chart.js';
2223
import {DataTableLike} from '../loader.js';
2324
import {ready} from './helpers.js';
2425

25-
const assert = chai.assert;
26-
2726
suite('<google-chart> use in Polymer element', () => {
2827
let element: GoogleChartTestElement;
2928

test/wct.d.ts

-14
This file was deleted.

web-test-runner.config.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// https://modern-web.dev/docs/test-runner/cli-and-configuration/
2+
export default {
3+
files: 'test/**/*test*.(html|js)',
4+
nodeResolve: true,
5+
testFramework: {
6+
// https://mochajs.org/api/mocha
7+
config: {
8+
ui: 'tdd',
9+
timeout: '20000', // default 2000
10+
},
11+
},
12+
};

0 commit comments

Comments
 (0)