test: add tests for runner coverage with different stdout column widths

PR-URL: https://github.com/nodejs/node/pull/54494
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
Pietro Marchini 2024-08-24 14:30:27 +02:00 committed by GitHub
parent 22daeba24d
commit bec3425d0c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 728 additions and 0 deletions

View File

@ -0,0 +1,52 @@
'use strict';
// Here we can't import common module as the coverage will be different based on the system
// Empty functions that don't do anything
function doNothing1() {
// Not implemented
}
function doNothing2() {
// No logic here
}
function unusedFunction1() {
// Intentionally left empty
}
function unusedFunction2() {
// Another empty function
}
// Unused variables
const unusedVariable1 = 'This is never used';
const unusedVariable2 = 42;
let unusedVariable3;
// Empty class with no methods
class UnusedClass {
constructor() {
// Constructor does nothing
}
}
// Empty object literal
const emptyObject = {};
// Empty array
const emptyArray = [];
// Function with parameters but no body
function doNothingWithParams(param1, param2) {
// No implementation
}
// Function that returns nothing
function returnsNothing() {
// No return statement
}
// Another unused function
function unusedFunction3() {
// More empty code
}

View File

@ -0,0 +1,11 @@
'use strict';
// Here we can't import common module as the coverage will be different based on the system
// Empty functions that don't do anything
function doNothing1() {
// Not implemented
}
function doNothing2() {
// No logic here
}

View File

