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

staf

v1.0.6

Published

Simple Test Automation Framework

Downloads

5

Readme

Simple Test Automation Framework

Background

The idea behind creation of another test runner is to enable:

  • Assigning any properties to test
  • Controling of which tests to execute and in which order based on their properties
  • Analyzing result of test and decide if it needs retry
  • Stopping test execution on fulfilling some condition
  • Providing test dependencies into test

Quick start

All quickstart code is stored in repo: https://github.com/geokur/staf-examples

Install Simple Test Automation Framework

npm install -g staf

Simple test

Create test class, save into 'first-test.js' in 'test' folder

const assert = require('assert').strict

class SimpleTest {
    mySimpleTest() {
        return () => {
            assert.ok(true)
        }
    }
}

module.exports = SimpleTest

And configuration file for test runner in file 'test-config.js'

module.exports = {
    testPath: 'test'
}

Project structure should look like this:

project
+-- test
    +-- simple-test.js
+-- test-config.js

Execute the test:

staf test-config.js

Test with pre and post conditions

const assert = require('assert').strict

class ConditionTest {
    beforeEach() {
        this.db = new Map()
        this.db.set('value1', 1)
    }
    hasEntryTest() {
        return () => {
            const hasEntry = this.db.has('value1')
            assert.ok(hasEntry)
        }
    }
    hasNoEntryTest() {
        return () => {
            const hasEntry = this.db.has('value1')
            assert.strictEqual(hasEntry, false)
        }
    }
    afterEach({ testResult }) {
        if (testResult instanceof Error) {
            this.db.clear()
        }
    }
}

module.exports = ConditionTest

Execute the test:

staf test-config.js

Test with properties

Create test with properties

const assert = require('assert').strict

class PropertyTest {
    myPositiveTest(testProperties) {
        testProperties.type = 'positive'
        return () => {
            assert.ok(true)
        }
    }
    myNegativeTest(testProperties) {
        testProperties.type = 'negative'
        return () => {
            assert.ok(false)
        }
    }
}

module.exports = PropertyTest

And configuration file for test runner in file 'positive-test-config.js'. Notice method 'schedule'. It is used to filter only 'positive' tests.

module.exports = {
    testPath: 'test',
    schedule(tests) {
        const onlyPositive = tests.filter(test => test.testProperties.type === 'positive')
        return onlyPositive
    }
}

Execute the test:

staf positive-test-config.js

Test with retry

Create test with retry property

const assert = require('assert').strict

class RetryTest {
    zeroRetryTest(testProperties) {
        testProperties.retry = 0
        return () => {
            assert.ok(true)
        }
    }
    oneRetryTest(testProperties) {
        testProperties.retry = 1
        return () => {
            assert.ok(false)
        }
    }
}

module.exports = RetryTest

And configuration file for test runner in file 'retry-test-config.js'. Notice method 'analyze' which is called after execution of each test. It is called with 3 params:

  • test - test which has just been executed
  • result - result of this test
  • tests - array with all tests planned for execution

For 'test' to be retried it should just be pushed back to 'tests' array.

const retryCount = new Map()

module.exports = {
    testPath: 'test',
    schedule(tests) {
        const onlyRetryable = tests.filter(test => 'retry' in test.testProperties)
        return onlyRetryable
    },
    analyze(test, result, tests) {
        if (result.testResult instanceof Error) {
            const { testProperties } = test
            let retried = retryCount.has(testProperties) ? retryCount.get(testProperties) : 0
            if (retried < testProperties.retry) {
                retryCount.set(testProperties, ++retried)
                tests.push(test)
            }
        }
    }
}

Execute the test:

staf retry-test-config.js