Skip to content

Commit 6630ef8

Browse files
committed
refactor(test): improve test infrastructure and coverage
- Increase coverage thresholds to 98% for lines and statements - Configure type coverage to 100% with strict settings - Optimize npm package test performance - Standardize module identifier to import.meta.url - Use crypto.randomUUID in temp-file-helper - Correct assertions and remove duplicate tests - Add c8 ignore comments with required reasons - Update test runner with better staged file handling
1 parent 0af17f8 commit 6630ef8

20 files changed

+91
-98
lines changed

.config/vitest.config.mts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export default defineConfig({
171171
reportsDirectory: 'coverage',
172172
reporter: ['text', 'json', 'html', 'lcov', 'clover'],
173173
// ONLY include registry/src production code (not types.ts)
174-
include: ['registry/src/index.{ts,mts,cts}'],
174+
include: ['registry/src/**/*.{ts,mts,cts}'],
175175
// Exclude everything else (must include vitest defaults)
176176
exclude: [
177177
// Vitest defaults
@@ -193,16 +193,16 @@ export default defineConfig({
193193
'registry/plugins/**',
194194
'registry/dist/**',
195195
],
196-
// Set to false to ONLY report files in include list that are executed
197-
all: false,
196+
// Set to true to report ALL files in include list, even if not executed
197+
all: true,
198198
clean: true,
199199
skipFull: false,
200200
ignoreClassMethods: ['constructor'],
201201
thresholds: {
202-
lines: 1,
203-
functions: 80,
204-
branches: 80,
205-
statements: 1,
202+
lines: 98,
203+
functions: 100,
204+
branches: 100,
205+
statements: 98,
206206
},
207207
},
208208
},

perf/npm/json-stable-stringify.perf.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import { getDefaultLogger } from '@socketsecurity/lib/logger'
77
import fastJsonStableStringify from 'fast-json-stable-stringify'
88
import { Bench } from 'tinybench'
99

10-
import constants from '../../scripts/constants.mjs'
10+
import { PERF_NPM_FIXTURES_PATH } from '../../scripts/constants/paths.mjs'
1111

1212
const logger = getDefaultLogger()
1313

1414
void (async () => {
1515
const sampleData2MbJson = require(
16-
path.join(constants.perfNpmFixturesPath, 'sample_data_2mb.json'),
16+
path.join(PERF_NPM_FIXTURES_PATH, 'sample_data_2mb.json'),
1717
)
1818
const sampleData6MbJson = {
1919
a: sampleData2MbJson,

test/npm/array-flatten.test.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** @fileoverview Tests for @socketregistry/array-flatten npm package override. */
12
import { describe, expect, it } from 'vitest'
23

34
import { setupNpmPackageTest } from '../utils/npm-package-helper.mts'
@@ -7,7 +8,7 @@ const {
78
module: flattenLegacy,
89
skip,
910
sockRegPkgName,
10-
} = await setupNpmPackageTest(__filename)
11+
} = await setupNpmPackageTest(import.meta.url)
1112
const flatten = flattenLegacy?.flatten
1213

1314
describe(`${eco} > ${sockRegPkgName}`, { skip }, () => {

test/npm/assert.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const {
1414
pkgPath,
1515
skip,
1616
sockRegPkgName,
17-
} = await setupNpmPackageTest(__filename)
17+
} = await setupNpmPackageTest(import.meta.url)
1818

1919
// assert package tests use old util.isError which was deprecated and removed
2020
// in Node.js 20+.

test/npm/date.test.mts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** @fileoverview Tests for @socketregistry/date npm package override. */
12
import { describe, expect, it } from 'vitest'
23

34
const DateImpl = require('../../packages/npm/date/Date')
@@ -92,6 +93,8 @@ describe('date', () => {
9293
})
9394
})
9495

96+
// Date string formatting is platform-dependent and may produce different
97+
// output on Windows due to timezone and locale differences.
9598
describe(
9699
'Date string formatting',
97100
{ skip: process.platform === 'win32' },

test/npm/deep-equal.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const {
1818
pkgPath,
1919
skip,
2020
sockRegPkgName,
21-
} = await setupNpmPackageTest(__filename)
21+
} = await setupNpmPackageTest(import.meta.url)
2222

2323
// deep-equal package tests may have issues with test dependencies.
2424
describe(`${eco} > ${sockRegPkgName}`, { skip }, () => {

test/npm/define-properties.test.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** @fileoverview Tests for @socketregistry/define-properties npm package override. */
12
import { describe, expect, it } from 'vitest'
23

34
const define = require('../../packages/npm/define-properties')

test/npm/es6-object-assign.test.mts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** @fileoverview Tests for @socketregistry/es6-object-assign npm package override. */
12
import path from 'node:path'
23
// eslint-disable-next-line n/no-extraneous-import
34
import { getDefaultLogger } from '@socketsecurity/lib/logger'
@@ -6,8 +7,9 @@ import { setupNpmPackageTest } from '../utils/npm-package-helper.mts'
67

78
const logger = getDefaultLogger()
89

9-
const { eco, pkgPath, skip, sockRegPkgName } =
10-
await setupNpmPackageTest(__filename)
10+
const { eco, pkgPath, skip, sockRegPkgName } = await setupNpmPackageTest(
11+
import.meta.url,
12+
)
1113

1214
// es6-object-assign has no unit tests.
1315
// https://github.com/rubennorte/es6-object-assign/tree/v1.1.0

test/npm/harmony-reflect.test.mts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
/** @fileoverview Tests for @socketregistry/harmony-reflect npm package override. */
12
import path from 'node:path'
23

34
import { describe, expect, it } from 'vitest'
45

56
import { setupNpmPackageTest } from '../utils/npm-package-helper.mts'
67

7-
const { eco, pkgPath, skip, sockRegPkgName } =
8-
await setupNpmPackageTest(__filename)
8+
const { eco, pkgPath, skip, sockRegPkgName } = await setupNpmPackageTest(
9+
import.meta.url,
10+
)
911

1012
// harmony-reflect has known failures in its package and requires running tests in browser.
1113
// https://github.com/tvcutsem/harmony-reflect/tree/v1.6.2/test

test/npm/hasown.test.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** @fileoverview Tests for @socketregistry/hasown npm package override. */
12
import { describe, expect, it } from 'vitest'
23

34
const hasOwn = require('../../packages/npm/hasown')

0 commit comments

Comments
 (0)