Socket
Socket
Sign inDemoInstall

lcov-result-merger

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lcov-result-merger - npm Package Compare versions

Comparing version 5.0.1 to 6.0.0-rc.0

32

bin/lcov-result-merger.js
#!/usr/bin/env node
const fastGlob = require('fast-glob');
const { copyFile, readFile } = require('node:fs/promises');
const { writeFile } = require('node:fs/promises');
const { mergeCoverageReportFiles } = require('../index');

@@ -40,10 +40,2 @@ const yargs = require('yargs/yargs');

},
'legacy-temp-file': {
type: 'boolean',
default: false,
description:
'Prior to version 5, a lcov.info file containing the merged output was created in the ' +
"current working directory. The operating system's temporary directory is now used by default, " +
'but if you relied on prior behavior then this flag will recreate it.',
},
ignore: {

@@ -54,2 +46,9 @@ type: 'array',

},
log: {
type: 'boolean',
default: false,
description:
'Show some additional information to the console about what the process is getting up' +
'to (fed to stderr).',
},
});

@@ -60,2 +59,8 @@ }

(async function () {
if (args.log) {
args.logger = function logger(...messages) {
process.stdout.write(`[lcov-result-merger] ${messages.join('\n')}\n`);
};
}
const files = await fastGlob(args.pattern, {

@@ -66,9 +71,12 @@ absolute: true,

const tempFilePath = await mergeCoverageReportFiles(files, args);
args.logger?.('Matched Files', JSON.stringify(files, null, 2));
const mergeResults = await mergeCoverageReportFiles(files, args);
if (args.outFile) {
await copyFile(tempFilePath, args.outFile);
await writeFile(args.outFile, mergeResults, 'utf-8');
args.logger?.(`Results written to "${args.outFile}"`);
} else {
process.stdout.write(await readFile(tempFilePath, 'utf-8'));
process.stdout.write(mergeResults + '\n');
}
})();

@@ -8,3 +8,2 @@ import { Transform } from 'node:stream'

prependPathFix?: string
legacyTempFile?: boolean
ignore?: string[]

@@ -11,0 +10,0 @@ }

@@ -5,7 +5,7 @@ /**

* @author Michael Weibel <michael.weibel@gmail.com>
* @copyright 2013-2023 Michael Weibel
* @copyright 2013-2024 Michael Weibel
* @license MIT
*/
const { readFile, writeFile } = require('node:fs/promises');
const { readFile } = require('node:fs/promises');
const path = require('node:path');

@@ -31,2 +31,3 @@ const { Transform } = require('node:stream');

const lines = data.toString('utf-8').split(/\r?\n/);
config.logger?.(`Read ${lines.length} lines of content`);

@@ -58,3 +59,11 @@ for (let i = 0; i < lines.length; i += 1) {

config.logger?.(
`Re-writing source file path, Before: "${sourceFilePath}"`
);
sourceFilePath = './' + rootRelPathName;
config.logger?.(
`Re-writing source file path, After: "${sourceFilePath}"`
);
}

@@ -75,3 +84,6 @@

default:
// do nothing with not implemented prefixes
// do nothing with not implemented prefixes
config.logger?.(
`Ignoring unrecognized/unsupported entry (line #${i}): "${prefix}:${suffix}"`
);
}

@@ -84,4 +96,4 @@ }

/**
* Merge together the LCOV contents of the provided files.
*
*
* @param {string[]} filePaths

@@ -98,17 +110,11 @@ * @param {import("./lib/configuration").ConfigurationPojo} options

const fileContent = await readFile(filePath, 'utf-8');
config.logger?.(`Processing "${filePath}"`);
processFile(path.dirname(filePath), fileContent, report, config);
}
const tmpFile = await config.getTempFilePath();
await writeFile(tmpFile, Buffer.from(report.toString()), {
encoding: 'utf-8',
flag: 'w+',
});
return tmpFile;
return report.toString().trim();
}
/**
*
* A Stream wrapper for the merge utility.
*/

