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

@socketsupply/ssc-test

v0.1.0

Published

Test ssc apps.

Downloads

82

Readme

ssc test

A tool for testing ssc apps. Exposes two functions -- addTest, which is called in your application code, and buildTests, called by your build script.

install

npm i -D @socketsupply/ssc-test

example -- application code

Within the render process, call addTest() --

import { render } from 'preact'
import { html } from 'htm/preact'
import addTest from "@socketsupply/ssc-test"

function demonstration () {
    return html`<div class="demo">
        <h1>hello, world</h1>
        <a href="/hello">hello</a>
    </div>`
}

// call this function within the render process. It will look at
// `process.argv`, for an argument like `--test=foo.js`. If this
// was not called with a `--test=...` argument, then it does nothing.
addTest()

render(html`<${demonstration} />`, document.body)

example -- build script

This is the node script that will build the JS for your application. Notice the buildTest function required in the example.

This will build all the test files located in the directory passed in, here __dirname + '/test'. That way we can compile the application, then you can run any of the tests without needing to re-compile. Also, make sure the test filenames do not conflict with the application code filenames.

const buildTests = require('@socketsupply/ssc-test/dist/build-tests')
// or with esm:
// import buildTests from('@socketsupply/ssc-test/build-tests)
const esbuild = require('esbuild')

async function main () {
  // render process
  await esbuild.build({
    entryPoints: ['src/render/index.js'],
    // ...
  })

  // main process
  await esbuild.build({
    entryPoints: ['src/main/index.js'],
    // ...
  })

  // tests
  if (buildTests.isTest()) { // check if this was passed `--test`
    // takes the path to a directory with tests in it,
    // and the path to the output directory
    const testDir = __dirname + '/test'
    const outputDir = __dirname + '/public'
    await buildTests(testDir, outputDir)
  }
}

example -- tests

// @ts-check
'use strict'
const { test } = require('tapzero')
const dom = require('@socketsupply/test-dom')
const uuid = require('uuid').v4
const path = require('path-browserify')
const Harness = require('@socketsupply/ssc-test/')

test('setup', async t => {
    const harness = await Harness.create({ customBootstrap })
    t.ok(harness, 'should create harness')
})

test('find an element', async t => {
    const el = await dom.waitFor({
        selector: 'a'
    })

    t.ok(dom.isElementVisible(el), 'should find a visible link tag')
})

function customBootstrap (harness, system, env) {
    const _dialog = system.dialog.bind(system)
    const mocks = harness.mocks
    mocks.folder = uuid()

    // this way we can mock calls to the app menu
    system.dialog = function (args) {
        if (args.title === 'Add Workspace Folder' && args.type === 'open') {
            const _path = path.join(env.home, 'ssc-test', mocks.folder)

            return system.send({
                api: 'fs',
                method: 'mkdirp',
                arguments: [_path]
            })
            .then(() => ([_path]))
        }

        // if we don't need to mock this call, return the standard dialog
        return _dialog(args)
    }
}

use with npm

Run tests as part of npm scripts. See the example directory. Run this command:

$ npm test -- --test=test.js .

See package.json in the example directory:

{
    "scripts": {
        "test": "node ./build.js --test && ssc compile -r --test"
    }
}