From 1df260829cd7e957fd1f88fde1c97068bf2876b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Fri, 26 Jul 2024 19:20:00 -0300 Subject: [PATCH] chore(deps): use monocart-coverage-reports (#610) * chore: use monocart-coverage-reports * ci: ignore invalid sintax fixture * ci: debug * ci: fix tests --- .nycrc | 2 +- .prettierignore | 1 + biome.json | 3 +- fixtures/fail-fast/parallel/.pokurc.json | 6 + fixtures/fail-fast/parallel/test/a.test.ts | 4 + fixtures/fail-fast/parallel/test/b.test.ts | 4 + fixtures/fail-fast/parallel/test/c.test.ts | 4 + fixtures/fail-fast/parallel/test/d.test.ts | 4 + fixtures/fail-fast/sequential/.pokurc.json | 4 + fixtures/fail-fast/sequential/test/a.test.ts | 4 + fixtures/fail-fast/sequential/test/b.test.ts | 4 + fixtures/fail/assert-fail-message.test.ts | 3 + fixtures/fail/assert-fail.test.ts | 3 + fixtures/fail/assert-if-error.test.ts | 3 + fixtures/fail/assert.test.ts | 3 + fixtures/sintax/invalid-file.js | 1 + fixtures/watch/.pokurc.json | 4 + fixtures/watch/test/a.test.ts | 3 + fixtures/watch/test/b.test.ts | 3 + fixtures/watch/test/sub/a.test.ts | 3 + fixtures/watch/test/sub/b.test.ts | 3 + fixtures/watch/test/sub/deep/.gitkeep | 0 package-lock.json | 147 +++++++++++++++++++ package.json | 5 +- src/modules/essentials/assert.ts | 2 - src/modules/essentials/poku.ts | 1 - src/modules/essentials/strict.ts | 2 - src/modules/helpers/container.ts | 2 - src/modules/helpers/describe.ts | 5 +- src/modules/helpers/each.ts | 2 - src/modules/helpers/env.ts | 2 - src/modules/helpers/it.ts | 4 +- src/modules/helpers/list-files.ts | 2 - src/modules/helpers/test.ts | 2 - src/modules/helpers/wait-for.ts | 2 - src/parsers/assert.ts | 2 - src/parsers/find-file-from-stack.ts | 2 - src/parsers/get-arg.ts | 2 - src/parsers/options.ts | 2 - src/parsers/output.ts | 2 - src/parsers/time.ts | 2 - src/services/assert.ts | 5 - src/services/container.ts | 8 +- src/services/each.ts | 2 - src/services/env.ts | 3 - src/services/format.ts | 2 - src/services/map-tests.ts | 2 - src/services/run-test-file.ts | 5 +- src/services/run-tests.ts | 11 -- src/services/watch.ts | 2 - src/services/write.ts | 2 - test/e2e/before-and-after-each.test.ts | 6 + test/e2e/fail-fast.test.ts | 29 ++++ test/e2e/failure.test.ts | 78 ++++++++++ test/e2e/watch.test.ts | 62 ++++++++ test/helpers/capture-cli.test.ts | 85 ++++++++++- test/integration/import.test.ts | 1 + test/unit/define-configs.test.ts | 14 ++ tsconfig.json | 8 +- tsconfig.test.json | 2 +- 60 files changed, 504 insertions(+), 82 deletions(-) create mode 100644 fixtures/fail-fast/parallel/.pokurc.json create mode 100644 fixtures/fail-fast/parallel/test/a.test.ts create mode 100644 fixtures/fail-fast/parallel/test/b.test.ts create mode 100644 fixtures/fail-fast/parallel/test/c.test.ts create mode 100644 fixtures/fail-fast/parallel/test/d.test.ts create mode 100644 fixtures/fail-fast/sequential/.pokurc.json create mode 100644 fixtures/fail-fast/sequential/test/a.test.ts create mode 100644 fixtures/fail-fast/sequential/test/b.test.ts create mode 100644 fixtures/fail/assert-fail-message.test.ts create mode 100644 fixtures/fail/assert-fail.test.ts create mode 100644 fixtures/fail/assert-if-error.test.ts create mode 100644 fixtures/fail/assert.test.ts create mode 100644 fixtures/sintax/invalid-file.js create mode 100644 fixtures/watch/.pokurc.json create mode 100644 fixtures/watch/test/a.test.ts create mode 100644 fixtures/watch/test/b.test.ts create mode 100644 fixtures/watch/test/sub/a.test.ts create mode 100644 fixtures/watch/test/sub/b.test.ts create mode 100644 fixtures/watch/test/sub/deep/.gitkeep create mode 100644 test/e2e/fail-fast.test.ts create mode 100644 test/e2e/failure.test.ts create mode 100644 test/e2e/watch.test.ts create mode 100644 test/unit/define-configs.test.ts diff --git a/.nycrc b/.nycrc index 8bfa43c3..82111ed7 100644 --- a/.nycrc +++ b/.nycrc @@ -19,7 +19,7 @@ "src/parsers/get-runtime.ts", "src/services/pid.ts" ], - "reporter": ["text", "lcov", "cobertura"], + "reporter": ["v8", "codecov", "console-details"], "branches": 95, "statements": 95, "lines": 95, diff --git a/.prettierignore b/.prettierignore index 61ed0e69..b0bb8052 100644 --- a/.prettierignore +++ b/.prettierignore @@ -2,3 +2,4 @@ /ci /CHANGELOG.md /website +/fixtures/sintax diff --git a/biome.json b/biome.json index f3847db3..84b4cf6a 100644 --- a/biome.json +++ b/biome.json @@ -9,7 +9,8 @@ "coverage", "website", "fixtures", - "benchmark" + "benchmark", + "fixtures/sintax" ] }, "organizeImports": { diff --git a/fixtures/fail-fast/parallel/.pokurc.json b/fixtures/fail-fast/parallel/.pokurc.json new file mode 100644 index 00000000..9119fdea --- /dev/null +++ b/fixtures/fail-fast/parallel/.pokurc.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://poku.io/schemas/configs.json", + "failFast": true, + "parallel": true, + "concurrency": 0 +} diff --git a/fixtures/fail-fast/parallel/test/a.test.ts b/fixtures/fail-fast/parallel/test/a.test.ts new file mode 100644 index 00000000..5dc97d83 --- /dev/null +++ b/fixtures/fail-fast/parallel/test/a.test.ts @@ -0,0 +1,4 @@ +import process from 'node:process'; + +console.log('Failure Fixture'); +process.exit(0); diff --git a/fixtures/fail-fast/parallel/test/b.test.ts b/fixtures/fail-fast/parallel/test/b.test.ts new file mode 100644 index 00000000..de44aaa9 --- /dev/null +++ b/fixtures/fail-fast/parallel/test/b.test.ts @@ -0,0 +1,4 @@ +import process from 'node:process'; + +console.log('Failure Fixture'); +process.exit(1); diff --git a/fixtures/fail-fast/parallel/test/c.test.ts b/fixtures/fail-fast/parallel/test/c.test.ts new file mode 100644 index 00000000..5dc97d83 --- /dev/null +++ b/fixtures/fail-fast/parallel/test/c.test.ts @@ -0,0 +1,4 @@ +import process from 'node:process'; + +console.log('Failure Fixture'); +process.exit(0); diff --git a/fixtures/fail-fast/parallel/test/d.test.ts b/fixtures/fail-fast/parallel/test/d.test.ts new file mode 100644 index 00000000..de44aaa9 --- /dev/null +++ b/fixtures/fail-fast/parallel/test/d.test.ts @@ -0,0 +1,4 @@ +import process from 'node:process'; + +console.log('Failure Fixture'); +process.exit(1); diff --git a/fixtures/fail-fast/sequential/.pokurc.json b/fixtures/fail-fast/sequential/.pokurc.json new file mode 100644 index 00000000..635b38af --- /dev/null +++ b/fixtures/fail-fast/sequential/.pokurc.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://poku.io/schemas/configs.json", + "failFast": true +} diff --git a/fixtures/fail-fast/sequential/test/a.test.ts b/fixtures/fail-fast/sequential/test/a.test.ts new file mode 100644 index 00000000..5dc97d83 --- /dev/null +++ b/fixtures/fail-fast/sequential/test/a.test.ts @@ -0,0 +1,4 @@ +import process from 'node:process'; + +console.log('Failure Fixture'); +process.exit(0); diff --git a/fixtures/fail-fast/sequential/test/b.test.ts b/fixtures/fail-fast/sequential/test/b.test.ts new file mode 100644 index 00000000..de44aaa9 --- /dev/null +++ b/fixtures/fail-fast/sequential/test/b.test.ts @@ -0,0 +1,4 @@ +import process from 'node:process'; + +console.log('Failure Fixture'); +process.exit(1); diff --git a/fixtures/fail/assert-fail-message.test.ts b/fixtures/fail/assert-fail-message.test.ts new file mode 100644 index 00000000..36d3f524 --- /dev/null +++ b/fixtures/fail/assert-fail-message.test.ts @@ -0,0 +1,3 @@ +import { assert } from '../../src/modules/index.js'; + +assert.fail('Should fail'); diff --git a/fixtures/fail/assert-fail.test.ts b/fixtures/fail/assert-fail.test.ts new file mode 100644 index 00000000..05fd8ae3 --- /dev/null +++ b/fixtures/fail/assert-fail.test.ts @@ -0,0 +1,3 @@ +import { assert } from '../../src/modules/index.js'; + +assert.fail(); diff --git a/fixtures/fail/assert-if-error.test.ts b/fixtures/fail/assert-if-error.test.ts new file mode 100644 index 00000000..134c1854 --- /dev/null +++ b/fixtures/fail/assert-if-error.test.ts @@ -0,0 +1,3 @@ +import { assert } from '../../src/modules/index.js'; + +assert.ifError(true, new Error('If error test')); diff --git a/fixtures/fail/assert.test.ts b/fixtures/fail/assert.test.ts new file mode 100644 index 00000000..7da092ad --- /dev/null +++ b/fixtures/fail/assert.test.ts @@ -0,0 +1,3 @@ +import { assert } from '../../src/modules/index.js'; + +assert(false); diff --git a/fixtures/sintax/invalid-file.js b/fixtures/sintax/invalid-file.js new file mode 100644 index 00000000..17c8127e --- /dev/null +++ b/fixtures/sintax/invalid-file.js @@ -0,0 +1 @@ +const: 123 = teste; \ No newline at end of file diff --git a/fixtures/watch/.pokurc.json b/fixtures/watch/.pokurc.json new file mode 100644 index 00000000..51c8f78f --- /dev/null +++ b/fixtures/watch/.pokurc.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://poku.io/schemas/configs.json", + "parallel": true +} diff --git a/fixtures/watch/test/a.test.ts b/fixtures/watch/test/a.test.ts new file mode 100644 index 00000000..3f82cba3 --- /dev/null +++ b/fixtures/watch/test/a.test.ts @@ -0,0 +1,3 @@ +import { assert } from '../../../src/modules/index.js'; + +assert(true, 'target: a'); diff --git a/fixtures/watch/test/b.test.ts b/fixtures/watch/test/b.test.ts new file mode 100644 index 00000000..d65d8990 --- /dev/null +++ b/fixtures/watch/test/b.test.ts @@ -0,0 +1,3 @@ +import { assert } from '../../../src/modules/index.js'; + +assert(true, 'target: b'); diff --git a/fixtures/watch/test/sub/a.test.ts b/fixtures/watch/test/sub/a.test.ts new file mode 100644 index 00000000..0d0555a6 --- /dev/null +++ b/fixtures/watch/test/sub/a.test.ts @@ -0,0 +1,3 @@ +import { assert } from '../../../../src/modules/index.js'; + +assert(true, 'sub: a'); diff --git a/fixtures/watch/test/sub/b.test.ts b/fixtures/watch/test/sub/b.test.ts new file mode 100644 index 00000000..ecf50a2f --- /dev/null +++ b/fixtures/watch/test/sub/b.test.ts @@ -0,0 +1,3 @@ +import { assert } from '../../../../src/modules/index.js'; + +assert(true, 'sub: b'); diff --git a/fixtures/watch/test/sub/deep/.gitkeep b/fixtures/watch/test/sub/deep/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/package-lock.json b/package-lock.json index db116883..3c87c52d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "@biomejs/biome": "1.8.3", "@types/node": "^20.14.12", "c8": "^10.1.2", + "monocart-coverage-reports": "^2.9.3", "packages-update": "^2.0.0", "prettier": "^3.3.3", "tsx": "4.16.2", @@ -676,6 +677,45 @@ "undici-types": "~5.26.4" } }, + "node_modules/acorn": { + "version": "8.12.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", + "integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", + "dev": true, + "license": "MIT", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-loose": { + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/acorn-loose/-/acorn-loose-8.4.0.tgz", + "integrity": "sha512-M0EUka6rb+QC4l9Z3T0nJEzNOO7JcoJlYMrBlyBCiFSXRyxjLKayd4TbQs2FDRWQU1h9FR7QVNHt+PEaoNL5rQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "acorn": "^8.11.0" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-walk": { + "version": "8.3.3", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.3.tgz", + "integrity": "sha512-MxXdReSRhGO7VlFe1bRG/oI7/mdLV9B9JJT0N8vZOhF7gFRR5l3M8W9G8JxmKV+JC5mGqJ0QvqfSOLsCPa4nUw==", + "dev": true, + "license": "MIT", + "dependencies": { + "acorn": "^8.11.0" + }, + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/ansi-regex": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", @@ -867,6 +907,23 @@ "dev": true, "license": "MIT" }, + "node_modules/commander": { + "version": "12.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-12.1.0.tgz", + "integrity": "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/console-grid": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/console-grid/-/console-grid-2.2.2.tgz", + "integrity": "sha512-ohlgXexdDTKLNsZz7DSJuCAwmRc8omSS61txOk39W3NOthgKGr1a1jJpZ5BCQe4PlrwMw01OvPQ1Bl3G7Y/uFg==", + "dev": true, + "license": "MIT" + }, "node_modules/convert-source-map": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz", @@ -889,6 +946,16 @@ "node": ">= 8" } }, + "node_modules/diff-sequences": { + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-29.6.3.tgz", + "integrity": "sha512-EjePK1srD3P08o2j4f0ExnylqRs5B9tJjcp9t1krH2qRi8CCdsYfwe9JgSLurFBWwq4uOlipzfk5fHNvwFKr8Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, "node_modules/eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", @@ -896,6 +963,13 @@ "dev": true, "license": "MIT" }, + "node_modules/eight-colors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/eight-colors/-/eight-colors-1.3.0.tgz", + "integrity": "sha512-hVoK898cR71ADj7L1LZWaECLaSkzzPtqGXIaKv4K6Pzb72QgjLVsQaNI+ELDQQshzFvgp5xTPkaYkPGqw3YR+g==", + "dev": true, + "license": "MIT" + }, "node_modules/emoji-regex": { "version": "9.2.2", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", @@ -1157,6 +1231,13 @@ "dev": true, "license": "ISC" }, + "node_modules/lz-utils": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/lz-utils/-/lz-utils-2.1.0.tgz", + "integrity": "sha512-CMkfimAypidTtWjNDxY8a1bc1mJdyEh04V2FfEQ5Zh8Nx4v7k850EYa+dOWGn9hKG5xOyHP5MkuduAZCTHRvJw==", + "dev": true, + "license": "MIT" + }, "node_modules/make-dir": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-4.0.0.tgz", @@ -1199,6 +1280,65 @@ "node": ">=16 || 14 >=14.17" } }, + "node_modules/monocart-code-viewer": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/monocart-code-viewer/-/monocart-code-viewer-1.1.4.tgz", + "integrity": "sha512-ehSe1lBG7D1VDVLjTkHV63J3zAgzyhlC9OaxOri7D0X4L5/EcZUOG5TEoMmYErL+YGSOQXghU9kSSAelwNnp1Q==", + "dev": true, + "license": "MIT" + }, + "node_modules/monocart-coverage-reports": { + "version": "2.9.3", + "resolved": "https://registry.npmjs.org/monocart-coverage-reports/-/monocart-coverage-reports-2.9.3.tgz", + "integrity": "sha512-guRHe/+FGwUc1x1XT4eKW4za5j9MQcq5Vp7CIZfzoGY1mwVp8LKZpDJUjoBkYAb5Xb+7CFAY3lSyNaQ8FKS6oQ==", + "dev": true, + "license": "MIT", + "workspaces": [ + "packages/*", + "test" + ], + "dependencies": { + "@bcoe/v8-coverage": "^0.2.3", + "@jridgewell/sourcemap-codec": "^1.5.0", + "acorn": "^8.12.1", + "acorn-loose": "^8.4.0", + "acorn-walk": "^8.3.3", + "commander": "^12.1.0", + "console-grid": "^2.2.2", + "diff-sequences": "^29.6.3", + "eight-colors": "^1.3.0", + "foreground-child": "^3.2.1", + "istanbul-lib-coverage": "^3.2.2", + "istanbul-lib-report": "^3.0.1", + "istanbul-reports": "^3.1.7", + "lz-utils": "^2.0.2", + "minimatch": "9.0.5", + "monocart-code-viewer": "^1.1.4", + "monocart-formatter": "^3.0.0", + "monocart-locator": "^1.0.2", + "turbogrid": "^3.2.0" + }, + "bin": { + "mcr": "lib/cli.js" + } + }, + "node_modules/monocart-formatter": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/monocart-formatter/-/monocart-formatter-3.0.0.tgz", + "integrity": "sha512-91OQpUb/9iDqvrblUv6ki11Jxi1d3Fp5u2jfVAPl3UdNp9TM+iBleLzXntUS51W0o+zoya3CJjZZ01z2XWn25g==", + "dev": true, + "license": "MIT", + "workspaces": [ + "packages/*" + ] + }, + "node_modules/monocart-locator": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/monocart-locator/-/monocart-locator-1.0.2.tgz", + "integrity": "sha512-v8W5hJLcWMIxLCcSi/MHh+VeefI+ycFmGz23Froer9QzWjrbg4J3gFJBuI/T1VLNoYxF47bVPPxq8ZlNX4gVCw==", + "dev": true, + "license": "MIT" + }, "node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", @@ -1526,6 +1666,13 @@ "fsevents": "~2.3.3" } }, + "node_modules/turbogrid": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/turbogrid/-/turbogrid-3.2.0.tgz", + "integrity": "sha512-c+2qrCGWzoYpLlxtHgRJ4V5dDRE9fUT7D9maxtdBCqJ0NzCdY+x7xF3/F6cG/+n3VIzKfIS+p9Z/0YMQPf6k/Q==", + "dev": true, + "license": "MIT" + }, "node_modules/typescript": { "version": "5.5.4", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", diff --git a/package.json b/package.json index 7ff20f9f..04cce562 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "test:bun:parallel": "bun src/bin/index.ts --bun -p test/unit test/integration test/e2e", "test:deno:sequential": "tsx src/bin/index.ts --deno --deno-allow=all --deno-cjs ci/test/unit ci/test/integration ci/test/e2e", "test:deno:parallel": "tsx src/bin/index.ts --deno --deno-allow=all --deno-cjs -p ci/test/unit ci/test/integration ci/test/e2e", - "test:c8": "c8 tsx test/c8.test.ts", + "test:c8": "c8 --experimental-monocart tsx test/c8.test.ts", "test:ci": "tsx test/ci.test.ts", "test:ci:node": "FILTER='node-' npm run test:ci", "test:ci:bun": "FILTER='bun-' npm run test:ci", @@ -49,7 +49,7 @@ "clear": "rm -rf lib ci coverage .temp test-src test-tests", "prebuild": "npm run clear", "build": "tsc && tsc -p tsconfig.test.json", - "postbuild": "tsx tools/compatibility/node.ts && cp fixtures/server/package.json ci/fixtures/server/package.json && npm run build:deno && chmod +x lib/bin/index.js", + "postbuild": "tsx tools/compatibility/node.ts && cp fixtures/server/package.json ci/fixtures/server/package.json && rm -f ./lib/@types/*.js ./lib/bin/*.ts && npm run build:deno && chmod +x lib/bin/index.js", "build:deno": "tsc -p tsconfig.mjs.json", "postbuild:deno": "tsx tools/build/check-deno-polyfill.ts", "lint": "npx @biomejs/biome lint && prettier --check .", @@ -62,6 +62,7 @@ "@biomejs/biome": "1.8.3", "@types/node": "^20.14.12", "c8": "^10.1.2", + "monocart-coverage-reports": "^2.9.3", "packages-update": "^2.0.0", "prettier": "^3.3.3", "tsx": "4.16.2", diff --git a/src/modules/essentials/assert.ts b/src/modules/essentials/assert.ts index 9322b869..dfb893a6 100644 --- a/src/modules/essentials/assert.ts +++ b/src/modules/essentials/assert.ts @@ -1,6 +1,4 @@ -/* c8 ignore next */ // ? import nodeAssert from 'node:assert'; import { createAssert } from '../../services/assert.js'; -/* c8 ignore next */ // ? export const assert = createAssert(nodeAssert); diff --git a/src/modules/essentials/poku.ts b/src/modules/essentials/poku.ts index ad60ed92..e3a5cf51 100644 --- a/src/modules/essentials/poku.ts +++ b/src/modules/essentials/poku.ts @@ -1,4 +1,3 @@ -/* c8 ignore next 2 */ // Types import type { Code } from '../../@types/code.js'; import type { Configs } from '../../@types/poku.js'; import process from 'node:process'; diff --git a/src/modules/essentials/strict.ts b/src/modules/essentials/strict.ts index a50bece1..43a82f10 100644 --- a/src/modules/essentials/strict.ts +++ b/src/modules/essentials/strict.ts @@ -1,6 +1,4 @@ -/* c8 ignore next */ // ? import nodeAssert from 'node:assert/strict'; import { createAssert } from '../../services/assert.js'; -/* c8 ignore next */ // ? export const strict = createAssert(nodeAssert); diff --git a/src/modules/helpers/container.ts b/src/modules/helpers/container.ts index 1a1cda12..109cfeda 100644 --- a/src/modules/helpers/container.ts +++ b/src/modules/helpers/container.ts @@ -1,4 +1,3 @@ -/* c8 ignore next */ // Types import type { DockerComposeConfigs, DockerfileConfigs, @@ -11,5 +10,4 @@ const dockerfile = (configs: DockerfileConfigs) => new DockerContainer(configs); /** A minimal API to assist tests that require containers or tests that run inside containers using a **docker-compose.yml**. */ const compose = (configs: DockerComposeConfigs) => new DockerCompose(configs); -/* c8 ignore next */ // ? export const docker = { dockerfile, compose }; diff --git a/src/modules/helpers/describe.ts b/src/modules/helpers/describe.ts index b42015cc..43f359c3 100644 --- a/src/modules/helpers/describe.ts +++ b/src/modules/helpers/describe.ts @@ -1,11 +1,9 @@ -/* c8 ignore next */ // Types import type { DescribeOptions } from '../../@types/describe.js'; import { hrtime, env } from 'node:process'; import { format } from '../../services/format.js'; import { Write } from '../../services/write.js'; import { indentation } from '../../configs/indentation.js'; -/** On **Poku**, `describe` also can be used just as a pretty `console.log` to title your test suites in the terminal */ export async function describe( title: string, cb: () => Promise @@ -14,7 +12,6 @@ export function describe(title: string, cb: () => unknown): void; export async function describe(cb: () => Promise): Promise; export function describe(cb: () => unknown): unknown; export function describe(title: string, options?: DescribeOptions): void; -/* c8 ignore next */ // ? export async function describe( arg1: string | (() => unknown | Promise), arg2?: (() => unknown | Promise) | DescribeOptions @@ -43,7 +40,7 @@ export async function describe( indentation.hasDescribe = true; const { background, icon } = options || {}; - const message = `${cb ? format('◌').dim() : icon || '☰'} ${cb ? format(isPoku ? `${title} › ${format(`${FILE}`).italic().gray()}` : title).dim() : format(title).bold() || ''}`; + const message = `${cb ? format('◌').dim() : icon || '☰'} ${cb ? format(isPoku ? `${title} › ${format(`${FILE}`).italic().gray()}` : title).dim() : format(title).bold()}`; const noBackground = !background; if (noBackground) { diff --git a/src/modules/helpers/each.ts b/src/modules/helpers/each.ts index 7d19fe94..343d84ef 100644 --- a/src/modules/helpers/each.ts +++ b/src/modules/helpers/each.ts @@ -1,4 +1,3 @@ -/* c8 ignore next */ // Types import type { Control, EachOptions } from '../../@types/each.js'; import { each } from '../../configs/each.js'; @@ -63,7 +62,6 @@ export const beforeEach = ( * after.reset(); * ``` */ -/* c8 ignore next */ // ? export const afterEach = (callback: () => unknown): Control => { each.after.cb = () => { if (each.after.status) { diff --git a/src/modules/helpers/env.ts b/src/modules/helpers/env.ts index ca1fcb1c..ca6dedc6 100644 --- a/src/modules/helpers/env.ts +++ b/src/modules/helpers/env.ts @@ -1,4 +1,3 @@ -/* c8 ignore start */ // ? import { readFile } from '../../polyfills/fs.js'; import { sanitizePath } from './list-files.js'; import { @@ -13,7 +12,6 @@ const regex = { /** Reads an environment file and sets the environment variables. */ export const envFile = async (filePath = '.env') => { - /* c8 ignore stop */ const mapEnv = new Map(); const env = await readFile(sanitizePath(filePath), 'utf8'); const lines = env diff --git a/src/modules/helpers/it.ts b/src/modules/helpers/it.ts index 7b96eb9d..12ccf787 100644 --- a/src/modules/helpers/it.ts +++ b/src/modules/helpers/it.ts @@ -1,4 +1,3 @@ -/* c8 ignore next */ // ? import { hrtime, env } from 'node:process'; import { each } from '../../configs/each.js'; import { indentation } from '../../configs/indentation.js'; @@ -12,7 +11,6 @@ export async function it( export function it(message: string, cb: () => unknown): void; export async function it(cb: () => Promise): Promise; export function it(cb: () => unknown): void; -/* c8 ignore next */ // ? export async function it( ...args: [ string | (() => unknown | Promise), @@ -37,7 +35,7 @@ export async function it( indentation.hasItOrTest = true; Write.log( - isPoku && !indentation.hasDescribe + isPoku ? `${indentation.hasDescribe ? ' ' : ''}${format(`◌ ${message} › ${format(`${FILE}`).italic().gray()}`).dim()}` : `${indentation.hasDescribe ? ' ' : ''}${format(`◌ ${message}`).dim()}` ); diff --git a/src/modules/helpers/list-files.ts b/src/modules/helpers/list-files.ts index 0ff34b48..e2c0ee28 100644 --- a/src/modules/helpers/list-files.ts +++ b/src/modules/helpers/list-files.ts @@ -1,4 +1,3 @@ -/* c8 ignore next */ // Types import type { Configs } from '../../@types/list-files.js'; import { env } from 'node:process'; import { sep, join } from 'node:path'; @@ -87,7 +86,6 @@ export const getAllFiles = async ( return files; }; -/* c8 ignore next */ // ? export const listFiles = async ( targetDir: string, configs?: Configs diff --git a/src/modules/helpers/test.ts b/src/modules/helpers/test.ts index a5e1bfa2..109afba4 100644 --- a/src/modules/helpers/test.ts +++ b/src/modules/helpers/test.ts @@ -1,5 +1,3 @@ -/* c8 ignore next */ // ? import { it } from './it.js'; -/* c8 ignore next */ // ? export const test = it; diff --git a/src/modules/helpers/wait-for.ts b/src/modules/helpers/wait-for.ts index 3ded5051..c03dabd4 100644 --- a/src/modules/helpers/wait-for.ts +++ b/src/modules/helpers/wait-for.ts @@ -1,4 +1,3 @@ -/* c8 ignore next */ // Types import type { WaitForExpectedResultOptions, WaitForPortOptions, @@ -95,7 +94,6 @@ export const waitForExpectedResult = async ( await sleep(delay); }; -/* c8 ignore next 2 */ // ? /** Wait until the defined port is active. */ export const waitForPort = async ( port: number, diff --git a/src/parsers/assert.ts b/src/parsers/assert.ts index 342d5377..4c57dd44 100644 --- a/src/parsers/assert.ts +++ b/src/parsers/assert.ts @@ -1,8 +1,6 @@ -/* c8 ignore next */ // ? import { fromEntries, entries } from '../polyfills/object.js'; import { nodeVersion } from './get-runtime.js'; -/* c8 ignore next */ // ? export const parseResultType = (type?: unknown): string => { const recurse = (value: unknown): unknown => { if ( diff --git a/src/parsers/find-file-from-stack.ts b/src/parsers/find-file-from-stack.ts index 39a95228..9ae40817 100644 --- a/src/parsers/find-file-from-stack.ts +++ b/src/parsers/find-file-from-stack.ts @@ -1,7 +1,5 @@ -/* c8 ignore next */ // ? const regex = /at\s(\/.+|file:.+)|^(\s+)at\smodule\scode\s\((\/.+|file:.+)\)/i; -/* c8 ignore next */ // ? export const findFile = (error: Error) => { const stackLines = error.stack?.split('\n') || []; diff --git a/src/parsers/get-arg.ts b/src/parsers/get-arg.ts index 73019a13..87d90fdb 100644 --- a/src/parsers/get-arg.ts +++ b/src/parsers/get-arg.ts @@ -1,4 +1,3 @@ -/* c8 ignore next */ // ? import { argv } from 'node:process'; const [, , ...processArgs] = argv; @@ -49,7 +48,6 @@ export const getPaths = ( return hasPaths ? paths : undefined; }; -/* c8 ignore next */ // ? export const argToArray = ( arg: string, prefix = '--', diff --git a/src/parsers/options.ts b/src/parsers/options.ts index fb353e91..abfcccdb 100644 --- a/src/parsers/options.ts +++ b/src/parsers/options.ts @@ -1,4 +1,3 @@ -/* c8 ignore next */ // Types import type { ConfigFile, ConfigJSONFile } from '../@types/poku.js'; import { cwd } from 'node:process'; import { normalize, join } from 'node:path'; @@ -7,7 +6,6 @@ import { JSONC } from '../polyfills/jsonc.js'; const processCWD = cwd(); -/* c8 ignore next */ // ? export const getConfigs = async ( customPath?: string ): Promise => { diff --git a/src/parsers/output.ts b/src/parsers/output.ts index fcf4de1e..8fe9897d 100644 --- a/src/parsers/output.ts +++ b/src/parsers/output.ts @@ -1,4 +1,3 @@ -/* c8 ignore next */ // Types import type { Configs } from '../@types/poku.js'; import { results } from '../configs/poku.js'; @@ -13,7 +12,6 @@ export const isQuiet = (configs?: Configs): boolean => export const isDebug = (configs?: Configs): boolean => Boolean(configs?.debug); -/* c8 ignore next */ // ? export const parserOutput = (options: { output: string; result: boolean; diff --git a/src/parsers/time.ts b/src/parsers/time.ts index 1c4add2f..c65d9ae2 100644 --- a/src/parsers/time.ts +++ b/src/parsers/time.ts @@ -1,4 +1,3 @@ -/* c8 ignore next */ // ? export const parseTime = (date: Date): string => { const hours = date.getHours().toString().padStart(2, '0'); const minutes = date.getMinutes().toString().padStart(2, '0'); @@ -7,7 +6,6 @@ export const parseTime = (date: Date): string => { return `${hours}:${minutes}:${seconds}`; }; -/* c8 ignore next */ // ? export const parseTimeToSecs = (milliseconds: string): string => { const ms = Number.parseFloat(milliseconds); const seconds = (ms / 1000).toFixed(2); diff --git a/src/services/assert.ts b/src/services/assert.ts index a02b08e9..05e19173 100644 --- a/src/services/assert.ts +++ b/src/services/assert.ts @@ -1,4 +1,3 @@ -/* c8 ignore next 3 */ // Types import type { ProcessAssertionOptions } from '../@types/assert.js'; import type assert from 'node:assert'; import type { AssertPredicate } from 'node:assert'; @@ -46,7 +45,6 @@ export const processAssert = async ( Write.log(message); } - /* c8 ignore start */ } catch (error) { if (error instanceof AssertionError) { const { code, actual, expected, operator } = error; @@ -113,7 +111,6 @@ export const processAssert = async ( } }; -/* c8 ignore next */ // ? export const createAssert = (nodeAssert: typeof assert) => { const ok = ( value: unknown, @@ -221,7 +218,6 @@ export const createAssert = (nodeAssert: typeof assert) => { ); }; - /* c8 ignore start */ const fail = (message?: ProcessAssertionOptions['message']): never => { processAssert( () => { @@ -236,7 +232,6 @@ export const createAssert = (nodeAssert: typeof assert) => { process.exit(1); }; - /* c8 ignore stop */ function doesNotThrow( block: () => unknown, diff --git a/src/services/container.ts b/src/services/container.ts index b13da845..57db53c3 100644 --- a/src/services/container.ts +++ b/src/services/container.ts @@ -174,7 +174,7 @@ export class DockerCompose { } public async up() { - const args: string[] = ['-f', this.file]; + const args: string[] = ['compose', '-f', this.file]; if (this.envFile) { args.push(...['--env-file', this.envFile]); @@ -194,7 +194,7 @@ export class DockerCompose { } return await runDockerCommand( - 'docker-compose', + 'docker', args, { cwd: this.cwd }, this.verbose @@ -212,8 +212,8 @@ export class DockerCompose { } return await runDockerCommand( - 'docker-compose', - [...args, 'down'], + 'docker', + ['compose', ...args, 'down'], { cwd: this.cwd }, this.verbose ); diff --git a/src/services/each.ts b/src/services/each.ts index e4297042..065be476 100644 --- a/src/services/each.ts +++ b/src/services/each.ts @@ -1,4 +1,3 @@ -/* c8 ignore next */ // Types import type { Configs } from '../@types/poku.js'; import { format } from './format.js'; import { Write } from '../services/write.js'; @@ -59,7 +58,6 @@ export const beforeEach = async (fileRelative: string, configs?: Configs) => { return true; }; -/* c8 ignore next */ // ? export const afterEach = async (fileRelative: string, configs?: Configs) => { if (configs?.afterEach) { return await eachCore('afterEach', fileRelative, configs); diff --git a/src/services/env.ts b/src/services/env.ts index 353808e9..6549f846 100644 --- a/src/services/env.ts +++ b/src/services/env.ts @@ -1,4 +1,3 @@ -/* c8 ignore next */ // ? export const removeComments = (input: string) => { let output = ''; let quoteChar = ''; @@ -27,7 +26,6 @@ export const removeComments = (input: string) => { return output.trim(); }; -/* c8 ignore net */ // ? export const parseEnvLine = (line: string) => { const index = line.indexOf('='); @@ -44,7 +42,6 @@ export const parseEnvLine = (line: string) => { return { arg, value }; }; -/* c8 ignore next */ // ? export const resolveEnvVariables = (str: string, env: typeof process.env) => { let result = ''; let i = 0; diff --git a/src/services/format.ts b/src/services/format.ts index af18cf5e..d7f94c75 100644 --- a/src/services/format.ts +++ b/src/services/format.ts @@ -1,4 +1,3 @@ -/* c8 ignore next */ // ? export const backgroundColor = { white: 7, black: 40, @@ -88,6 +87,5 @@ export class Formatter { export const format = (text: string) => Formatter.create(text); -/* c8 ignore next */ // ? export const getLargestStringLength = (arr: string[]): number => arr.reduce((max, current) => Math.max(max, current.length), 0); diff --git a/src/services/map-tests.ts b/src/services/map-tests.ts index 4796470a..a0f97969 100644 --- a/src/services/map-tests.ts +++ b/src/services/map-tests.ts @@ -1,4 +1,3 @@ -/* c8 ignore next */ // ? import { relative, dirname } from 'node:path'; import { stat, readFile } from '../polyfills/fs.js'; import { listFiles } from '../modules/helpers/list-files.js'; @@ -151,7 +150,6 @@ export const createImportMap = async ( ); }; -/* c8 ignore next */ // ? export const mapTests = async ( srcDir: string, testPaths: string[], diff --git a/src/services/run-test-file.ts b/src/services/run-test-file.ts index 4bc63b11..9dc5c004 100644 --- a/src/services/run-test-file.ts +++ b/src/services/run-test-file.ts @@ -1,4 +1,3 @@ -/* c8 ignore next */ // Types import type { Configs } from '../@types/poku.js'; import { cwd as processCWD, hrtime, env } from 'node:process'; import { relative } from 'node:path'; @@ -13,23 +12,21 @@ import { Write } from './write.js'; const cwd = processCWD(); -/* c8 ignore next */ // ? export const runTestFile = async ( filePath: string, configs?: Configs ): Promise => { - /* c8 ignore start */ const runtimeOptions = runner(filePath, configs); const runtime = runtimeOptions.shift()!; const runtimeArguments = [ ...runtimeOptions, + /* c8 ignore next 5 */ configs?.deno?.cjs === true || (Array.isArray(configs?.deno?.cjs) && configs.deno.cjs.some((ext) => filePath.includes(ext))) ? 'https://cdn.jsdelivr.net/npm/poku/lib/polyfills/deno.mjs' : filePath, ]; - /* c8 ignore stop */ const fileRelative = relative(cwd, filePath); const showLogs = !isQuiet(configs); diff --git a/src/services/run-tests.ts b/src/services/run-tests.ts index b9a8daf9..27138846 100644 --- a/src/services/run-tests.ts +++ b/src/services/run-tests.ts @@ -1,4 +1,3 @@ -/* c8 ignore start */ // Types import type { Configs } from '../@types/poku.js'; import { cwd as processCWD, hrtime } from 'node:process'; import { join, relative, sep } from 'node:path'; @@ -62,7 +61,6 @@ export const runTests = async ( Write.log( `${indentation.test}${format('✔').success()} ${log}${format(` › ${total}ms`).success().dim()}${nextLine}` ); - /* c8 ignore start */ } else { ++results.fail; @@ -85,14 +83,11 @@ export const runTests = async ( break; } } - - /* c8 ignore stop */ } return passed; }; -/* c8 ignore next */ // ? export const runTestsParallel = async ( dir: string, configs?: Configs @@ -117,10 +112,6 @@ export const runTestsParallel = async ( try { for (const fileGroup of filesByConcurrency) { const promises = fileGroup.map(async (filePath) => { - if (configs?.failFast && results.fail > 0) { - return; - } - const testPassed = await runTestFile(filePath, configs); if (!testPassed) { @@ -144,7 +135,6 @@ export const runTestsParallel = async ( } return concurrencyResults.every((group) => group.every((result) => result)); - /* c8 ignore start */ } catch (error) { if (showLogs) { Write.hr(); @@ -153,5 +143,4 @@ export const runTestsParallel = async ( return false; } - /* c8 ignore stop */ }; diff --git a/src/services/watch.ts b/src/services/watch.ts index 4d787687..06bb8d76 100644 --- a/src/services/watch.ts +++ b/src/services/watch.ts @@ -1,4 +1,3 @@ -/* c8 ignore next 2 */ // Types import type { WatchCallback } from '../@types/watch.js'; import { watch as nodeWatch, type FSWatcher } from 'node:fs'; import { join } from 'node:path'; @@ -117,7 +116,6 @@ export class Watcher { } } -/* c8 ignore next */ // ? export const watch = async (path: string, callback: WatchCallback) => { const watcher = new Watcher(path, callback); diff --git a/src/services/write.ts b/src/services/write.ts index 340f49ba..adf48405 100644 --- a/src/services/write.ts +++ b/src/services/write.ts @@ -1,4 +1,3 @@ -/* c8 ignore next */ // Types import type { Formatter } from '../services/format.js'; import { stdout } from 'node:process'; @@ -11,5 +10,4 @@ export const Write = { Write.log(`\n\x1b[2m\x1b[90m${line}\x1b[0m\n`); }, - /* c8 ignore next */ // ? } as const; diff --git a/test/e2e/before-and-after-each.test.ts b/test/e2e/before-and-after-each.test.ts index ea0951e3..c13b7539 100644 --- a/test/e2e/before-and-after-each.test.ts +++ b/test/e2e/before-and-after-each.test.ts @@ -3,6 +3,12 @@ import { describe } from '../../src/modules/helpers/describe.js'; import { it } from '../../src/modules/helpers/it.js'; import { poku } from '../../src/modules/essentials/poku.js'; import { assert } from '../../src/modules/essentials/assert.js'; +import { isProduction } from '../helpers/capture-cli.test.js'; +import { skip } from '../../src/modules/helpers/skip.js'; + +if (isProduction) { + skip(); +} test(async () => { const prepareService = () => new Promise((resolve) => resolve(undefined)); diff --git a/test/e2e/fail-fast.test.ts b/test/e2e/fail-fast.test.ts new file mode 100644 index 00000000..6257e243 --- /dev/null +++ b/test/e2e/fail-fast.test.ts @@ -0,0 +1,29 @@ +import { describe } from '../../src/modules/helpers/describe.js'; +import { it } from '../../src/modules/helpers/it.js'; +import { assert } from '../../src/modules/essentials/assert.js'; +import { inspectCLI, isProduction } from '../helpers/capture-cli.test.js'; +import { skip } from '../../src/modules/helpers/skip.js'; + +if (isProduction) { + skip(); +} + +describe('Fast Fast', async () => { + await it('Parallel / Concurrent', async () => { + const results = await inspectCLI('npx tsx ../../../src/bin/index.ts', { + cwd: './fixtures/fail-fast/parallel', + }); + + assert.match(results.stderr, /fail-fast/, 'Fail Fast is enabled'); + assert.match(results.stdout, /FAIL › 1/, 'Needs to fail 1'); + }); + + await it('Sequential', async () => { + const results = await inspectCLI('npx tsx ../../../src/bin/index.ts', { + cwd: './fixtures/fail-fast/sequential', + }); + + assert.match(results.stdout, /fail-fast/, 'Fail Fast is enabled'); + assert.match(results.stdout, /FAIL › 1/, 'Needs to fail 1'); + }); +}); diff --git a/test/e2e/failure.test.ts b/test/e2e/failure.test.ts new file mode 100644 index 00000000..371c09a4 --- /dev/null +++ b/test/e2e/failure.test.ts @@ -0,0 +1,78 @@ +import { describe } from '../../src/modules/helpers/describe.js'; +import { it } from '../../src/modules/helpers/it.js'; +import { assert } from '../../src/modules/essentials/assert.js'; +import { inspectCLI, isProduction } from '../helpers/capture-cli.test.js'; +import { skip } from '../../src/modules/helpers/skip.js'; + +if (isProduction) { + skip(); +} + +describe('Failure', async () => { + await it('Sequential', async () => { + const results = await inspectCLI('npx tsx ../../src/bin/index.ts', { + cwd: './fixtures/fail', + }); + + assert.match(results.stdout, /FAIL › 5/, 'Needs to fail 5'); + assert.match( + results.stdout, + /Should fail/, + 'Needs to show custom message for "fail"' + ); + assert.match( + results.stdout, + /If error test/, + 'Needs to show custom message for "ifError"' + ); + }); + + await it('Parallel / Concurrent', async () => { + const results = await inspectCLI('npx tsx ../../src/bin/index.ts -p', { + cwd: './fixtures/fail', + }); + + assert.match(results.stdout, /FAIL › 5/, 'Needs to fail 5'); + assert.match( + results.stdout, + /Should fail/, + 'Needs to show custom message fail' + ); + assert.match( + results.stdout, + /If error test/, + 'Needs to show custom message for "ifError"' + ); + }); + + await it('Missing File', async () => { + const results = await inspectCLI( + 'npx tsx ../../src/bin/index.ts ./foo/bar.js', + { + cwd: './fixtures/fail', + } + ); + + assert.match(results.stderr, /ENOENT/, 'Needs to show error message"'); + assert.strictEqual(results.exitCode, 1, 'Exit Code needs to be 0'); + }); + + await it('Wrong Sintax', async () => { + const results = await inspectCLI( + 'npx tsx ../../src/bin/index.ts invalid-file.js', + { + cwd: './fixtures/sintax', + } + ); + + // console.log(results.stdout); + // console.log(results.stderr); + + assert.match( + results.stdout, + /SyntaxError/, + 'Needs to show sintax error message"' + ); + assert.strictEqual(results.exitCode, 1, 'Exit Code needs to be 0'); + }); +}); diff --git a/test/e2e/watch.test.ts b/test/e2e/watch.test.ts new file mode 100644 index 00000000..6b2fa2b7 --- /dev/null +++ b/test/e2e/watch.test.ts @@ -0,0 +1,62 @@ +import { describe } from '../../src/modules/helpers/describe.js'; +import { it } from '../../src/modules/helpers/it.js'; +import { assert } from '../../src/modules/essentials/assert.js'; +import { watchCLI } from '../helpers/capture-cli.test.js'; +import { skip } from '../../src/modules/helpers/skip.js'; +import { + sleep, + waitForExpectedResult, +} from '../../src/modules/helpers/wait-for.js'; + +skip('TODO: Create files to test e2e maps'); + +import { readFile, writeFile } from 'node:fs/promises'; + +const saveFileUnchanged = async (filename: string) => { + const data = await readFile(filename, 'utf-8'); + + await writeFile(filename, data, 'utf-8'); +}; + +describe('Watch Mode', async () => { + const watcher = watchCLI( + 'bun ../../src/bin/index.ts -w --watch-interval=500', + { + cwd: './fixtures/watch', + } + ); + + await waitForExpectedResult(() => { + const results = watcher.getOutput(); + + return /Watching:/.test(results.stdout); + }, true); + + await Promise.all([ + saveFileUnchanged('./fixtures/watch/test/a.test.ts'), + saveFileUnchanged('./fixtures/watch/test/sub/b.test.ts'), + saveFileUnchanged('./fixtures/watch/test/a.test.ts'), + saveFileUnchanged('./fixtures/watch/test/sub/b.test.ts'), + ]); + + await sleep(100); + + const results = watcher.getOutput(); + await watcher.kill(); + + await it('Top path', async () => { + const watched = results.stdout + .split('\n') + .filter((result) => /test\/a\.test\.ts/.test(result)).length; + + assert(watched >= 4); + }); + + await it('Sub path', async () => { + const watched = results.stdout + .split('\n') + .filter((result) => /test\/sub\/b\.test\.ts/.test(result)).length; + + assert(watched >= 4); + }); +}); diff --git a/test/helpers/capture-cli.test.ts b/test/helpers/capture-cli.test.ts index b414e0f4..527e4aec 100644 --- a/test/helpers/capture-cli.test.ts +++ b/test/helpers/capture-cli.test.ts @@ -1,6 +1,11 @@ import process from 'node:process'; -import { spawn, type SpawnOptionsWithoutStdio } from 'node:child_process'; +import { + type ChildProcessWithoutNullStreams, + spawn, + type SpawnOptionsWithoutStdio, +} from 'node:child_process'; import { isWindows, runner } from '../../src/parsers/get-runner.js'; +import { kill as pokuKill } from '../../src/modules/helpers/kill.js'; // `/_.ts`: Simulate TypeScript file for Deno const currentFile = typeof __filename === 'string' ? __filename : '/_.ts'; @@ -43,10 +48,29 @@ export const executeCLI = (args: string[]): Promise => }); }); +type InspectCLIResult = { + stdout: string; + stderr: string; + exitCode: number; + process: ChildProcessWithoutNullStreams; + PID: number; + kill: () => Promise; +}; + +type WatchCLIResult = { + process: ChildProcessWithoutNullStreams; + PID: number; + kill: () => Promise; + getOutput: () => { + stdout: string; + stderr: string; + }; +}; + export const inspectCLI = ( command: string, options?: SpawnOptionsWithoutStdio -): Promise<{ stdout: string; stderr: string; exitCode: number }> => +): Promise => new Promise((resolve, reject) => { const [cmd, ...args] = command.split(' '); @@ -55,6 +79,12 @@ export const inspectCLI = ( ...options, }); + const PID = childProcess.pid!; + + const kill = async () => { + await pokuKill.pid(PID); + }; + let stdout = ''; let stderr = ''; @@ -71,6 +101,55 @@ export const inspectCLI = ( }); childProcess.on('close', (code: number) => { - resolve({ stdout, stderr, exitCode: code }); + resolve({ + stdout, + stderr, + exitCode: code, + process: childProcess, + PID, + kill, + }); }); }); + +export const watchCLI = ( + command: string, + options?: SpawnOptionsWithoutStdio +): WatchCLIResult => { + const [cmd, ...args] = command.split(' '); + + let stdout = ''; + let stderr = ''; + + const childProcess = spawn(cmd, args, { + shell: isWindows, + ...options, + }); + + const PID = childProcess.pid!; + + const kill = async () => { + await pokuKill.pid(PID); + }; + + const getOutput = () => { + return { + stdout, + stderr, + }; + }; + + childProcess.stdout.on('data', (data: Buffer) => { + stdout += data.toString(); + }); + + childProcess.stderr.on('data', (data: Buffer) => { + stderr += data.toString(); + }); + + childProcess.on('error', (error: Error) => { + throw error; + }); + + return { kill, PID, process: childProcess, getOutput }; +}; diff --git a/test/integration/import.test.ts b/test/integration/import.test.ts index c0f07242..29c2abfd 100644 --- a/test/integration/import.test.ts +++ b/test/integration/import.test.ts @@ -12,6 +12,7 @@ index.test('Import Suite', () => { index.assert.ok(index.assert, 'Importing assert method'); index.assert.ok(index.strict, 'Importing strict method'); + index.assert.ok(index.defineConfig, 'Importing defineConfig method'); index.assert.ok(index.envFile, 'Importing envFile method'); index.assert.ok(index.startService, 'Importing startService method'); index.assert.ok(index.startScript, 'Importing startScript method'); diff --git a/test/unit/define-configs.test.ts b/test/unit/define-configs.test.ts new file mode 100644 index 00000000..342aaa7e --- /dev/null +++ b/test/unit/define-configs.test.ts @@ -0,0 +1,14 @@ +// import { assert } from '../../src/modules/essentials/assert.js'; +// import { isProduction } from '../helpers/capture-cli.test.js'; +// import { skip } from '../../src/modules/helpers/skip.js'; +// import { defineConfig } from '../../src/modules/index.js'; + +// if (isProduction) { +// skip(); +// } + +// assert.deepStrictEqual( +// defineConfig({ debug: true }), +// { debug: true }, +// 'Reflect configs' +// ); diff --git a/tsconfig.json b/tsconfig.json index 08d946c8..23eccd4d 100755 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,12 @@ { "include": ["src"], - "exclude": ["test", "tools", "src/@types", "src/polyfills/deno.mts"], + "exclude": [ + "test", + "tools", + "src/@types", + "src/polyfills/deno.mts", + "fixtures/sintax/invalid-file.js" + ], "compilerOptions": { "target": "ES2018", "lib": ["ES2018"], diff --git a/tsconfig.test.json b/tsconfig.test.json index f1257b73..cddf5070 100644 --- a/tsconfig.test.json +++ b/tsconfig.test.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.json", "include": ["test", "src", "fixtures"], - "exclude": ["tools"], + "exclude": ["tools", "fixtures/sintax/invalid-file.js"], "compilerOptions": { "outDir": "ci", "declaration": false,