Comparing version 0.4.0-next.4 to 0.4.0
19
bin.js
@@ -6,7 +6,2 @@ #!/usr/bin/env node | ||
const hasImport = (() => { | ||
try { new Function('import').call(0) } | ||
catch (err) { return !/unexpected/i.test(err.message) } | ||
})(); | ||
sade('uvu [dir] [pattern]') | ||
@@ -25,7 +20,11 @@ .version(pkg.version) | ||
if (hasImport) { | ||
await import('uvu/run').then(m => m.default(suites, opts)); | ||
} else { | ||
await require('uvu/run')(suites, opts); | ||
} | ||
// TODO: mjs vs js file | ||
globalThis.UVU_DEFER = 1; | ||
suites.forEach((x, idx) => { | ||
globalThis.UVU_INDEX = idx; | ||
QUEUE.push([x.name]); | ||
require(x.file); // auto-add to queue | ||
}); | ||
await exec(opts.bail); | ||
} catch (err) { | ||
@@ -32,0 +31,0 @@ console.error(err.stack || err.message); |
const kleur = require('kleur'); | ||
const differ = require('diff'); | ||
const diff = require('diff'); | ||
// Native ESM workaround, until resolved at source | ||
// @see https://github.com/kpdecker/jsdiff/issues/292 | ||
const diff = differ.default || differ; | ||
const colors = { | ||
@@ -96,3 +92,3 @@ '--': kleur.red, | ||
// no length offsets | ||
} else if (tmp.removed) { | ||
} else if (tmp.removed && arr[i + 1]) { | ||
let del = tmp.count - arr[i + 1].count; | ||
@@ -99,0 +95,0 @@ if (del == 0) { |
@@ -59,25 +59,4 @@ const kleur = require('kleur'); | ||
function toProxy(cache) { | ||
return { | ||
get(obj, key) { | ||
let tmp = obj[key]; | ||
if (!tmp || typeof tmp !== 'object') return tmp; | ||
let nxt = cache.get(tmp); | ||
if (nxt) return nxt; | ||
nxt = new Proxy(tmp, this); | ||
cache.set(tmp, nxt); | ||
return nxt; | ||
}, | ||
set() { | ||
write('\n' + kleur.yellow('[WARN]') + ' Cannot modify context within tests!\n'); | ||
return true; | ||
} | ||
} | ||
} | ||
async function runner(ctx, name) { | ||
let { only, tests, before, after, bEach, aEach, state } = ctx; | ||
let reader = Proxy.revocable(state, toProxy(new Map)); | ||
let hook, test, arr = only.length ? only : tests; | ||
@@ -91,5 +70,6 @@ let num=0, errors='', total=arr.length; | ||
for (test of arr) { | ||
state.__test__ = test.name; | ||
try { | ||
for (hook of bEach) await hook(state); | ||
await test.handler(reader.proxy); | ||
await test.handler(state); | ||
for (hook of aEach) await hook(state); | ||
@@ -106,3 +86,3 @@ write(PASS); | ||
} finally { | ||
reader.revoke(); | ||
state.__test__ = ''; | ||
for (hook of after) await hook(state); | ||
@@ -117,2 +97,4 @@ let msg = ` (${num} / ${total})\n`; | ||
function setup(ctx, name = '') { | ||
ctx.state.__test__ = ''; | ||
ctx.state.__suite__ = name; | ||
const test = into(ctx, 'tests'); | ||
@@ -119,0 +101,0 @@ test.before = hook(ctx, 'before'); |
declare namespace uvu { | ||
type Callback<T> = (context: T) => Promise<void> | void; | ||
type Crumbs = { __suite__: string; __test__: string }; | ||
type Callback<T> = (context: T & Crumbs) => Promise<void> | void; | ||
@@ -20,5 +21,8 @@ interface Hook<T> { | ||
type Context = Record<string, any>; | ||
export type Test<T=Context> = uvu.Test<T>; | ||
export type Callback<T=Context> = uvu.Callback<T>; | ||
export const test: uvu.Test<Context>; | ||
export type Callback<T=Context> = uvu.Callback<T>; | ||
export function suite<T=Context>(title?: string, suite?: T): uvu.Test<T>; | ||
export function suite<T=Context>(title?: string, context?: T): uvu.Test<T>; | ||
export function exec(bail?: boolean): Promise<void>; |
{ | ||
"name": "uvu", | ||
"version": "0.4.0-next.4", | ||
"version": "0.4.0", | ||
"repository": "lukeed/uvu", | ||
@@ -29,6 +29,2 @@ "description": "uvu is an extremely fast and lightweight test runner for Node.js and the browser", | ||
"import": "./parse/index.mjs" | ||
}, | ||
"./run": { | ||
"require": "./run/index.js", | ||
"import": "./run/index.mjs" | ||
} | ||
@@ -42,4 +38,3 @@ }, | ||
"diff", | ||
"dist", | ||
"run" | ||
"dist" | ||
], | ||
@@ -46,0 +41,0 @@ "modes": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
0
44676
16
1065