@ -0,0 +1,353 @@
'use strict';
// Here we can't import common module as the coverage will be different based on the system
// Empty functions that don't do anything
function doNothing1() {
// Not implemented
}
function doNothing2() {
// No logic here
}
function unusedFunction1() {
// Intentionally left empty
}
function unusedFunction2() {
// Another empty function
}
// Unused variables
const unusedVariable1 = 'This is never used';
const unusedVariable2 = 42;
let unusedVariable3;
// Empty class with no methods
class UnusedClass {
constructor() {
// Constructor does nothing
}
}
// Empty object literal
const emptyObject = {};
// Empty array
const emptyArray = [];
// Function with parameters but no body
function doNothingWithParams(param1, param2) {
// No implementation
}
// Function that returns nothing
function returnsNothing() {
// No return statement
}
// Another unused function
function unusedFunction3() {
// More empty code
}
// Empty functions with different signatures
function doNothing4() {
// No logic here
}
function doNothing5() {
// Another placeholder
}
function doNothingWithRestParams(...args) {
// Function with rest parameters but no logic
}
function doNothingWithCallback(callback) {
// Callback not called
}
// Unused variables of different types
const unusedVariable7 = null;
const unusedVariable8 = undefined;
const unusedVariable9 = Symbol('unused');
let unusedVariable10;
// Another empty class
class YetAnotherUnusedClass {
// No properties or methods
}
// Unused object with nested array
const unusedObjectWithArray = {
innerArray: [],
};
// Another empty array
const anotherEmptyArray = [];
// Function with default and rest parameters
function anotherComplexFunction(param1 = 10, ...rest) {
// No implementation
}
// More unused functions
function unusedFunction5() {
// Placeholder
}
function unusedFunction6() {
// Empty again
}
function unusedFunction7() {
// Still nothing here
}
// Empty static method in class
class UnusedClassWithStaticMethod {
static unusedStaticMethod() {
// No logic inside static method
}
}
// Empty getter and setter in a class
class ClassWithGetterSetter {
get unusedGetter() {
// Empty getter
}
set unusedSetter(value) {
// Empty setter
}
}
// Unused function returning undefined
function returnsUndefined() {
return undefined;
}
// Empty promise-returning function
function emptyPromiseFunction() {
return new Promise((resolve, reject) => {
// No promise logic
});
}
// Empty immediately-invoked function expression (IIFE)
(function emptyIIFE() {
// No implementation
})();
// Unused generator function with parameters
function* unusedGeneratorFunctionWithParams(param1, param2) {
// No yielding of values
}
// Unused async arrow function
const unusedAsyncArrowFunction = async () => {
// No async logic here
};
// Unused map function with no logic
const unusedMapFunction = new Map();
// Unused set function with no logic
const unusedSetFunction = new Set();
// Empty for loop
for (let i = 0; i < 10; i++) {
// Loop does nothing
}
// Empty while loop
while (false) {
// Never executes
}
// Empty try-catch-finally block
try {
// Nothing to try
} catch (error) {
// No error handling
} finally {
// Nothing to finalize
}
// Empty if-else block
if (false) {
// No logic here
} else {
// Nothing here either
}
// Empty switch statement
switch (false) {
case true:
// No case logic
break;
default:
// Default does nothing
break;
}
// Empty nested function
function outerFunction() {
function innerFunction() {
// Empty inner function
}
}
// More unused arrow functions
const unusedArrowFunction1 = () => {};
const unusedArrowFunction2 = (param) => {};
// Empty function with a try-catch block
function emptyTryCatchFunction() {
try {
// Nothing to try
} catch (error) {
// No error handling
}
}
// Unused async generator function
async function* unusedAsyncGenerator() {
// No async yielding
}
// Unused function returning an empty array
function returnsEmptyArray() {
return [];
}
// Unused function returning an empty object
function returnsEmptyObject() {
return {};
}
// Empty arrow function with destructuring
const unusedArrowFunctionWithDestructuring = ({ key1, key2 }) => {
// No logic here
};
// Unused function with default parameters
function unusedFunctionWithDefaults(param1 = 'default', param2 = 100) {
// No implementation
}
// Unused function returning an empty Map
function returnsEmptyMap() {
return new Map();
}
// Unused function returning an empty Set
function returnsEmptySet() {
return new Set();
}
// Unused async function with try-catch
async function unusedAsyncFunctionWithTryCatch() {
try {
// Nothing to try
} catch (error) {
// No error handling
}
}
// Function with spread operator but no logic
function unusedFunctionWithSpread(...args) {
// No implementation
}
// Function with object spread but no logic
function unusedFunctionWithObjectSpread(obj) {
const newObj = { ...obj };
// No logic here
}
// Empty function that takes an array and does nothing
function unusedFunctionWithArrayParam(arr) {
// No logic here
}
// Empty function that returns a function
function unusedFunctionReturningFunction() {
return function() {
// Empty function returned
};
}
// Empty function with destructuring and rest parameters
function unusedFunctionWithDestructuringAndRest({ a, b, ...rest }) {
// No logic here
}
// Unused async function that returns a promise
async function unusedAsyncFunctionReturningPromise() {
return Promise.resolve();
}
// Empty recursive function
function unusedRecursiveFunction() {
// No recursive logic
}
// Empty function using template literals
function unusedFunctionWithTemplateLiterals(param) {
const message = `Message: ${param}`;
// No further logic
}
// Function with complex destructuring and no logic
function unusedComplexDestructuringFunction({ a: { b, c }, d }) {
// No logic here
}
// Empty function that uses bitwise operations
function unusedFunctionWithBitwiseOperations(num) {
const result = num & 0xff;
// No further logic
}
// Unused function with optional chaining
function unusedFunctionWithOptionalChaining(obj) {
const value = obj?.property?.nestedProperty;
// No further logic
}
// Unused function with nullish coalescing operator
function unusedFunctionWithNullishCoalescing(param) {
const value = param ?? 'default';
// No further logic
}
// Unused generator function returning nothing
function* unusedGeneratorFunction() {
// No yielding
}
// Function using try-catch with finally, but no logic
function unusedFunctionWithTryCatchFinally() {
try {
// Nothing to try
} catch (e) {
// No error handling
} finally {
// Nothing in finally
}
}
// Function with chaining but no logic
function unusedFunctionWithChaining() {
const obj = {
method1: () => ({ method2: () => {} }),
};
obj.method1().method2();
}
// Empty function returning a new Date object
function unusedFunctionReturningDate() {
return new Date();
}

View File

@ -0,0 +1,12 @@
// Flags: --experimental-test-coverage
// here we can't import common module as the coverage will be different based on the system
// Unused imports are here in order to populate the coverage report
import * as a from '../coverage-snap/b.js';
import * as b from '../coverage-snap/a.js';
import * as c from '../coverage-snap/many-uncovered-lines.js';
import { test } from 'node:test';
process.stdout.columns = 100;
test(`Coverage Print Fixed Width ${process.stdout.columns}`);

View File

