2.1.8 • Published 4 years ago

@orcden/od-component-test-suite v2.1.8

Weekly downloads
-
License
MIT
Repository
bitbucket
Last release
4 years ago

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

FieldTypeDescription
testServerStringThe server/page that your Testcafe fixture runs tests against
nameStringThe proper name for your component; Should be easy to read
componentTagStringThe tagName for your component when it is in the DOM
componentSelectorStringThe selector used to find your component in the DOM of your specified server/page; Should be an Id
hasShadowBooleanSet to true if your component uses a shadow DOM
shadowSelectorStringThe selector used to find the PARENT element inside your components shadow DOM; Can be excluded if hasShadow is set false
propertiesArrayA set of properties that component exposes; See below for property Configuration

Property Configuration

FieldDescription
nameStringThe name of the property
typePrimativeThe JS type that your property is; Supported Types: Boolean, String, Number, Object, Array
defaultPrimativeThe default value that the property is set to upon initialization; Should be of type specified in 'type' field
validValuePrimativeA value that the given property can accept without issue; Should be of type specified in 'type' field; ONLY REQUIRED IN Number AND String 'type'
attributeNamePrimativeThe 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
1.0.3

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.30

4 years ago

2.0.1

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.0.16

4 years ago

2.1.4

4 years ago

2.0.13

4 years ago

2.1.3

4 years ago

2.0.14

4 years ago

2.1.6

4 years ago

2.0.11

4 years ago

2.1.5

4 years ago

2.0.12

4 years ago

2.1.8

4 years ago

2.1.7

4 years ago

2.0.10

4 years ago

2.0.20

4 years ago

2.0.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.3.5

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.45

4 years ago

0.2.44

4 years ago

0.2.43

4 years ago

0.2.42

4 years ago

0.2.41

4 years ago

0.2.40

4 years ago

0.2.39

4 years ago

0.2.38

4 years ago

0.2.37

4 years ago

0.2.36

4 years ago

0.2.35

4 years ago

0.2.34

4 years ago

0.2.33

4 years ago

0.2.32

4 years ago

0.2.30

4 years ago

0.2.31

4 years ago

0.2.29

4 years ago

0.2.28

4 years ago

0.2.27

4 years ago

0.2.26

4 years ago

0.2.25

4 years ago

0.2.24

4 years ago

0.2.23

4 years ago

0.2.22

4 years ago

0.2.21

4 years ago

0.2.20

4 years ago

0.2.19

4 years ago

0.2.18

4 years ago

0.2.17

4 years ago

0.2.16

4 years ago

0.2.15

4 years ago

0.2.14

4 years ago

0.2.13

4 years ago

0.2.12

4 years ago

0.2.11

4 years ago

0.2.10

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.1.2

4 years ago

0.2.0

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago