Comments (1)
@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](https://private-user-images.githubusercontent.com/156867/347558638-e77aeb19-c105-4dc9-9ba2-8471b9674e96.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE2NjYxODMsIm5iZiI6MTcyMTY2NTg4MywicGF0aCI6Ii8xNTY4NjcvMzQ3NTU4NjM4LWU3N2FlYjE5LWMxMDUtNGRjOS05YmEyLTg0NzFiOTY3NGU5Ni5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzIyJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcyMlQxNjMxMjNaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1iYTdmZTcxYjU5MGE1ZDk0MThiMjkyM2QzNTJiMmNlNTFiNzg5YjI1OTBjMDVkNWI4MjRiYzkzNjkyZWM4MmRlJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.jZuUiNldNQvIodFfePoXvFqqXePngUZ5kQuaeJ1RBWo)
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)
- Drop support for node < 18? HOT 1
- Can we drop builtin AMD support? HOT 6
- Can we start a `next` branch so I can start PRing improvements? HOT 1
- Let simple array data in test.each() serve as automatic labels
- Facilitate "close to" number equal assertion HOT 3
- [Feature Request]: Allow more customization of how errors are handled (especially uncaughtrejection). HOT 1
- Web Test Runner and QUnit reporting problems HOT 9
- qunit cannot parse private functions and properties HOT 2
- Support multiple `module` parameters (QUnit.config.module array) HOT 2
- Unify qunitjs.com and api.qunitjs.com
- [QUESTION] How can I forcefully abort a testcase and advance to next in queue HOT 1
- Let the test.each callback access the current case key HOT 3
- deepEqual should not compare constructors HOT 2
- Document QUnit.urlsParams
- Add tests for QUnit.config.fixture HOT 1
- Stack trace cleaning preserves URLs with ports HOT 1
- [Feature Request]: Option to run tests in parallel? HOT 3
- Document QUnit.equiv()
- Support DOM nodes in TapReporter value formatting
- Support multiple `--reporter` options on the CLI
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qunit.