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

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.3 to 1.0.4

test/es6module.mjs

58

mocha-list-tests.js

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

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

@@ -93,9 +95,20 @@ // 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 fileNameAndLine = 'unknown:0';
try {
const stackTrace = { name: 'Stacktrace' };
Error.captureStackTrace(stackTrace, addTestRouteToTree);
const frames = stackTrace.stack.split('\n');
const line = frames[2].replace('file://', '');
// at Object.<anonymous> (file:///home/whatever/github/mocha-list-tests/test/example.mjs:56:12)
// at file:///home/whatever/github/mocha-list-tests/test/example.mjs:51:1
const matches = line.match(/^(?:.*\((.*):\d+\)|.*\s+at\s+(\/.*?):\d+)$/);
if (matches)
fileNameAndLine = (matches[1] || matches[2]).replace(directoryPrefix, '');
}
catch(e) {
// ignore unknown errors
}
let newTestRoute = testRoute.slice(0); // clone

@@ -112,3 +125,3 @@ newTestRoute.push (name);

if ((i + 1) == newTestRoute.length)
root[current] = filenameAndLine;
root[current] = fileNameAndLine;
else

@@ -184,3 +197,3 @@ root[current] = {};

// -----------------------------------------------------------------------------
function findSuitesAndTests (testFolder, extensions) {
async function findSuitesAndTests (testFolder, extensions) {
if (typeof (extensions) === "string")

@@ -207,8 +220,12 @@ extensions = [extensions];

for (let i = 0; i < allTestFiles.length; i++) {
const file = allTestFiles[i];
let file = allTestFiles[i];
if (path.isAbsolute (file))
if (!path.isAbsolute (file))
file = './' + path.relative (__dirname, file);
// load ES6 modules with import and everything else with require
if (/\.mjs$/i.test(file))
await import(file);
else
require (file);
else
require ('./' + path.relative (__dirname, file));
}

@@ -228,3 +245,3 @@

// -----------------------------------------------------------------------------
function main () {
async function main () {
if (

@@ -242,3 +259,3 @@ (process.argv.length <= 2)

const result = findSuitesAndTests (testFolder, 'js');
const result = await findSuitesAndTests (testFolder, 'js');
console.log (JSON.stringify (result, null, ' '));

@@ -253,10 +270,11 @@

if (require.main === module) {
try {
process.exit (main());
}
catch (e) {
main()
.then(function(result) {
process.exit (result);
})
.catch(function(e) {
console.error ("Fatal Error (try --help for help):");
console.error (e);
process.exit (-1);
}
});
}

@@ -263,0 +281,0 @@

{
"name": "mocha-list-tests",
"version": "1.0.3",
"version": "1.0.4",
"description": "List mocha suites and tests without running anything",

@@ -19,3 +19,6 @@ "main": "mocha-list-tests.js",

"author": "Pau Sanchez",
"license": "MIT"
"license": "MIT",
"engines" : {
"node" : ">=7.6"
}
}
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