Comparing version 4.0.0-beta.5 to 4.0.0-beta.6
@@ -6,4 +6,6 @@ 'use strict' | ||
const appleTerm = process.env.TERM_PROGRAM === 'Apple_Terminal' | ||
const xterm = process.env.TERM === 'xterm-256color' | ||
const charOffset = appleTerm || xterm ? -1 : 0 | ||
module.exports = (char) => new Promise((resolve, reject) => { | ||
const checkChar = (char) => new Promise((resolve, reject) => { | ||
if (!(process.stdin.isTTY && process.stdin.isTTY)) return resolve(false) | ||
@@ -32,3 +34,3 @@ let clean = false | ||
const val = +((`${d}` || '').match(/;(\d+)R/) || [])[1] | ||
return cleanup(val === expect || (appleTerm && val - 1 === expect)) | ||
return cleanup(val === expect || ((val + charOffset) === expect)) | ||
} | ||
@@ -45,1 +47,3 @@ | ||
}) | ||
module.exports = { checkChar, charOffset: Math.abs(charOffset) } |
48
index.js
'use strict' | ||
process.env.NODE_ENV = process.env.NODE_ENV || 'test' | ||
const { deepStrictEqual, notDeepStrictEqual } = require('assert').strict | ||
const checkChar = require('./cli-char-supported') | ||
const { checkChar, charOffset } = require('./cli-char-supported') | ||
const colorReset = `\u001b[0m` | ||
@@ -10,5 +12,7 @@ const colorGreen = `\u001b[32m` | ||
const colorYellow = `\u001b[33m` | ||
const buf = `${Array(charOffset + 1).join(' ')}` | ||
const queue = [] | ||
let verbose = process.argv.some((a) => a === '--verbose' || a === '-v') | ||
let fileName, lastFileName | ||
@@ -25,3 +29,4 @@ let charsChecked = false | ||
const char = (n) => { | ||
return `${chars[n].useEmoji ? chars[n].emoji : chars[n].plain}${colorReset}` | ||
if (!chars[n].useEmoji) return `${chars[n].plain}${colorReset}` | ||
return `${chars[n].emoji}${colorReset}${buf}` | ||
} | ||
@@ -45,4 +50,5 @@ | ||
const setup = (opts = {}) => before(async () => { | ||
const _setup = async (opts = {}) => { | ||
verbose = opts.verbose !== undefined ? !!opts.verbose : verbose | ||
fileName = opts.fileName | ||
@@ -56,2 +62,7 @@ if (charsChecked) return | ||
charsChecked = true | ||
} | ||
const setup = (opts = {}) => queue.push({ | ||
fn: () => _setup(opts), | ||
fileName: opts.fileName | ||
}) | ||
@@ -72,4 +83,12 @@ | ||
const runner = async (t, noExit) => { | ||
const { msg, fn, failing, benchOpts } = t | ||
const { msg, fn, failing, benchOpts, fileName: currFile } = t | ||
if (currFile) { | ||
const fileRunMsg = `\nRunning tests for ${currFile}\n\n` | ||
if (currFile !== lastFileName) process.stdout.write(fileRunMsg) | ||
lastFileName = currFile | ||
} | ||
if (benchOpts) return benchRunner(t) | ||
@@ -86,3 +105,4 @@ | ||
const toPrint = `${char('okFail')} ${colorRed}${msg}${colorReset}\n` | ||
const ms = ` (${fmtMs(Date.now() - start)})` | ||
const toPrint = `${char('okFail')} ${colorRed}${msg}${ms}${colorReset}\n` | ||
return process.stdout.write(toPrint) | ||
@@ -125,3 +145,3 @@ } | ||
const test = async (msg, fn) => { | ||
if (msg && fn) queue.push({ msg, fn }) | ||
if (msg && fn) queue.push({ msg, fn, fileName }) | ||
@@ -137,2 +157,3 @@ const curLen = queue.length | ||
let countTodo = 0 | ||
let countNormal = 0 | ||
let countSkipped = 0 | ||
@@ -145,2 +166,3 @@ let countFailing = 0 | ||
if (t.failing) countFailing += 1 | ||
if (t.msg) countNormal += 1 | ||
@@ -154,3 +176,2 @@ if (t.first) first.push(t) | ||
const countOnly = only.length | ||
const countRan = (countOnly + normal.length) | ||
const plural = (c, s) => c > 1 ? `${s || 'test'}s` : `${s || 'test'}` | ||
@@ -179,3 +200,5 @@ | ||
process.stdout.write(`\n${char('good')} ${result}\n`) | ||
process.stdout.write(`${colorReset}${countRan} ${plural(countRan)} declared\n`) | ||
process.stdout.write( | ||
`${colorReset}${countNormal} ${plural(countNormal)} declared\n` | ||
) | ||
@@ -273,2 +296,3 @@ if (countOnly) { | ||
falsy: falsy(msg, f), | ||
contains: contains(msg, f), | ||
deepEqual: deepEqual(msg, f), | ||
@@ -327,2 +351,8 @@ notDeepEqual: notDeepEqual(msg, f), | ||
const contains = (msg, f) => (a, b) => { | ||
const asStr = JSON.stringify(a, null, 2) | ||
const err = `${toPrint(asStr)} does not contain ${b}` | ||
return wrap(msg, () => asStr.indexOf(b) !== -1, err, f) | ||
} | ||
const deepEqual = (msg, f) => (a, b) => { | ||
@@ -382,4 +412,4 @@ return wrap( | ||
setup() | ||
before(_setup) | ||
module.exports = test |
{ | ||
"name": "mvt", | ||
"version": "4.0.0-beta.5", | ||
"description": "A minimum viable testing framework, aka a few test helpers, 0 dependencies", | ||
"version": "4.0.0-beta.6", | ||
"description": "Minimum Viable Testing framework, it's like AVA, if AVA sucked", | ||
"main": "index.js", | ||
@@ -11,3 +11,3 @@ "files": [ | ||
"scripts": { | ||
"test": "node test --verbose" | ||
"test": "node test/index.js --verbose" | ||
}, | ||
@@ -14,0 +14,0 @@ "repository": { |
@@ -11,6 +11,5 @@ # mvt [](https://npmjs.org/package/mvt) [](https://github.com/feross/standard) | ||
test needs. That was a bit too restrictive though. In version `4.0.0+` it became | ||
a blatant ripoff of AVA. Well, not really. It does about 1% of what AVA does, | ||
and it doesn't do that nearly as well. | ||
a blatant ripoff of AVA. Although, it does a small fraction of what AVA does. | ||
## If it's inferior in every way to AVA then why does it exist | ||
## If it's inferior to AVA then why does it exist | ||
Because I need to minimize my security alerts so that I don't lose real security | ||
@@ -20,5 +19,7 @@ threats in the deluge. I'm often finding my devDependencies to be the culprit | ||
[But It's Just a Dev Dependency...](https://medium.com/swlh/but-its-just-a-dev-dependency-566646ebeec9) | ||
## What's good about it | ||
- It has 0 dependencies and devDependencies | ||
- That's really about it | ||
- It has 0 dependencies (and devDependencies) | ||
- It's more emojified than AVA (of course that matters 0) | ||
@@ -28,4 +29,3 @@ ## What it lacks (way more than I can list, but here's the most notable) | ||
- tests must be run as `node tests/a.js` | ||
- the above must be done for each test file `node tests/a.js && node tests/b.js` | ||
- thus each test file gets a distinct output, so no central tracking of tests | ||
- for multiple files you must require them from an entry test file | ||
- Useful `Error` output | ||
@@ -39,7 +39,6 @@ - you won't get a clean stack, it will be filled with useless info from `mvt` | ||
- A community and product maturity | ||
- one of the most crucial pieces, I think we can all agree on that | ||
- among the most crucial elements | ||
## This might be for you if | ||
- You're willing to sacrifice all of the above (and more) to reduce dependencies | ||
- Your tests are in a single file and concurrency doesn't impact test times | ||
@@ -49,3 +48,3 @@ ## Install | ||
```sh | ||
$ npm install --save-dev mvt | ||
$ npm install --save-dev mvt@beta | ||
``` | ||
@@ -64,22 +63,46 @@ | ||
test('assert.is works', (assert) => assert.is(1, 1)) | ||
test('assert.is works', (assert) => { | ||
assert.is(1, 1) | ||
}) | ||
test('assert.not works', (assert) => assert.not(1, 2)) | ||
test('assert.not works', (assert) => { | ||
assert.not(1, 2) | ||
}) | ||
test('assert.pass works', assert) => assert.pass()) | ||
test('assert.pass works', assert) => { | ||
assert.pass() | ||
}) | ||
test.failing('test.failing and assert.fail works', (assert) => assert.fail()) | ||
test.failing('test.failing and assert.fail works', (assert) => { | ||
assert.fail() | ||
}) | ||
test('assert.true works', (assert) => assert.true(true)) | ||
test('assert.true works', (assert) => { | ||
assert.true(true) | ||
}) | ||
test('assert.false works', (assert) => assert.false(false)) | ||
test('assert.false works', (assert) => { | ||
assert.false(false) | ||
}) | ||
test('assert.truthy works', (assert) => assert.truthy(1)) | ||
test('assert.truthy works', (assert) => { | ||
assert.truthy(1) | ||
}) | ||
test('assert.falsy works', (assert) => assert.falsy(0)) | ||
test('assert.falsy works', (assert) => { | ||
assert.falsy(0) | ||
}) | ||
test('assert.deepEqual works', (assert) => assert.deepEqual([1, 2], [1, 2])) | ||
test('assert.contains works', (assert) => { | ||
assert.contains('a few words', 'few') | ||
}) | ||
test('assert.notDeepEqual works', (assert) => assert.notDeepEqual([2, 1], [1, 2])) | ||
test('assert.deepEqual works', (assert) => { | ||
assert.deepEqual([1, 2], [1, 2]) | ||
}) | ||
test('assert.notDeepEqual works', (assert) => { | ||
assert.notDeepEqual([2, 1], [1, 2]) | ||
}) | ||
test('assert.throws works', (assert) => { | ||
@@ -86,0 +109,0 @@ assert.throws(() => { throw new Error('it throws') }) |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
17589
353
152
4