Code Monkey home page Code Monkey logo

custom-elements-everywhere's Introduction

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.

custom-elements-everywhere's People

Contributors

adamhaile avatar agubler avatar antgonzales avatar arjunyel avatar atilacamurca avatar chasenlehara avatar dependabot[bot] avatar dntzhang avatar eps1lon avatar github-actions[bot] avatar jorgecasar avatar kbrsh avatar mattdsteele avatar paul-hebert avatar porsager avatar rarkins avatar renovate-bot avatar renovate[bot] avatar rich-harris avatar rickhanlonii avatar rictic avatar robdodson avatar ryansolid avatar thysultan avatar tomayac avatar vogloblinsky avatar webreflection avatar wolfadex avatar zaceno avatar zevdg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

custom-elements-everywhere's Issues

Dependency deprecation warning: babel-preset-es2015 (npm)

On registry https://registry.npmjs.org/, the "latest" version (v6.24.1) of dependency babel-preset-es2015 has the following deprecation notice:

๐Ÿ™Œ Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update!

Marking the latest version of an npm package as deprecated results in the entire package being considered deprecated, so contact the package author you think this is a mistake.

Affected package file(s): libraries/__shared__/webcomponents/package.json, libraries/angular/package.json, libraries/angularjs/package.json, libraries/canjs/package.json, libraries/dio/package.json, libraries/dojo2/package.json, libraries/hybrids/package.json, libraries/hyperhtml/package.json, libraries/litelement/package.json, libraries/mithril/package.json, libraries/polymer/package.json, libraries/preact/package.json, libraries/react/package.json, libraries/skate/package.json, libraries/surplus/package.json, libraries/svelte/package.json, libraries/vue/package.json

If you don't care about this, you can close this issue and not be warned about babel-preset-es2015's deprecation again. If you would like to completely disable all future deprecation warnings then add the following to your config:

"suppressNotifications": ["deprecationWarningIssues"]

TODO: Results changed PR bot

It'd be rad if a bot could compare the before/after results of every PR and sound the alarm if a library's scores have changed. On a few occasions I've seen libraries go to 0 either because of them shipping an upgrade that breaks the tests, or they themselves have actually shipped a bug and the tests caught it for them. Currently I manually check before each deploy but that's inefficient :P

Passing camelCase properties

It seems to me that libraries do not always appropriately handle camelCase property names the same way.

When using Vue and Svelte together, for example, I'm finding the only way to reliably pass properties is to use a single lowercase value such as textcolor instead of textColor.

However when using only Vue, it seems to pass and accept camelCased properties without issue.

Could this behavior be standardized?

Add test for setting properties with primitive values

Right now primitive values are allowed to be set as either an attribute or a property. Since properties and attributes are two separate APIs, custom elements could require that a value is passed in via one API or the other. I do think it's fairly common that there are properties not set from corresponding attributes.

There should be tests that set a property to a boolean|number|string|null|undefined and requires that the property is set, not the attribute.

Historical Test Data for Compatibility Milestones

I love the utility that custom-elements-everywhere.com provides to web developers, but the biggest issue with the test data is that it only shows the current versions of each framework.

Not all developers are fortunate enough to be using the latest releases of each framework, so it would be extremely useful to be able to view test results for older versions.

It wouldn't need to be exhaustive, but it would need to at least have results for compatibility milestones (last failing vs first passing).

Add a test to render a <template>'s contents

I'm working on a project where we integrate web components into a web application using the preact framework. For the most part, the issues this site have raised have proven applicable and been very helpful in steering the way we design the application.

One aspect that took me by surprise, though, is that there may be an issue when a custom element uses template tags in the light children area. In particular, I encountered issues with the Vaadin Grid, which uses inner templates to define the columns. Something seemed to go wrong in the way the JSX/h engine generated these teplate tags.

It's a little hard to explain what I was seeing. It was like the template tags weren't quite inert, and the inside of the template turned into strings. Or something. I do think there's an issue here.

Missing the framework's version

This is really cool! Thanks for the detailed write ups!


That being said...

I would expect to see which version of React was tested in the test results.

For example, React 15.6.1

Otherwise the results will become stale and no one will know.

Add Aurelia

I've been successfully using Aurelia with custom elements for some time now. I would like to attempt a PR for adding Aurelia. Would that be something that is wanted?

Cover Salesforce "Lightning Web Components"

It would be great to cover Saleforce "Lightning Web Components", which are claimed to be based on web standards but in practice completely fail all interoperability criteria, if for no other reason than to shame Salesforce.

What about producing custom elements?

While listing which libraries work with custom elements is extremely useful, I'd also like to know which frameworks can produce custom elements. Would this be a useful advanced test?

Adding complexity is that some frameworks have third party libraries that do this, (example: convert react to web components), should something like this be included?

If there's support, I'd be interested in helping write the tests, etc. Thanks!

Test for <slot> (named and unnamed)

I'm the maintainer of a large private custom element library at work and we we're very excited to see Svelte move to 100% passing tests recently. Several pilot projects had been done with Svelte and finally we adopted it for use in official applications based in part on the fantastic information in this repository.