@ -0,0 +1,27 @@
TAP version 13
# Subtest: Coverage Print Fixed Width 100
ok 1 - Coverage Print Fixed Width 100
---
duration_ms: *
...
1..1
# tests 1
# suites 0
# pass 1
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms *
# start of coverage report
# --------------------------------------------------------------------------------------------------
# file | line % | branch % | funcs % | uncovered lines
# --------------------------------------------------------------------------------------------------
# …ap/a.js | 55.77 | 100.00 | 0.00 | 5-7 9-11 13-15 17-19 29-30 40-42 45-47 50-52
# …ap/b.js | 45.45 | 100.00 | 0.00 | 5-7 9-11
# …ines.js | 50.99 | 42.86 | 1.92 | 5-7 9-11 13-15 17-19 29-30 40-42 45-47 50-52 55-57 59-6…
# …nes.mjs | 100.00 | 100.00 | 100.00 |
# --------------------------------------------------------------------------------------------------
# all fil… | 52.80 | 60.00 | 1.61 |
# --------------------------------------------------------------------------------------------------
# end of coverage report

View File

@ -0,0 +1,11 @@
// Flags: --experimental-test-coverage
// here we can't import common module as the coverage will be different based on the system
// Unused imports are here in order to populate the coverage report
import * as a from '../coverage-snap/b.js';
import * as b from '../coverage-snap/a.js';
import { test } from 'node:test';
process.stdout.columns = 100;
test(`Coverage Print Fixed Width ${process.stdout.columns}`);

View File

@ -0,0 +1,26 @@
TAP version 13
# Subtest: Coverage Print Fixed Width 100
ok 1 - Coverage Print Fixed Width 100
---
duration_ms: *
...
1..1
# tests 1
# suites 0
# pass 1
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms *
# start of coverage report
# --------------------------------------------------------------------------------------------------
# file | line % | branch % | funcs % | uncovered lines
# --------------------------------------------------------------------------------------------------
# test/fixtures/test-runner/coverage-snap/a.js | 55.77 | 100.00 | 0.00 | 5-7 9-11 13-15 …
# test/fixtures/test-runner/coverage-snap/b.js | 45.45 | 100.00 | 0.00 | 5-7 9-11
# …tures/test-runner/output/coverage-width-100.mjs | 100.00 | 100.00 | 100.00 |
# --------------------------------------------------------------------------------------------------
# all files | 60.81 | 100.00 | 0.00 |
# --------------------------------------------------------------------------------------------------
# end of coverage report

View File

@ -0,0 +1,12 @@
// Flags: --experimental-test-coverage
// here we can't import common module as the coverage will be different based on the system
// Unused imports are here in order to populate the coverage report
import * as a from '../coverage-snap/b.js';
import * as b from '../coverage-snap/a.js';
import * as c from '../coverage-snap/many-uncovered-lines.js';
import { test } from 'node:test';
process.stdout.columns = 150;
test(`Coverage Print Fixed Width ${process.stdout.columns}`);

View File

@ -0,0 +1,27 @@
TAP version 13
# Subtest: Coverage Print Fixed Width 150
ok 1 - Coverage Print Fixed Width 150
---
duration_ms: *
...
1..1
# tests 1
# suites 0
# pass 1
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms *
# start of coverage report
# ----------------------------------------------------------------------------------------------------------------------------------------------------
# file | line % | branch % | funcs % | uncovered lines
# ----------------------------------------------------------------------------------------------------------------------------------------------------
# …ap/a.js | 55.77 | 100.00 | 0.00 | 5-7 9-11 13-15 17-19 29-30 40-42 45-47 50-52
# …ap/b.js | 45.45 | 100.00 | 0.00 | 5-7 9-11
# …ines.js | 50.99 | 42.86 | 1.92 | 5-7 9-11 13-15 17-19 29-30 40-42 45-47 50-52 55-57 59-61 63-65 67-69 91-93 96-98 100-102 104-106 111-112 …
# …nes.mjs | 100.00 | 100.00 | 100.00 |
# ----------------------------------------------------------------------------------------------------------------------------------------------------
# all fil… | 52.80 | 60.00 | 1.61 |
# ----------------------------------------------------------------------------------------------------------------------------------------------------
# end of coverage report

View File

@ -0,0 +1,11 @@
// Flags: --experimental-test-coverage
// here we can't import common module as the coverage will be different based on the system
// Unused imports are here in order to populate the coverage report
import * as a from '../coverage-snap/b.js';
import * as b from '../coverage-snap/a.js';
import { test } from 'node:test';
process.stdout.columns = 150;
test(`Coverage Print Fixed Width ${process.stdout.columns}`);

View File

