From 91721608d5c102d81aa05a309743579fdf06b7ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 24 Feb 2024 16:43:33 -0300 Subject: [PATCH] fix(filter): include both .test. and .spec. as default (#27) * chore(website): add robots.txt * fix(poku and CLI): include both .test. and .spec. as default filter * chore(CLI): improve hr --- goals.md | 10 +++++++++- src/helpers/format.ts | 3 +++ src/helpers/hr.ts | 19 +++++++++++++++---- src/modules/list-files.ts | 2 +- src/services/run-tests.ts | 4 ++-- website/static/robots.txt | 4 ++++ 6 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 website/static/robots.txt diff --git a/goals.md b/goals.md index c1607c6d..acf5056e 100644 --- a/goals.md +++ b/goals.md @@ -1,3 +1,11 @@ -- **fix:** include both .test. and .spec. as default filter +# Goals + +## `fix:` + +--- + +## `feat:` + - **feat:** show message from `assert` like in popular "describe" and "it" if `describe` option is `true` - **feat:** show individual test execution time +- **feat:** allow to limit concurrency in parallel runs diff --git a/src/helpers/format.ts b/src/helpers/format.ts index 5ab09038..3d27600e 100644 --- a/src/helpers/format.ts +++ b/src/helpers/format.ts @@ -12,3 +12,6 @@ export const format = { success: (value: string) => `\x1b[32m${value}\x1b[0m`, fail: (value: string) => `\x1b[31m${value}\x1b[0m`, }; + +export const getLargestStringLength = (arr: string[]): number => + arr.reduce((max, current) => Math.max(max, current.length), 0); diff --git a/src/helpers/hr.ts b/src/helpers/hr.ts index c2acebec..bdd1fb4c 100644 --- a/src/helpers/hr.ts +++ b/src/helpers/hr.ts @@ -1,9 +1,20 @@ import { EOL } from 'node:os'; import process from 'node:process'; -export const hr = () => { - const columns = process.stdout.columns; - const line = '⎯'.repeat(columns - 10 || 30); +let lastLenght: number = 0; - console.log(`\x1b[2m${line}\x1b[0m${EOL}`); +export const hr = (size?: number) => { + const pad = 10; + const limit = process.stdout.columns - pad; + const fileLenght = typeof size === 'number' ? Math.floor(size / 2) + pad : 0; + const columns = + fileLenght > 0 && fileLenght <= limit + ? fileLenght + : lastLenght > 0 + ? lastLenght + : limit; + const line = '⎯'.repeat(columns); + lastLenght = columns; + + console.log(`${EOL}\x1b[2m${line}\x1b[0m${EOL}`); }; diff --git a/src/modules/list-files.ts b/src/modules/list-files.ts index 50d72a43..4f9dfe49 100644 --- a/src/modules/list-files.ts +++ b/src/modules/list-files.ts @@ -16,7 +16,7 @@ export const listFiles = ( configs?: Configs ) => { const currentFiles = fs.readdirSync(dirPath); - const defaultRegExp = /\.test\./i; + const defaultRegExp = /\.(test|spec)\./i; const filter: RegExp = (envFilter ? envFilter diff --git a/src/services/run-tests.ts b/src/services/run-tests.ts index 967fc3cc..bfa1c100 100644 --- a/src/services/run-tests.ts +++ b/src/services/run-tests.ts @@ -5,7 +5,7 @@ import { runner } from '../helpers/runner.js'; import { indentation } from '../helpers/indentation.js'; import { listFiles } from '../modules/list-files.js'; import { hr } from '../helpers/hr.js'; -import { format } from '../helpers/format.js'; +import { format, getLargestStringLength } from '../helpers/format.js'; import { runTestFile } from './run-test-file.js'; import { Configs } from '../@types/poku.js'; import { isQuiet } from '../helpers/logs.js'; @@ -24,7 +24,7 @@ export const runTests = async ( let passed = true; if (showLogs) { - hr(); + hr(getLargestStringLength(files)); console.log( `${format.bold('Directory:')} ${format.underline(currentDir)}${EOL}` ); diff --git a/website/static/robots.txt b/website/static/robots.txt new file mode 100644 index 00000000..49e114ed --- /dev/null +++ b/website/static/robots.txt @@ -0,0 +1,4 @@ +User-agent: * +Disallow: + +Sitemap: https://poku.dev/sitemap.xml