Socket
Socket
Sign inDemoInstall

mocha-list-tests

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mocha-list-tests - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

33

mocha-list-tests.js

@@ -84,3 +84,3 @@ // -----------------------------------------------------------------------------

let testRoute = [];
const directoryPrefix = new RegExp(`^${process.cwd()}/`);
// -----------------------------------------------------------------------------

@@ -93,2 +93,9 @@ // addTestRouteToTree

function addTestRouteToTree (testRoute, name) {
const stackTrace = { name: 'Stacktrace' };
Error.captureStackTrace(stackTrace, addTestRouteToTree);
const frames = stackTrace.stack.split('\n');
const line = frames[2];
const matches = line.match(/^(?:.*\((.*):\d+\)|.* at (\/.*?):\d+)$/);
const filenameAndLine = (matches[1] || matches[2]).replace(directoryPrefix, '');
let newTestRoute = testRoute.slice(0); // clone

@@ -103,5 +110,5 @@ newTestRoute.push (name);

// to override a leaf with an object.
if (!(current in root) || (root[current] === true)) {
if (!(current in root) || typeof(root[current]) == 'string') {
if ((i + 1) == newTestRoute.length)
root[current] = true;
root[current] = filenameAndLine;
else

@@ -129,3 +136,9 @@ root[current] = {};

suites[testRoute.join ('.')] = true;
suite();
// define methods that can be used inside describe using this
suite.apply({
timeout : () => {},
slow : () => {},
retries: () => {}
});
testRoute.pop ();

@@ -155,3 +168,2 @@ }

return function capture (ignoreFunction) {
console.log (name, ignoreFunction);
addTestRouteToTree (testRoute, ':' + name);

@@ -181,5 +193,10 @@ };

// HOOK: describe/it function hooks
global.describe = captureDescribeFunctions
global.it = captureItFunctions
global.describe = captureDescribeFunctions
global.it = captureItFunctions
global.describe.skip = global.describe
global.describe.only = global.describe
global.it.skip = global.it
global.it.only = global.it
global.before = captureHookFunctions('before')

@@ -247,2 +264,2 @@ global.after = captureHookFunctions('after')

findSuitesAndTests
};
};
{
"name": "mocha-list-tests",
"version": "1.0.2",
"version": "1.0.3",
"description": "List mocha suites and tests without running anything",

@@ -5,0 +5,0 @@ "main": "mocha-list-tests.js",

# mocha-list-tests
List all mocha suites and tests without running them. Zero dependencies.
List all mocha suites and tests without running them.

@@ -9,3 +9,3 @@ This is a standalone mocha-compatible companion, with no dependencies (not even mocha), to get a parseable json list of all suites and tests that would be executed in a folder.

This script would be useful as long as this functionality is not included in mocha itself. At the time of this writing (2019), there seems to be no motivation to do so, since a patch was submitted in the past and rejected.
This script would be useful as long as this functionality is not included in mocha itself. At the time of this writing (2018), there seems to be no motivation to do so, since a patch was submitted in the past and rejected.

@@ -12,0 +12,0 @@ ## Install

it ('test-0', async function () {

@@ -31,2 +32,31 @@ console.log ("won't execute");

});
});
// test internal functions
describe('suite-4', async function() {
this.timeout(3000);
this.slow(150);
this.retries(4);
describe('suite-4.1', async function() {
this.timeout(3000);
this.slow(150);
this.retries(4);
it('test-4.1.1', async function() {
this.skip(); // will never be executed
console.log ("won't execute");
});
});
});
describe('suite-5', async function() {
it.skip('test-5.1', async function() {
console.log ("won't execute");
});
describe.skip('suite-5.2', async function() {
it('test-5.2.1', async function() {
console.log ("won't execute");
});
});
});
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