@ -0,0 +1,26 @@
TAP version 13
# Subtest: Coverage Print Fixed Width 150
ok 1 - Coverage Print Fixed Width 150
---
duration_ms: *
...
1..1
# tests 1
# suites 0
# pass 1
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms *
# start of coverage report
# -------------------------------------------------------------------------------------------------------------------------------------
# file | line % | branch % | funcs % | uncovered lines
# -------------------------------------------------------------------------------------------------------------------------------------
# test/fixtures/test-runner/coverage-snap/a.js | 55.77 | 100.00 | 0.00 | 5-7 9-11 13-15 17-19 29-30 40-42 45-47 50-52
# test/fixtures/test-runner/coverage-snap/b.js | 45.45 | 100.00 | 0.00 | 5-7 9-11
# test/fixtures/test-runner/output/coverage-width-150.mjs | 100.00 | 100.00 | 100.00 |
# -------------------------------------------------------------------------------------------------------------------------------------
# all files | 60.81 | 100.00 | 0.00 |
# -------------------------------------------------------------------------------------------------------------------------------------
# end of coverage report

View File

@ -0,0 +1,12 @@
// Flags: --experimental-test-coverage
// here we can't import common module as the coverage will be different based on the system
// Unused imports are here in order to populate the coverage report
import * as a from '../coverage-snap/b.js';
import * as b from '../coverage-snap/a.js';
import * as c from '../coverage-snap/many-uncovered-lines.js';
import { test } from 'node:test';
process.stdout.columns = 100;
test(`Coverage Print Fixed Width ${process.stdout.columns}`);

View File

@ -0,0 +1,27 @@
TAP version 13
# Subtest: Coverage Print Fixed Width 100
ok 1 - Coverage Print Fixed Width 100
---
duration_ms: *
...
1..1
# tests 1
# suites 0
# pass 1
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms *
# start of coverage report
# --------------------------------------------------------------------------------------------------
# file | line % | branch % | funcs % | uncovered lines
# --------------------------------------------------------------------------------------------------
# …ap/a.js | 55.77 | 100.00 | 0.00 | 5-7 9-11 13-15 17-19 29-30 40-42 45-47 50-52
# …ap/b.js | 45.45 | 100.00 | 0.00 | 5-7 9-11
# …ines.js | 50.99 | 42.86 | 1.92 | 5-7 9-11 13-15 17-19 29-30 40-42 45-47 50-52 55-57 59-6…
# …nes.mjs | 100.00 | 100.00 | 100.00 |
# --------------------------------------------------------------------------------------------------
# all fil… | 52.80 | 60.00 | 1.61 |
# --------------------------------------------------------------------------------------------------
# end of coverage report

View File

@ -0,0 +1,11 @@
// Flags: --experimental-test-coverage
// here we can't import common module as the coverage will be different based on the system
// Unused imports are here in order to populate the coverage report
import * as a from '../coverage-snap/b.js';
import * as b from '../coverage-snap/a.js';
import { test } from 'node:test';
process.stdout.columns = 80;
test(`Coverage Print Fixed Width ${process.stdout.columns}`);

View File

@ -0,0 +1,26 @@
TAP version 13
# Subtest: Coverage Print Fixed Width 80
ok 1 - Coverage Print Fixed Width 80
---
duration_ms: *
...
1..1
# tests 1
# suites 0
# pass 1
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms *
# start of coverage report
# ------------------------------------------------------------------------------
# file | line % | branch % | funcs % | …
# ------------------------------------------------------------------------------
# test/fixtures/test-runner/coverage-snap/a.js | 55.77 | 100.00 | 0.00 | …
# test/fixtures/test-runner/coverage-snap/b.js | 45.45 | 100.00 | 0.00 | …
# …es/test-runner/output/coverage-width-80.mjs | 100.00 | 100.00 | 100.00 |
# ------------------------------------------------------------------------------
# all files | 60.81 | 100.00 | 0.00 |
# ------------------------------------------------------------------------------
# end of coverage report

View File

@ -0,0 +1,12 @@
// Flags: --experimental-test-coverage
// here we can't import common module as the coverage will be different based on the system
// Unused imports are here in order to populate the coverage report
import * as a from '../coverage-snap/b.js';
import * as b from '../coverage-snap/a.js';
import * as c from '../coverage-snap/many-uncovered-lines.js';
import { test } from 'node:test';
process.stdout.columns = Infinity;
test(`Coverage Print Fixed Width ${process.stdout.columns}`);

