Detect and parse CI artifact types for test frameworks and linters
npm install artifact-detective



š View Full Documentation | Detect and parse CI artifact types for test frameworks and linters.
artifact-detective is a library for identifying and parsing CI artifacts from various test frameworks, linters, and type checkers. It reads HTML, JSON, XML, and text outputs, detects the tool that generated them, and extracts structured data for analysis.
- Type validation by content inspection
- Automatic type detection by content inspection
- Many-to-JSON conversion many artifact types can be converted to JSON for programmatic access
- Linter output extraction from CI logs
- TypeScript with full type definitions
- Fixture Generation Framework we generate extensive test cases from real projects using various tooling in various languages
``bash`
npm install artifact-detective
`typescript
import { detectArtifactType } from 'artifact-detective';
const result = detectArtifactType('./test-results/report.html');
console.log(result);
// {
// detectedType: 'pytest-html',
// originalFormat: 'html',
// isBinary: false
// }
`
`typescript
import { validate } from 'artifact-detective';
const content = readFileSync('./report.json', 'utf-8');
const result = validate('pytest-json', content);
if (result.valid) {
console.log('Valid pytest JSON report');
console.log(result.description); // Includes parsing guide
}
`
`typescript
import { extract } from 'artifact-detective';
const logContent = readFileSync('./ci-log.txt', 'utf-8');
// Extract linter output from logs
const result = extract('eslint-txt', logContent);
if (result) {
console.log('Extracted content:', result.content);
console.log('Artifact type:', result.artifact.artifactType);
console.log('Format info:', {
isJSON: result.artifact.isJSON,
toolUrl: result.artifact.toolUrl,
parsingGuide: result.artifact.parsingGuide
});
}
`
#### Custom Extraction Markers
For custom CI environments, you can provide markers to control extraction:
`typescript
import { extract, type ExtractorConfig } from 'artifact-detective';
const logContent = readFileSync('./ci-log.txt', 'utf-8');
// Custom extraction with start/end markers
const config: ExtractorConfig = {
startMarker: /^Running ESLint/,
endMarker: /^\d+ problems?/,
includeEndMarker: true, // Include end marker line in output (default: true)
};
const result = extract('eslint-txt', logContent, { config });
if (result) {
console.log('Extracted:', result.content);
}
`
Many artifact types can be normalized to JSON for programmatic access. Use the unified extract() function with the normalize option:
`typescript
import { extract } from 'artifact-detective';
const logContent = readFileSync('./ci-log.txt', 'utf-8');
// Extract and normalize to JSON in one step
const result = extract('mypy-txt', logContent, { normalize: true });
if (result) {
const errors = JSON.parse(result.content);
console.log(Extracted ${errors.length} type errors);`
console.log('Normalized type:', result.artifact.artifactType); // 'mypy-json'
console.log('Original type was:', result.artifact.normalizedFrom); // 'mypy-txt'
}
#### File-based Normalization
For file-based normalization (without extraction from logs):
`typescript
import { detectArtifactType, convertToJSON, canConvertToJSON } from 'artifact-detective';
// Detect artifact type
const result = detectArtifactType('./pytest-report.html');
// Check if conversion supported
if (canConvertToJSON(result)) {
const conversion = convertToJSON(result, './pytest-report.html');
if (conversion) {
const data = JSON.parse(conversion.json);
console.log(Found ${data.tests.length} tests);`
console.log('Type:', conversion.artifact.artifactType); // 'pytest-json'
console.log('Guide:', conversion.artifact.parsingGuide);
}
}
artifact-detective provides a command-line interface for quick detection, validation, extraction, and normalization of artifacts.
Install globally or use npm link for development:
`bash`
npm install -g artifact-detective
artifact-detective --help
#### detect
Detect artifact type from file:
`bashDetect type and show summary
artifact-detective detect ./report.html
#### validate
Validate artifact against expected type:
`bash
Validate type
artifact-detective validate eslint-json ./eslint-results.jsonInclude parsing documentation
artifact-detective validate --show-description eslint-json ./eslint-results.jsonOutput as JSON
artifact-detective validate --json pytest-json ./pytest-results.jsonVia stdin
cat results.json | artifact-detective validate eslint-json -
`Exit code: 0 for valid, 2 for invalid
#### extract
Extract artifact from CI logs with optional custom markers:
`bash
Extract eslint output from log
artifact-detective extract eslint-txt ./ci-log.txtWrite to file
artifact-detective extract eslint-txt ./ci-log.txt --output extracted.txtCustom markers for specific CI format
artifact-detective extract eslint-txt ./ci-log.txt \
--start-marker "^Running ESLint" \
--end-marker "^\d+ problems?"Via stdin
cat ci-log.txt | artifact-detective extract eslint-txt -
`#### normalize
Convert artifact to JSON format:
`bash
Auto-detect type and convert to JSON
artifact-detective normalize ./pytest-report.htmlExplicitly specify type
artifact-detective normalize ./report.html --type pytest-htmlWrite to file
artifact-detective normalize ./report.html --output report.jsonInclude parsing guide
artifact-detective normalize --show-description ./pytest-report.htmlVia stdin (auto-detect from content)
cat report.html | artifact-detective normalize -
`Supported Formats
| Type | Description | Extract | JSON | Example Fixture |
| --------------------- | ------------------------------------------------------------------ | ------- | ----------- | ------------------------------------------------------------- |
| jest-json | Jest JSON reporter: 5 pass, 2 fail, 1 skip | ā | already is |
fixtures/generated/javascript/jest-results.json |
| playwright-json | Playwright JSON: 3 pass, 1 fail | ā | already is | fixtures/generated/javascript/playwright-results.json |
| pytest-json | Pytest JSON: 5 pass, 2 fail, 1 skip | ā | already is | fixtures/generated/python/pytest-results.json |
| mypy-ndjson | Mypy NDJSON: type checking errors in newline-delimited JSON format | ā | can convert | fixtures/generated/python/mypy-results.json |
| eslint-json | ESLint JSON: reports linting violations | ā | already is | fixtures/generated/javascript/eslint-results.json |
| clippy-ndjson | Clippy NDJSON output with 5+ warnings | ā | can convert | fixtures/generated/rust/clippy-output.json |
| go-test-ndjson | Go test NDJSON: 7 pass, 1 skip | ā | can convert | fixtures/generated/go/go-test.json |
| golangci-lint-json | golangci-lint JSON: linting violations | ā | already is | fixtures/generated/go/golangci-lint.json |
| checkstyle-sarif-json | Checkstyle SARIF violations | ā | already is | fixtures/generated/java/checkstyle-result.sarif |
| pytest-html | Pytest HTML report with test details | ā | can convert | fixtures/generated/python/pytest-report.html |
| jest-html | Jest HTML report with test details | ā | can convert | fixtures/generated/javascript/jest-report.html |
| surefire-html | Maven Surefire HTML test report | ā | todo | fixtures/generated/java/surefire-report.html |
| junit-xml | JUnit test results: 6 passed, 1 failed, 1 skipped | ā | todo | fixtures/generated/java/TEST-com.example.CalculatorTest.xml |
| checkstyle-xml | Checkstyle violations | ā | todo | fixtures/generated/java/checkstyle-result.xml |
| spotbugs-xml | SpotBugs analysis | ā | todo | fixtures/generated/java/spotbugsXml.xml |
| eslint-txt | ESLint output with violations | ā | todo | fixtures/generated/javascript/eslint-output.txt |
| tsc-txt | TypeScript compiler errors | ā | todo | fixtures/generated/javascript/tsc-output.txt |
| mypy-txt | Mypy type checker errors | ā | todo | fixtures/generated/python/mypy-output.txt |
| ruff-txt | Ruff linter output with violations | ā | todo | fixtures/generated/python/ruff-output.txt |
| clippy-txt | Clippy text output with warnings | ā | todo | fixtures/generated/rust/clippy-output.txt |
| flake8-txt | flake8 linter output | ā | todo | ā |
| cargo-test-txt | Cargo test text output: 4 pass, 1 panic, 1 ignored | ā | todo | fixtures/generated/rust/cargo-test-output.txt |
| rustfmt-txt | Rustfmt check output | ā | todo | fixtures/generated/rust/rustfmt-output.txt |Development
`bash
Install dependencies
npm installBuild
npm run buildTest
npm testTest with coverage report
npm run test:coverageFormat code
npm run formatType check
npm run lint
``MIT