Git Product home page Git Product logo

Comments (1)

Krinkle avatar Krinkle commented on August 15, 2024

@david-pfx Coud you share an example or two of the kind of links you'd like to insert, and what (if any) test information you use to builld the links?

I've recently documented the beginnings of the "HTML API" at https://qunitjs.com/browser/#html-api

Here is how you might use it:

Screenshot
QUnit.hooks.afterEach(function () {
  const test = QUnit.config.current;
  const testItem = document.querySelector('#qunit-test-output-' + test.testId);
  const assertList = testItem.querySelector('ol');

  // Append "View source" link
  const fileName = /.*\/([^/:]+):/.exec((test.stack || '').split('\n')[0])?.[1];
  if (fileName) {
    const url = `https://github.com/search?type=code&q=${encodeURIComponent('org:qunitjs path:"' + fileName + '"')}`;
    testItem.insertBefore(
      Object.assign(document.createElement('a'), {
        href: url,
        textContent: 'View source'
      }),
      assertList
    );
  }
});

I suspect this is close to what you have already, but I figured I'd recognise and support it.
We could ease this by wrapping "Rerun" in a <span> with a documented class like qunit-test-actions that you can safely append to, instead of having to manually position it relative to "runtime" and "assert-list":

QUnit.hooks.afterEach(function () {
  const test = QUnit.config.current;
  const testActions = document.querySelector(`#qunit-test-output-${test.testId} .qunit-test-actions`);

  // Append "View source" link
  const fileName = /.*\/([^/:]+):/.exec((test.stack || '').split('\n')[0])?.[1];
  if (fileName) {
    const url = `https://github.com/search?type=code&q=${encodeURIComponent('org:qunitjs path:"' + fileName + '"')}`;
    testActions.append(Object.assign(document.createElement('a'), {
      href: url,
      textContent: 'View source'
    }));
  }
});

A more constrained but declarative API could look like this:

QUnit.on('htmlTestActions', (e) => {
  e.status; // "passed"
  e.testDone; // https://qunitjs.com/api/callbacks/QUnit.testDone

  e.actions.push({
    url: '…',
    label: 'View source'
  });
});

from qunit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.