View File

@ -0,0 +1,27 @@
TAP version 13
# Subtest: Coverage Print Fixed Width Infinity
ok 1 - Coverage Print Fixed Width Infinity
---
duration_ms: *
...
1..1
# tests 1
# suites 0
# pass 1
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms *
# start of coverage report
# ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# file | line % | branch % | funcs % | uncovered lines
# ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# test/fixtures/test-runner/coverage-snap/a.js | 55.77 | 100.00 | 0.00 | 5-7 9-11 13-15 17-19 29-30 40-42 45-47 50-52
# test/fixtures/test-runner/coverage-snap/b.js | 45.45 | 100.00 | 0.00 | 5-7 9-11
# test/fixtures/test-runner/coverage-snap/many-uncovered-lines.js | 50.99 | 42.86 | 1.92 | 5-7 9-11 13-15 17-19 29-30 40-42 45-47 50-52 55-57 59-61 63-65 67-69 91-93 96-98 100-102 104-106 111-112 118-119 122-123 127-129 132-136 144-146 150 166-167 173 180 188-189 196-200 207-213 216-218 221-223 226-228 232 236-238 241-243 246-248 251-257 260-262 265-268 271-273 276-280 283-285 288-290 293-295 298-301 304-306 309-312 315-318 321-324 327-329 332-340 343-348 351-353
# test/fixtures/test-runner/output/coverage-width-infinity-uncovered-lines.mjs | 100.00 | 100.00 | 100.00 |
# ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# all files | 52.80 | 60.00 | 1.61 |
# ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# end of coverage report

View File

@ -0,0 +1,11 @@
// Flags: --experimental-test-coverage
// here we can't import common module as the coverage will be different based on the system
// Unused imports are here in order to populate the coverage report
import * as a from '../coverage-snap/b.js';
import * as b from '../coverage-snap/a.js';
import { test } from 'node:test';
process.stdout.columns = Infinity;
test(`Coverage Print Fixed Width ${process.stdout.columns}`);

View File

@ -0,0 +1,26 @@
TAP version 13
# Subtest: Coverage Print Fixed Width Infinity
ok 1 - Coverage Print Fixed Width Infinity
---
duration_ms: *
...
1..1
# tests 1
# suites 0
# pass 1
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms *
# start of coverage report
# ------------------------------------------------------------------------------------------------------------------------------------------
# file | line % | branch % | funcs % | uncovered lines
# ------------------------------------------------------------------------------------------------------------------------------------------
# test/fixtures/test-runner/coverage-snap/a.js | 55.77 | 100.00 | 0.00 | 5-7 9-11 13-15 17-19 29-30 40-42 45-47 50-52
# test/fixtures/test-runner/coverage-snap/b.js | 45.45 | 100.00 | 0.00 | 5-7 9-11
# test/fixtures/test-runner/output/coverage-width-infinity.mjs | 100.00 | 100.00 | 100.00 |
# ------------------------------------------------------------------------------------------------------------------------------------------
# all files | 60.81 | 100.00 | 0.00 |
# ------------------------------------------------------------------------------------------------------------------------------------------
# end of coverage report

View File

@ -151,6 +151,14 @@ const tests = [
{ name: 'test-runner/output/test-runner-plan.js' },
process.features.inspector ? { name: 'test-runner/output/coverage_failure.js' } : false,
{ name: 'test-runner/output/test-diagnostic-warning-without-test-only-flag.js' },
process.features.inspector ? { name: 'test-runner/output/coverage-width-80.mjs' } : false,
process.features.inspector ? { name: 'test-runner/output/coverage-width-100.mjs' } : false,
process.features.inspector ? { name: 'test-runner/output/coverage-width-150.mjs' } : false,
process.features.inspector ? { name: 'test-runner/output/coverage-width-infinity.mjs' } : false,
process.features.inspector ? { name: 'test-runner/output/coverage-width-80-uncovered-lines.mjs' } : false,
process.features.inspector ? { name: 'test-runner/output/coverage-width-100-uncovered-lines.mjs' } : false,
process.features.inspector ? { name: 'test-runner/output/coverage-width-150-uncovered-lines.mjs' } : false,
process.features.inspector ? { name: 'test-runner/output/coverage-width-infinity-uncovered-lines.mjs' } : false,
]
.filter(Boolean)
.map(({ name, tty, transform }) => ({