A few weeks after adoption we discovered Svelte isn't fully compatible with custom elements because of a conflicting "named slot" implementation. We have worked around the issue temporarily, but since slot (or "content projection" in framework nomenclature) is a major function of both custom elements and frameworks I thought a test for would be good to add here.

A related Svelte issue has already been reported by @therealnicksaunders here:

sveltejs/svelte#1689

Accessibility: Repetitive heading structure for screen readers

Hey, thanks for the awesome site! This has been super useful for some web components research I've been doing!

I noticed one issue that could potentially make the site difficult to navigate for screen reader users (or search engine crawlers).

Screen reader users can navigate the page by jumping to headings (h1, h2, h3, etc.) For example, in VoiceOver you can use the "rotor" feature to get a list of all headings on the page and then jump to a specific heading based on it's text. This can be a very quick way to navigate the page.

For example imagine a screen reader user was interested in compatibility between React and web components. They hit the home page, open the rotor, and search for a heading containing the text "React." This is the heading structure they see instead:

H1 โ€” Custom Elements Everywhere 
H2 โ€” Making sure frameworks and custom elements can be BFFs ๐Ÿป 
H2 โ€” What's this? 
H4 โ€” Handling data 
H4 โ€” Handling events 
H3 โ€” Related Issues 
H4 โ€” Yay! No open issues! 
H4 โ€” Handling data 
H4 โ€” Handling events 
H3 โ€” Related Issues 
H4 โ€” Yay! No open issues! 
H4 โ€” Handling data 
H4 โ€” Handling events 
H3 โ€” Related Issues 
H4 โ€” Handling data 
H4 โ€” Handling events 
H3 โ€” Related Issues 
H4 โ€” Yay! No open issues! 
H4 โ€” Handling data 
H4 โ€” Handling events 
H3 โ€” Related Issues 
H4 โ€” Yay! No open issues! 
H4 โ€” Handling data 
H4 โ€” Handling events 
H3 โ€” Related Issues 
H4 โ€” Yay! No open issues! 
H4 โ€” Handling data 
H4 โ€” Handling events 
H3 โ€” Related Issues 
H4 โ€” Yay! No open issues! 
H4 โ€” Handling data 
H4 โ€” Handling events 
H3 โ€” Related Issues 
H4 โ€” Handling data 
H4 โ€” Handling events 
H3 โ€” Related Issues 
H4 โ€” Handling data 
H4 โ€” Handling events 
H3 โ€” Related Issues 
H4 โ€” Handling data 
H4 โ€” Handling events 
H3 โ€” Related Issues 
H4 โ€” Handling data 
H4 โ€” Handling events 
H3 โ€” Related Issues 
H4 โ€” Yay! No open issues! 
H4 โ€” Handling data 
H4 โ€” Handling events 
H3 โ€” Related Issues 
H4 โ€” Handling data 
H4 โ€” Handling events 
H3 โ€” Related Issues 
H4 โ€” Yay! No open issues! 
H4 โ€” Handling data 
H4 โ€” Handling events 
H3 โ€” Related Issues 
H4 โ€” Yay! No open issues! 
H4 โ€” Handling data 
H4 โ€” Handling events 
H3 โ€” Related Issues 
H4 โ€” Yay! No open issues! 
H4 โ€” Handling data 
H4 โ€” Handling events 
H3 โ€” Related Issues 
H4 โ€” Yay! No open issues! 
H2 โ€” Frequently Asked Questions 
H3 โ€” What are these custom element things? 
H3 โ€” Are you testing that libraries let you author custom elements? 
H3 โ€” Why is each test counted twice? 
H3 โ€” How are the libraries scored? 
H3 โ€” How are basic and advanced tests different? 
H3 โ€” I thought the whole point of Polymer was to write custom elements. Why doesn't it get a 100%? 
H3 โ€” If a library is missing a feature, like declarative event or property bindings, does it automatically fail those tests? 
H3 โ€” Why don't you have tests for _____ library? 
H3 โ€” I want to write some tests for _____ library. Do you accept pull requests? 

This was output by running this snippet on the home page:

[...document.querySelectorAll('h1, h2, h3, h4, h5, h6')].forEach(heading => {
  console.log(`${heading.tagName} โ€” ${heading.innerText}`)
});

As you can see, it would be difficult to find information about React using the rotor heading navigation strategy. Instead they'd need to search the page for a string containing "react" or read through the full document.

Similarly search engines use headings to determine and catalogue page content. If the headings do not describe the content well it can be difficult for search engines to understand the content.

I think each framework section should likely have a heading structure like this instead:

H3 โ€” React
H4 โ€” Handling data 
H4 โ€” Handling events 
H4 โ€” Related Issues 

Ideally this change would be made without any visual changes by using CSS to maintain the current styles and layout.

Let me know what you think. I could spend some time putting together a PR if this is something you're interested in.

Thanks!

Which version of hyperHTML should we report?

@WebReflection The site displays the library version under test:

