beartest-js 7.0.1 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/cli.js +43 -5
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -1,16 +1,54 @@
1
1
  #!/usr/bin/env node
2
+
2
3
  const { run } = require('./beartest')
3
4
  const fs = require('node:fs')
5
+ const path = require('node:path')
4
6
 
5
- async function cli() {
6
- const globStr = process.argv[2] || '**/*.test.*'
7
+ const INCLUDE = ['**/*.{test,spec}.{js,ts,jsx,tsx}']
8
+ const EXCLUDE = ['**/node_modules/**', '**/dist/**', '**/.git/**', '**/build/**', '**/coverage/**']
9
+
10
+ const hasGlob = (s) => /[*?\[\]{}()!]/.test(s)
11
+ const norm = (p) => p.split(path.sep).join('/')
12
+
13
+ async function discoverAll() {
14
+ const seen = new Set()
15
+ for (const pat of INCLUDE) {
16
+ for await (const f of fs.promises.glob(pat, { ignore: EXCLUDE })) seen.add(norm(f))
17
+ }
18
+ return [...seen].sort()
19
+ }
7
20
 
8
- const files = await Array.fromAsync(fs.promises.glob(globStr))
21
+ async function applyFilters(files, args) {
22
+ if (!args.length) return files
23
+
24
+ let out = files
25
+ for (const arg of args) {
26
+ if (hasGlob(arg)) {
27
+ const gset = new Set()
28
+ for await (const f of fs.promises.glob(arg, { ignore: EXCLUDE })) gset.add(norm(f))
29
+ out = out.filter((f) => gset.has(f)) // glob filter
30
+ } else {
31
+ const needle = norm(arg)
32
+ out = out.filter((f) => f.includes(needle)) // substring filter
33
+ }
34
+ }
35
+ return out
36
+ }
37
+
38
+ async function cli() {
39
+ const discovered = await discoverAll()
40
+ console.log(discovered)
41
+ const selected = await applyFilters(discovered, process.argv.slice(2))
42
+ console.log(selected)
9
43
 
10
- for await (let event of run({ files: files })) {
44
+ for await (let event of run({ files: selected.map((f) => path.resolve(f)) })) {
11
45
  const prefix = ' '.repeat(event.data.nesting)
12
46
  if (event.type === 'test:start' && event.data.type === 'suite') {
13
- process.stdout.write(`\x1b[36m${prefix}${event.data.name} \n\x1b[0m`)
47
+ if (path.isAbsolute(event.data.name)) {
48
+ console.log(`\x1b[36m${prefix}${path.parse(event.data.name).name} (${path.relative('./', event.data.name)})\x1b[0m`)
49
+ } else {
50
+ console.log(`\x1b[36m${prefix}${event.data.name}\x1b[0m`)
51
+ }
14
52
  } else if (event.type === 'test:pass' && event.data.details.type === 'test' && !event.data.skip) {
15
53
  process.stdout.write(`\x1b[32m${prefix}✓\x1b[0m\x1b[90m ${event.data.name}\n\x1b[0m`)
16
54
  } else if (event.type === 'test:fail' && event.data.details.type === 'test') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beartest-js",
3
- "version": "7.0.1",
3
+ "version": "7.1.0",
4
4
  "description": "Bear Bones Testing",
5
5
  "repository": {
6
6
  "type": "git",