@@ -137,3 +143,3 @@ class WrappingTransform extends Transform {

mergeCoverageReportFiles(this.filePaths, this.mergeOptions).then(
(tempFile) => callback(null, tempFile),
(fullReport) => callback(null, fullReport.toString().trim()),
(error) => callback(error)

@@ -145,2 +151,5 @@ );

/**
* A variation of the `mergeCoverageReportFiles()` utility that will return a
* stream instead of a promise.
*
* @param {string[] | import("./lib/configuration").ConfigurationPojo} [filePathsOrOptions]

@@ -147,0 +156,0 @@ * @param {import("./lib/configuration").ConfigurationPojo} [options]

@@ -1,8 +0,1 @@

const { join } = require('node:path');
const { tmpdir } = require('node:os');
const { mkdtemp } = require('node:fs');
const { promisify } = require('node:util');
const mkdtempAsync = promisify(mkdtemp);
/**

@@ -17,5 +10,6 @@ * @typedef {Object} ConfigurationPojo

* @property {string} [prepend-path-fix]
* @property {boolean} [legacyTempFile=false]
* @property {boolean} [legacy-temp-file=false]
* @property {string[]} [ignore]
* @property {boolean} [log]
*
* @property {(...msg: string[]) => void} [logger]
*/

@@ -30,2 +24,3 @@

* A glob pattern matching one or more lcov files to be merged.
*
* @type {string}

@@ -37,2 +32,3 @@ */

* A file to write the merged lcov to.
*
* @type {string|undefined}

@@ -44,2 +40,3 @@ */

* File path globs that will be ignored.
*
* @type {string[]}

@@ -50,2 +47,9 @@ */

/**
* An optional logger function.
*
* @type {((...msg: string[]) => void) | undefined}
*/
this.logger = partial.logger;
/**
* Modify source file paths to be relative to the working directory that

@@ -75,33 +79,3 @@ * the merge operation was run in.

: '..';
/**
* Prior to version 5, a lcov.info file containing the merged output was created in the
* current working directory. The operating system's temporary directory is now used by default,
* but if you relied on prior behavior then this flag will recreate it.
*
* @type {boolean}
*/
this.legacyTempFile =
typeof partial.legacyTempFile === 'boolean'
? partial.legacyTempFile
: typeof partial['legacy-temp-file'] === 'boolean'
? partial['legacy-temp-file']
: false;
}
/**
* @param {string} [fileName="lcov.info"]
* @param {string} [prefix="lcov-result-merger"]
* @return {Promise<string>}
*/
async getTempFilePath(
fileName = 'lcov.info',
prefix = 'lcov-result-merger-'
) {
const tmpPath = this.legacyTempFile
? ''
: await mkdtempAsync(join(tmpdir(), prefix));
return join(tmpPath, fileName);
}
};

@@ -70,3 +70,3 @@ {

},
"version": "5.0.1",
"version": "6.0.0-rc.0",
"volta": {

@@ -73,0 +73,0 @@ "node": "14.17.3",

# LCOV Result Merger
[![npm version](https://badge.fury.io/js/lcov-result-merger.svg)](https://badge.fury.io/js/lcov-result-merger)
[![Build Status](https://travis-ci.org/mweibel/lcov-result-merger.png)](https://travis-ci.org/mweibel/lcov-result-merger)
![CI](https://github.com/mweibel/lcov-result-merger/actions/workflows/ci.yml/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/mweibel/lcov-result-merger/badge.svg?branch=master)](https://coveralls.io/github/mweibel/lcov-result-merger?branch=master)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-release--it-444444.svg)](https://github.com/release-it/release-it)
When you have multiple test suites for the same application you still want to
have the code coverage across all testsuites.
have the code coverage across all test suites.
This tool will handle this for you.
> See the [Migration Notes](#migrating-notes) below if you are looking to upgrade between major versions.
# Usage

@@ -48,1 +50,14 @@

```
## Migrating Notes
Additional information about breaking changes.
### Version 6
- The `--legacy-temp-file` flag has been removed. This means that if your project is expecting an
errant `lcov.info` file to be created in the PWD, then it will need to be updated to instead use
the output file specified when running the command.
- The internal usage of temp files has also been eliminated. This only effects project that are
directly importing the `mergeCoverageReportFiles` or `mergeCoverageReportFilesStream` functions
into their own code. Both of these methods now return the merged LCOV content directly, in the
form of a string, instead of a path to the temporary file where that content could be read.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc