npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@orcden/od-component-test-suite

v2.1.8

Published

OrcDen Component Test Suite

Downloads

18

Readme

OD Component Test Suite

A set of universal component tests in TestCafe.

The OD Component Test Suite runs a series of tests on your agnostic components. Based on basic symantic HTML behaviours, it ensures your components behave as they should.

Features

  • Simple Configuration
  • Easy Execution
  • Built-In TestCafe Selectors and 'Custom DOM Properties'
  • Automatically Tests:
    • Webcomponents Support
    • Shadow DOM Support
    • Property Types
    • Property Behaviours
    • Attribute Behaviours
    • More...

Proposal

Creating Webcomponents comes with many challenges; especially so when designed to be agnostic of any particular framework. Some libraries attempt to alleviate these challenges by providing a stricter set of rules to adhere to and wider selection of basic features while developing said components; implementing the required behaviour behind the scenes. Many of these libraries offer simple patterns to allow for easy data-binding and DOM rendering.

The advantages of this appraoch cannot be denied; faster development, easier to read code, etc. However it also comes with some disadvantages for more complex components and ones designed to be agnostic of any given framework. Since web development tends to grow rapidly a need to support compatibility with older libraries could be required while transitioning to new technologies. The authors of said libraries may have moved on or dropped support entirely, forcing developers to find workarounds, find new solutions, or wait patiently for a fix. Additionally, the stricter set of rules may actually impose limitations on the devopler while attempting more complex features or DOM manipulation.

Given the balancing act of relying on external frameworks and dependencies many devolopers in the Webcomponents space have started opting to design completely agnostic components from the ground up. Built on the new Webcomponents spec, developers are able to extend HTMLElement directly and leave compatibility issues to a supported polyfill until browsers are fully up to date with the spec. The downside being the loss of many built in behaviours and ease-of-use development features.

Instead of creating a new framewwork 'flavour-of-the-month' we believe the solution lies in test-driven development. Frontend testing frameworks are quickly becoming more popular and in some cases neccessary. Cross-browser compatibility and behaviour are of the utmost importance, and for larger organizations consistency of code and stable build pipelines means that most have already implemented some form of frontend testing already.

This Component Test Suite for TestCafe is designed to execute a series of configurable tests on your components, agnostic or otherwise. The goal being that your custom components operate as close to semantic HTML elements as possible. This will empower developers to maintain complete control of their code and not have to rely on external component-building libraries if they do not desire, while targeting a consistent set of component behaviours and interoperability.

Why Testcafe?

TestCafe is perfectly positioned at this time to provide cross-browser testing solutions and it is because of that this library uses testcafe first and foremost. As other frontend testing frameworks add support for more browser testing it is our hope to add that functionality here as well.

Installation

  • Install with npm
npm i @orcden/od-component-test-suite --save-dev

Example Basic Usage

See TestCafe for setting up a set of tests, then in your testfile:

import { TestCafeComponentTestSuite } from '../../../node_modules/@orcden/od-component-test-suite';
const _config = {
    testServer: 'http://localhost:8079',
    name: 'OD Top Button',
    tag: 'od-top-button',
    componentSelector: '#top-button',
    hasShadow: true,
    shadowSelector: '#top-button',
    properties: [
        {
            name: 'active',
            type: Boolean,
            default: false,
            attributeName: 'active'
        },
        {
            name: 'offset',
            type: Number,
            default: 1,
            validValue: 5,
            attributeName: 'offset'
        }
    ]
}

const testSuite = new TestCafeComponentTestSuite( _config );
testSuite.runAllTests();

Example with Custom Tests

...
const testSuite = new TestCafeComponentTestSuite( _config );
testSuite.runAllTests();

const model = testSuite.model;
const topButton = model.component;

fixture( 'OD-Top-Button Custom Tests' )
    .page( model.testServer );

test( 'Integration Tests - Properties - offset - behaviour', async t => {
    let selector = model.componentSelector
    await t.eval( () => { document.querySelector( selector ).offset = 2 }, {dependencies: { selector }} );

    let offsetValue = await topButton.offset;

    await t
        .expect( topButton.withAttribute( 'offset', offsetValue.toString() ).exists ).ok( 'Attribute "offset" updates with property' );
        
    await t.eval( () => { document.querySelector( selector ).offset = 1 }, {dependencies: { selector }} );
} );

Configuration

| Field | Type | Description | |---------------------|---------|---------------------------------------------------------------| | testServer | String | The server/page that your Testcafe fixture runs tests against | | name | String | The proper name for your component; Should be easy to read | | componentTag | String | The tagName for your component when it is in the DOM | | componentSelector | String | The selector used to find your component in the DOM of your specified server/page; Should be an Id | | hasShadow | Boolean | Set to true if your component uses a shadow DOM | | shadowSelector | String | The selector used to find the PARENT element inside your components shadow DOM; Can be excluded if hasShadow is set false | | properties | Array | A set of properties that component exposes; See below for property Configuration |

Property Configuration

| Field | Description | | |-----------------|-------------|--------------------------| | name | String | The name of the property | | type | Primative | The JS type that your property is; Supported Types: Boolean, String, Number, Object, Array | | default | Primative | The default value that the property is set to upon initialization; Should be of type specified in 'type' field | | validValue | Primative | A value that the given property can accept without issue; Should be of type specified in 'type' field; ONLY REQUIRED IN Number AND String 'type' | | attributeName | Primative | The name of the attribute that corresponds to the property; ONLY REQUIRED IN Number AND String AND Boolean 'type' |

Development

Run development server and show demo

npm run demo

Run linter

npm run lint

Fix linter errors

npm run fix

Build for production

npm run build