From ba9e8a8bdb982331f78b1713d3dfd7d41c50e038 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Tue, 7 Apr 2026 18:44:32 -0300 Subject: [PATCH 1/5] feat: support for YAML and TOML config files --- package-lock.json | 30 +++++++++++++++++++++++++++++- package.json | 4 +++- src/config.ts | 46 +++++++++++++++++++++++++++++++++++++++++++++- src/index.ts | 12 ++++++------ 4 files changed, 83 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0719e9a..859a47f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,9 @@ "license": "MIT", "dependencies": { "c8": "^10.1.3", - "jsonc.min": "^1.1.2" + "jsonc.min": "^1.1.2", + "toml.min": "^1.0.0", + "yaml.min": "^0.1.0" }, "devDependencies": { "@ianvs/prettier-plugin-sort-imports": "^4.7.1", @@ -1740,6 +1742,19 @@ "node": ">=18" } }, + "node_modules/toml.min": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/toml.min/-/toml.min-1.0.0.tgz", + "integrity": "sha512-AxGMz8dc0gx3xGYGFzs9SrcqamCsJEUQ1D6whZgfeJWCHvytqhsl2OExMc2xEWjy1S51HHuap0r6bK4O+CcjiA==", + "license": "MIT", + "engines": { + "node": ">=18.x.x" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wellwelwel" + } + }, "node_modules/tsx": { "version": "4.21.0", "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.21.0.tgz", @@ -1910,6 +1925,19 @@ "node": ">=10" } }, + "node_modules/yaml.min": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/yaml.min/-/yaml.min-0.1.0.tgz", + "integrity": "sha512-DapivAF/9X7Knuy+012K8ue76RYWbpJoBC4/O6cnIRRcYqdOn7I9bTUO2C2+vpdqei5kFomORr+dhz+loeBtfQ==", + "license": "MIT", + "engines": { + "node": ">=18.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wellwelwel" + } + }, "node_modules/yargs": { "version": "17.7.2", "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", diff --git a/package.json b/package.json index e80d315..aabc87a 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,9 @@ }, "dependencies": { "c8": "^10.1.3", - "jsonc.min": "^1.1.2" + "jsonc.min": "^1.1.2", + "toml.min": "^1.0.0", + "yaml.min": "^0.1.0" }, "peerDependencies": { "monocart-coverage-reports": "^2.12.9", diff --git a/src/config.ts b/src/config.ts index 9d10bf0..d0e0e2c 100644 --- a/src/config.ts +++ b/src/config.ts @@ -2,6 +2,42 @@ import type { CoverageOptions } from './types.js'; import { existsSync, readFileSync } from 'node:fs'; import { join } from 'node:path'; import { JSONC } from 'jsonc.min'; +import { parse as tomlParse } from 'toml.min'; +import { parse as yamlParse } from 'yaml.min'; + +const scriptExtensions = new Set([ + '.js', + '.mjs', + '.cjs', + '.ts', + '.mts', + '.cts', +]); + +const isScript = (path: string): boolean => + scriptExtensions.has(getExtension(path)); + +const isToml = (path: string): boolean => getExtension(path) === '.toml'; + +const isYaml = (path: string): boolean => { + const ext = getExtension(path); + return ext === '.yml' || ext === '.yaml'; +}; + +const getExtension = (filePath: string): string => { + const dotIndex = filePath.lastIndexOf('.'); + if (dotIndex === -1) return ''; + return filePath.slice(dotIndex); +}; + +const parseConfig = ( + content: string, + filePath: string +): Record => { + if (isToml(filePath)) return tomlParse(content) as Record; + if (isYaml(filePath)) return yamlParse(content) as Record; + return JSONC.parse(content) as Record; +}; const kebabMap: Record = { 'reports-dir': 'reportsDirectory', @@ -40,12 +76,20 @@ export const loadConfig = ( '.c8rc', '.c8rc.json', '.c8rc.jsonc', + '.c8rc.toml', + '.c8rc.yaml', + '.c8rc.yml', '.nycrc', '.nycrc.json', '.nycrc.jsonc', + '.nycrc.toml', + '.nycrc.yaml', + '.nycrc.yml', ]; for (const file of expectedFiles) { + if (isScript(file)) continue; + const filePath = join(cwd, file); if (!existsSync(filePath)) continue; @@ -53,7 +97,7 @@ export const loadConfig = ( try { const content = readFileSync(filePath, 'utf8'); - return mapKeys(JSONC.parse(content) as Record); + return mapKeys(parseConfig(content, file)); } catch {} } diff --git a/src/index.ts b/src/index.ts index 36b36a4..9addc44 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,6 +21,11 @@ export const coverage = ( setup(context) { if (options.requireFlag && !process.argv.includes('--coverage')) return; + if (context.runtime !== 'node') + console.warn( + `[@pokujs/c8] V8 coverage is only supported on Node.js (current runtime: ${context.runtime}). Coverage data may not be collected.` + ); + enabled = true; const cliConfig = process.argv @@ -28,13 +33,8 @@ export const coverage = ( ?.split('=')[1]; const fileConfig = loadConfig(context.cwd, cliConfig ?? options.config); - options = { ...fileConfig, ...options }; - - if (context.runtime !== 'node') - console.warn( - `[@pokujs/c8] V8 coverage is only supported on Node.js (current runtime: ${context.runtime}). Coverage data may not be collected.` - ); + options = { ...fileConfig, ...options }; originalEnv = process.env.NODE_V8_COVERAGE; userProvidedTempDir = typeof options.tempDirectory === 'string'; From fc1bcb4597e1b99e9b6764bb659dc0da77d3447c Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Tue, 7 Apr 2026 18:53:11 -0300 Subject: [PATCH 2/5] chore: improve types --- src/config.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/config.ts b/src/config.ts index d0e0e2c..0e05911 100644 --- a/src/config.ts +++ b/src/config.ts @@ -30,13 +30,10 @@ const getExtension = (filePath: string): string => { return filePath.slice(dotIndex); }; -const parseConfig = ( - content: string, - filePath: string -): Record => { - if (isToml(filePath)) return tomlParse(content) as Record; - if (isYaml(filePath)) return yamlParse(content) as Record; - return JSONC.parse(content) as Record; +const parseConfig = (content: string, filePath: string): CoverageOptions => { + if (isToml(filePath)) return tomlParse(content); + if (isYaml(filePath)) return yamlParse(content); + return JSONC.parse(content); }; const kebabMap: Record = { From 28dee44fd68455535202c581ed412bf132b767b9 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Wed, 8 Apr 2026 08:33:12 -0300 Subject: [PATCH 3/5] chore: update `yaml.min` --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 859a47f..05ec977 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "c8": "^10.1.3", "jsonc.min": "^1.1.2", "toml.min": "^1.0.0", - "yaml.min": "^0.1.0" + "yaml.min": "^1.0.0" }, "devDependencies": { "@ianvs/prettier-plugin-sort-imports": "^4.7.1", @@ -1926,9 +1926,9 @@ } }, "node_modules/yaml.min": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/yaml.min/-/yaml.min-0.1.0.tgz", - "integrity": "sha512-DapivAF/9X7Knuy+012K8ue76RYWbpJoBC4/O6cnIRRcYqdOn7I9bTUO2C2+vpdqei5kFomORr+dhz+loeBtfQ==", + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/yaml.min/-/yaml.min-1.0.0.tgz", + "integrity": "sha512-p/mX2R20rnblQo57YJHcOpFtbut5JBeq0PLMn2WXQn9XLRMGmisMRQk/ug1rnpA4eBKaTr9O7H332hdIwMUhxA==", "license": "MIT", "engines": { "node": ">=18.0.0" diff --git a/package.json b/package.json index aabc87a..4d28372 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "c8": "^10.1.3", "jsonc.min": "^1.1.2", "toml.min": "^1.0.0", - "yaml.min": "^0.1.0" + "yaml.min": "^1.0.0" }, "peerDependencies": { "monocart-coverage-reports": "^2.12.9", From 4300f9640a501ba9cfa4d17490bbfeb88d3ce975 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Wed, 8 Apr 2026 08:55:18 -0300 Subject: [PATCH 4/5] ci: add tests --- test/__fixtures__/e2e/configs/.c8rc.jsonc | 5 +++++ test/__fixtures__/e2e/configs/.c8rc.toml | 2 ++ test/__fixtures__/e2e/configs/.c8rc.yaml | 4 ++++ .../e2e/configs/config-file-jsonc.config.js | 11 +++++++++++ .../e2e/configs/config-file-toml.config.js | 11 +++++++++++ .../e2e/configs/config-file-yaml.config.js | 11 +++++++++++ test/e2e/coverage-config-file-jsonc.test.ts | 17 +++++++++++++++++ test/e2e/coverage-config-file-toml.test.ts | 17 +++++++++++++++++ test/e2e/coverage-config-file-yaml.test.ts | 17 +++++++++++++++++ 9 files changed, 95 insertions(+) create mode 100644 test/__fixtures__/e2e/configs/.c8rc.jsonc create mode 100644 test/__fixtures__/e2e/configs/.c8rc.toml create mode 100644 test/__fixtures__/e2e/configs/.c8rc.yaml create mode 100644 test/__fixtures__/e2e/configs/config-file-jsonc.config.js create mode 100644 test/__fixtures__/e2e/configs/config-file-toml.config.js create mode 100644 test/__fixtures__/e2e/configs/config-file-yaml.config.js create mode 100644 test/e2e/coverage-config-file-jsonc.test.ts create mode 100644 test/e2e/coverage-config-file-toml.test.ts create mode 100644 test/e2e/coverage-config-file-yaml.test.ts diff --git a/test/__fixtures__/e2e/configs/.c8rc.jsonc b/test/__fixtures__/e2e/configs/.c8rc.jsonc new file mode 100644 index 0000000..5116ff0 --- /dev/null +++ b/test/__fixtures__/e2e/configs/.c8rc.jsonc @@ -0,0 +1,5 @@ +{ + // JSONC: comments should be supported in .jsonc files + "include": ["src/**"], + "reporter": ["text"] +} diff --git a/test/__fixtures__/e2e/configs/.c8rc.toml b/test/__fixtures__/e2e/configs/.c8rc.toml new file mode 100644 index 0000000..6cccf78 --- /dev/null +++ b/test/__fixtures__/e2e/configs/.c8rc.toml @@ -0,0 +1,2 @@ +include = ["src/**"] +reporter = ["text"] diff --git a/test/__fixtures__/e2e/configs/.c8rc.yaml b/test/__fixtures__/e2e/configs/.c8rc.yaml new file mode 100644 index 0000000..2aacc0a --- /dev/null +++ b/test/__fixtures__/e2e/configs/.c8rc.yaml @@ -0,0 +1,4 @@ +include: + - 'src/**' +reporter: + - text diff --git a/test/__fixtures__/e2e/configs/config-file-jsonc.config.js b/test/__fixtures__/e2e/configs/config-file-jsonc.config.js new file mode 100644 index 0000000..598aec7 --- /dev/null +++ b/test/__fixtures__/e2e/configs/config-file-jsonc.config.js @@ -0,0 +1,11 @@ +const { coverage } = require('../../../../lib/index.js'); + +/** @type {import('poku').PokuConfig} */ +module.exports = { + include: ['test/'], + plugins: [ + coverage({ + config: 'configs/.c8rc.jsonc', + }), + ], +}; diff --git a/test/__fixtures__/e2e/configs/config-file-toml.config.js b/test/__fixtures__/e2e/configs/config-file-toml.config.js new file mode 100644 index 0000000..fe178ab --- /dev/null +++ b/test/__fixtures__/e2e/configs/config-file-toml.config.js @@ -0,0 +1,11 @@ +const { coverage } = require('../../../../lib/index.js'); + +/** @type {import('poku').PokuConfig} */ +module.exports = { + include: ['test/'], + plugins: [ + coverage({ + config: 'configs/.c8rc.toml', + }), + ], +}; diff --git a/test/__fixtures__/e2e/configs/config-file-yaml.config.js b/test/__fixtures__/e2e/configs/config-file-yaml.config.js new file mode 100644 index 0000000..fe41795 --- /dev/null +++ b/test/__fixtures__/e2e/configs/config-file-yaml.config.js @@ -0,0 +1,11 @@ +const { coverage } = require('../../../../lib/index.js'); + +/** @type {import('poku').PokuConfig} */ +module.exports = { + include: ['test/'], + plugins: [ + coverage({ + config: 'configs/.c8rc.yaml', + }), + ], +}; diff --git a/test/e2e/coverage-config-file-jsonc.test.ts b/test/e2e/coverage-config-file-jsonc.test.ts new file mode 100644 index 0000000..7e8ee8d --- /dev/null +++ b/test/e2e/coverage-config-file-jsonc.test.ts @@ -0,0 +1,17 @@ +import { assert, test } from 'poku'; +import { inspectPoku } from 'poku/plugins'; + +const fixtureDir = 'test/__fixtures__/e2e'; +const pokuBin = 'node_modules/poku/lib/bin/index.js'; + +test('loads JSONC config file with .jsonc extension', async () => { + const result = await inspectPoku({ + command: '-c=configs/config-file-jsonc.config.js', + spawnOptions: { cwd: fixtureDir }, + bin: pokuBin, + }); + + assert.strictEqual(result.exitCode, 0); + assert(result.stdout.includes('math.ts')); + assert(result.stdout.includes('%')); +}); diff --git a/test/e2e/coverage-config-file-toml.test.ts b/test/e2e/coverage-config-file-toml.test.ts new file mode 100644 index 0000000..84048ad --- /dev/null +++ b/test/e2e/coverage-config-file-toml.test.ts @@ -0,0 +1,17 @@ +import { assert, test } from 'poku'; +import { inspectPoku } from 'poku/plugins'; + +const fixtureDir = 'test/__fixtures__/e2e'; +const pokuBin = 'node_modules/poku/lib/bin/index.js'; + +test('loads TOML config file', async () => { + const result = await inspectPoku({ + command: '-c=configs/config-file-toml.config.js', + spawnOptions: { cwd: fixtureDir }, + bin: pokuBin, + }); + + assert.strictEqual(result.exitCode, 0); + assert(result.stdout.includes('math.ts')); + assert(result.stdout.includes('%')); +}); diff --git a/test/e2e/coverage-config-file-yaml.test.ts b/test/e2e/coverage-config-file-yaml.test.ts new file mode 100644 index 0000000..3cda7d2 --- /dev/null +++ b/test/e2e/coverage-config-file-yaml.test.ts @@ -0,0 +1,17 @@ +import { assert, test } from 'poku'; +import { inspectPoku } from 'poku/plugins'; + +const fixtureDir = 'test/__fixtures__/e2e'; +const pokuBin = 'node_modules/poku/lib/bin/index.js'; + +test('loads YAML config file', async () => { + const result = await inspectPoku({ + command: '-c=configs/config-file-yaml.config.js', + spawnOptions: { cwd: fixtureDir }, + bin: pokuBin, + }); + + assert.strictEqual(result.exitCode, 0); + assert(result.stdout.includes('math.ts')); + assert(result.stdout.includes('%')); +}); From 92629441fb3a3d25bf7af48d350542e42c9eb24b Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Wed, 8 Apr 2026 09:00:16 -0300 Subject: [PATCH 5/5] run tests sequentially --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4d28372..4a73552 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ }, "scripts": { "pretest": "npm run build", - "test": "poku test/e2e", + "test": "poku --sequential test/e2e", "prebuild": "rm -rf lib", "build": "tsc", "lint": "prettier --check .",