image

However, with hyperhtml we're actually entirely using hyperhtml-element now, instead of hyperhtml itself. Would you rather show the hyperhtml version or the hyperhtml-element version?

Upgrading Elements

Should there be a test that covers upgrading elements? Just wondering if the custom element is defined after the framework/library renders the output how

It appears that this currently does not work for Preact props and might be an issue for others.

Dependency Dashboard

This issue provides visibility into Renovate updates and their statuses. Learn more

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • Pin dependencies (@babel/core, @babel/preset-env, @babel/preset-react, @webcomponents/webcomponentsjs, babel-loader, chai, copy-webpack-plugin, karma, karma-chrome-launcher, karma-firefox-launcher, karma-webpack, preact, react, react-dom, webpack)
  • Update babel monorepo (@babel/core, @babel/plugin-transform-runtime, @babel/preset-env, @babel/preset-react, babel-loader)
  • Update dependency rxjs to v7.5.1

Other Branches

These updates are pending. To force PRs open, click the checkbox below.

  • Update dependency https-proxy-agent to 2.2.3 [SECURITY]
  • Update dependency node-fetch to 2.6.1 [SECURITY]
  • Update dependency trim-newlines to 3.0.1 [SECURITY]

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.


  • Check this box to trigger a request for Renovate to run again on this repository

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (github>whitesource/merge-confidence:beta)

Add test to emit custom event

I'm currently encountering a problem with svelte and I think it could be interesting to know if other framework has this caveat.

The goal of the test is to see if a custom element produced by a framework can emit a CustomEvent.

<my-element></my-element>
<script>
document.querySelector('my-element').addEventListener('myevent', function (e) {

});
</script>

The sentence would be

  • The library/framework should be able to dispatch DOM events from a custom element. These DOM events could be listened from the outside.

LitElement Handling Data section is not acurate

LitElement will pass data to an element as properties, as long as the property is defined on the element's prototype. Otherwise it will fallback to passing data as attributes.

I just asked on the LitElement slack and this is not true. lit-html uses attributes by default and has an alternate syntax to explicitly pass a property instead, just like Vue.

P.S. Historically, this one the other way around (properties by default and special syntax to explicitly specify attributes). This was changed in lit-html 0.11 via lit/lit#398

Test with preact-compat

Maybe there's some obvious reason why it isn't needed, but it isn't obvious to me due to my murky understanding -- would it make sense to also test preact with the preact-compat react compatibility layer?

I mean as a separate test. Testing without it is probably more useful. But would be good to know if anything negative happens when the compatibility layer is needed.

Add stenciljs

Similar to #12, stenciljs outputs custom elements now so let's see if they comply with the tests. We'd be looking to check how they handle attributes and properties, events, etc. We know stencil doesn't use shadow dom so there would be a few test failures there I think, but good to identify and track all of this stuff, especially as stencil evolves.

Shared tests

Going through the tests, it seemed like there were some (small) disparities between some of the libraries. This dojo test in particular caught my eye.

If the tests were shared, it would give a level of consistency across the tests. It would also make it easier to add new tests/fix tests (if necessary) and to add new libraries to the repo. It might even be useful to export the tests so that libraries could add them to their own test suites.

I'm thinking providing a light adaptor for each framework would be enough.

Take a look at this example for Preact:
https://gist.github.com/mlrawlings/1a14ddf446ca9787da7e378bc80f9a0c
conceptually, it should work, but I haven't actually run the code

Thoughts?

JSDom

I'd love to see JSDom's support on the page.

Update babel-preset-es2015 to babel-preset-env

Several libraries are outputting the following during npm install:

npm WARN deprecated [email protected]: ๐Ÿ™Œ Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update!

Each project should be updated to remove this recommendation warning.

Preact X

Preact X (10) is out, seems like it has fixed some issues in compatibility.

Maybe it is worth to update the version?

I can do it, if you are not against

Upgrade hyperHTML to 2.0

@WebReflection I tried updating to 2.0.6 but noticed all the tests failed because

import {hyper} from 'hyperhtml'

no longer works. The docs mention that hyper is still an exported function so I must be doing something wrong with my use of modules. Any ideas?

Add Ember.js

I've been doing some work with Ember + WebComponents lately and support, in the latest version, is actually pretty good. I would love to get this reflected in your site! I can look into making a PR that adds tests for Ember, but it may be tricky since Ember is tightly coupled to its own build tools.

Dependency deprecation warning: @dojo/interfaces (npm)

On registry https://registry.npmjs.org/, the "latest" version (v0.2.1) of dependency @dojo/interfaces has the following deprecation notice:

@dojo/interfaces is deprecated

Marking the latest version of an npm package as deprecated results in the entire package being considered deprecated, so contact the package author you think this is a mistake.

Affected package file(s): libraries/dojo2/package.json

If you don't care about this, you can close this issue and not be warned about @dojo/interfaces's deprecation again. If you would like to completely disable all future deprecation warnings then add the following to your config:

"suppressNotifications": ["deprecationWarningIssues"]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.