Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@asdgf/core

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@asdgf/core

A stupid simple way to test

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@asdgf/core

A stupid simple way to test

No magic, no nonsense.

Demo

import { describe, executeTests } from '@asdgf/core';
import { expect } from '@open-wc/testing';
import { sum } from 'sum';

describe('sum', ({it, before, /* beforeEach, after, afterEach */}) => {
  before(() => {
    console.log('hello world');
  });

  it('adds two numbers', () => {
    expect(sum(1,1)).to.equal(2);
  });
});

/**
 * Returns a test report
 */
executeTests().then(console.log);

You can also nest suites:

describe('foo', ({it, /* before, beforeEach, after, afterEach */}) => {
  it('does foo', () => {
    expect(true).to.equal(true);
  });

  /** Make sure to destructure `it` from the suite */
  describe('bar', ({it}) => {
    it('does bar', () => {
      expect(true).to.equal(true);
    });
  });
});

Example with web components

import { describe } from 'asdgf';
import { expect, html } from '@open-wc/testing';
import { fixture, fixtureCleanup } from '@open-wc/testing-helpers/pure';

class MyEl extends HTMLElement {
  connectedCallback() {
    this.innerHTML = `hello world`;
  }
}
customElements.define('my-el', MyEl);

describe('MyEl', ({it, afterEach}) => {
  afterEach(fixtureCleanup);

  it('renders', async () => {
    const el = await fixture(html`<my-el></my-el>`);
    expect(el.textContent).to.equal('hello world');
  });
});

Renderer

You can provide a custom renderer to render progress in the browser, or log progress to the console.

import { executeTests } from '@asdgf/core';

/**
 * Log progress to the console
 */
const renderer = {
  /** Runs before all suites run, depending on the integration */
  start: () => {},
  /** Runs before the suite starts, can be used for set up */
  suiteStart: ({name, only, tests}) => {
    console.log(`Starting suite: [${name}]`);
  },
  /** Runs after every ran test, whether it's skipped, passed, or failed */
  renderTest: (testResult) => {
    console.log(`${testResult.name}: ${testResult.passed ? '✅' : '❌'}`);
  },
  /** Runs after the entire suite has ran */
  suiteEnd: (testSuiteResult) => {
    console.log(`End of suite: [${testSuiteResult.name}]`);
  },
  /** Runs after all suites run, depending on the integration */
  end: () => {}
}

executeTests({renderer});
import { executeTests } from '@asdgf/core';
import '@asdgf/ui/test-report.js';

/**
 * Render progress to the browser
 */
const renderer = {
  /** Runs after every ran test, whether it's skipped, passed, or failed */
  renderTest: (testResult) => {
    const result = document.createElement('test-result');
    result.test = testResult;
    document.body.appendChild(result);
  },
}

executeTests({renderer});

Usage with @web/test-runner

npm i -D @asdgf/web-test-runner

web-test-runner.config.mjs:

export default {
  /** 
   * Point WTR to `asdgf` as the testFramework of choice 
   */
  testFramework: { path: 'node_modules/@asdgf/web-test-runner/index.js' },
};

Prior art

This project was inspired by uvu.

Keywords

FAQs

Package last updated on 24 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc