• Stars
    star
    1,169
  • Rank 39,968 (Top 0.8 %)
  • Language
    JavaScript
  • License
    Other
  • Created about 7 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Custom Element + Framework Interoperability Tests.

Custom Elements Everywhere 🍻

What is this?

Karma tests for each of the major frameworks to see how they handle working with Custom Elements.

Build Status Renovate enabled

Installation

To install all dependencies and build the site:

# Install all the things!
npm ci

# Test all the things!
npm run build

# Preview the site.
npm start

Current List of Libraries/Frameworks

How do I add a library/framework to the project?

Step 1. Copy an existing example

Tests for each library/framework live in the libraries/ directory. The easiest way to start is by copying the test directory from a project that is similar to your own. For example, if the library you use is similar to React/Preact, you might start by copying and renaming the libraries/preact directory.

Your library structure should look like this:

β”œβ”€β”€ .babelrc
β”œβ”€β”€ karma.conf.js
β”œβ”€β”€ meta
β”‚Β Β  β”œβ”€β”€ issues.json
β”‚Β Β  └── summary.md
β”œβ”€β”€ package-lock.json
β”œβ”€β”€ package.json
β”œβ”€β”€ src
β”‚Β Β  β”œβ”€β”€ advanced-tests.js
|   β”œβ”€β”€ basic-tests.js
β”‚Β Β  └── components.js
└── tests.webpack.js

package.json

Your package.json should contain build and test npm scripts. The test script is in charge of actually running karma. The test script should set a variable, LIBRARY_NAME, that corresponds to your library's npm package name. This is used during the build process to grab the library's semver and publish it on the site.

Example:

"scripts": {
  "test": "cross-env LIBRARY_NAME=@angular/core karma start",
  "build": "npm run test"
},

karma.conf.js

Your Karma configuration. Ideally you shouldn't need to change much in here. The config file uses karma-webpack, so there is a webpack property where you can essentially write your webpack.config.js. You'll need to change this property to tell it how to bundle your library.

meta/

This directory contains issues.json where you list any open GitHub issues related to custom element support in your library. There is also a summary.md where you write a short description of how the library interacts with custom elements and any known quirks or gotchas.

src/

This directory contains components.js where you create library/framework components which try to communicate with custom elements. You then test these components in basic-tests.js and advanced-tests.js. You'll want to use all of the assertions in the test files but update the actual test implementations to use your library's components.

Note that all frameworks use the custom elements in the /libraries/__shared__/webcomponents/ directory for tests.

tests.webpack.js

This file is consumed by the test runner and tells it to import any files ending in -test. You probably won't need to change this file.

Step 2. Add npm scripts

In the root of the project you'll need to add a couple of npm scripts to make sure your library builds with the rest of the site. You should be able to copy an example from one of the other libraries.

  • In the root of the project, Add an install-* script to package.json and run it during the install script.
  • In the libraries/[your library]/ director, update the build script in package.json to include your library's name.

There's a test runner called index.js that lives in the root of the project. It will detect when you've added a new folder to libraries/ and attempt to run that folder's build command.

Step 3. Run update-goldens

In the root of the project, run npm run update-goldens. This will generate an expectedResults.json file for your library's tests.

This way any change that results in a different summary score for any library shows up in code review, and any change that would accidentally change the summary score will make the tests fail.

What kind of behavior do the tests assume?

  • The library/framework should be able to display elements that use shadow DOM, insert children in them, and handle hiding and showing them.
  • The library/framework should be able to pass primitive data (strings, numbers, booleans) to a custom element as either attributes or properties.
  • The library/framework should be able to pass rich data (objects, arrays) to a custom element using properties.
  • The library/framework should be able to listen to DOM events from a custom element. These DOM events could use any casing style.

How does the site get deployed/maintained?

Any PR landed to the main branch will trigger an automatic publish to GitHub pages.

License

Copyright 2017 Google, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

More Repositories

1

webcomponentsjs

A suite of polyfills supporting the HTML Web Components specs
HTML
3,874
star
2

polyfills

Web Components Polyfills
HTML
1,137
star
3

gold-standard

1,029
star
4

webcomponents.github.io

WebComponents.org is where community-members document Web Components best practices
JavaScript
734
star
5

custom-elements

A polyfill for HTML Custom Elements v1
HTML
455
star
6

polymer-boilerplate

Fork this repo if you want to start your own Web Component using Polymer
HTML
369
star
7

webcomponents.org

Home of the web components community
TypeScript
366
star
8

custom-elements-manifest

A file format for describing custom elements
TypeScript
365
star
9

react-integration

Converts web components into React components so that you can use them as first class citizens in your React components.
JavaScript
306
star
10

element-boilerplate

Fork this repo if you want to start your own Web Component using VanillaJS
HTML
271
star
11

shadycss

HTML
197
star
12

shadydom

ShadowDOM v1 shim
HTML
162
star
13

hello-world-element

Web Component example using VanillaJS
HTML
151
star
14

chrome-webcomponents-extension

Google Chrome extension to identify all Custom Elements used on a site
JavaScript
81
star
15

html-imports

HTML Imports polyfill
HTML
73
star
16

angular-interop

A demo of interoperability between Polymer and AngularJS
TypeScript
72
star
17

template

Minimal polyfill for <template>
HTML
69
star
18

hello-world-polymer

Web Component example using Polymer
HTML
58
star
19

xtag-boilerplate

Fork this repo if you want to start your own Web Component using X-Tag
HTML
52
star
20

sass-interop

A demo of interoperability between Sass and Polymer
CSS
46
star
21

slush-element

Slush generator to create Custom Elements using Polymer, X-Tag or VanillaJS
JavaScript
41
star
22

webcomponents-icons

Collection of high resolution Web Components icons for presentations, blog posts or whatever
CSS
40
star
23

template-shadowroot

TypeScript
38
star
24

community

A space for the webcomponents community
JavaScript
26
star
25

hello-world-xtag

Web Component example using X-Tag
HTML
24
star
26

webcomponents-platform

Very minimal platform related polyfills
JavaScript
23
star
27

less-interop

A demo of interoperability between Less and Polymer
CSS
20
star
28

webcomponents-lite

Web Components Polyfills minus Shadow DOM
JavaScript
16
star
29

wc-catalog

11
star
30

custom-elements-manifest-tools

Tools for working with custom elements manifests
TypeScript
7
star
31

apply-shim

Shim for CSS @apply mixins
JavaScript
5
star
32

.allstar

1
star