Skip to content

Commit d2e7f48

Browse files
jdaltonclaude
andcommitted
refactor: update test imports to use src instead of dist
Simplifies test setup by importing directly from source files rather than built dist, removing vitest alias configuration for coverage mode. This matches the pattern used in socket-cli and socket-sdk-js. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent e1a73f4 commit d2e7f48

11 files changed

+17
-42
lines changed

.config/vitest.config.mts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
import path from 'node:path'
2-
import { fileURLToPath } from 'node:url'
3-
41
import { defineConfig } from 'vitest/config'
52

6-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
7-
const isCoverage = process.argv.includes('--coverage')
8-
93
export default defineConfig({
104
test: {
115
globals: false,
@@ -57,23 +51,4 @@ export default defineConfig({
5751
include: ['src/**/*.ts'],
5852
},
5953
},
60-
resolve: {
61-
// Map dist imports to src when running coverage, use dist otherwise.
62-
alias: isCoverage
63-
? [
64-
{
65-
// Match: ../dist/some-module.js
66-
find: /^\.\.\/dist\/(.*)\.js$/,
67-
// Replace: src/some-module.ts
68-
replacement: path.resolve(__dirname, '../src/$1.ts'),
69-
},
70-
{
71-
// Match: ./dist/some-module.js
72-
find: /^\.\/dist\/(.*)\.js$/,
73-
// Replace: src/some-module.ts
74-
replacement: path.resolve(__dirname, '../src/$1.ts'),
75-
},
76-
]
77-
: [],
78-
},
7954
})

test/benchmark.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { describe, expect, it } from 'vitest'
66
import { readJson } from '@socketsecurity/registry/lib/fs'
77
import { isObject } from '@socketsecurity/registry/lib/objects'
88

9-
import { PackageURL } from '../dist/package-url.js'
9+
import { PackageURL } from '../src/package-url.js'
1010

1111
describe('PackageURL', () => {
1212
it('Benchmarking the library', async () => {

test/json-export.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ SOFTWARE.
2525
*/
2626
import { describe, expect, it } from 'vitest'
2727

28-
import { PackageURL } from '../dist/package-url.js'
28+
import { PackageURL } from '../src/package-url.js'
2929

3030
describe('PackageURL JSON/dict export', () => {
3131
describe('toObject', () => {

test/package-url-builder.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ SOFTWARE.
2525
*/
2626
import { describe, expect, it } from 'vitest'
2727

28-
import { PackageURL, PackageURLBuilder } from '../dist/package-url.js'
28+
import { PackageURL, PackageURLBuilder } from '../src/package-url.js'
2929

3030
describe('PackageURLBuilder', () => {
3131
describe('basic construction', () => {

test/package-url.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
testValidParam,
2929
testValidStringParam,
3030
} from './utils/param-validation.mjs'
31-
import { PackageURL } from '../dist/package-url.js'
31+
import { PackageURL } from '../src/package-url.js'
3232

3333
describe('PackageURL', () => {
3434
describe('KnownQualifierNames', () => {

test/purl-edge-cases.test.mts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@ SOFTWARE.
2323
import { describe, expect, it } from 'vitest'
2424

2525
import { createTestFunction } from './utils/test-helpers.mjs'
26-
import { LOOP_SENTINEL } from '../dist/constants.js'
27-
import { PurlError, formatPurlErrorMessage } from '../dist/error.js'
28-
import { recursiveFreeze } from '../dist/objects.js'
29-
import { PackageURL } from '../dist/package-url.js'
30-
import { PurlQualifierNames } from '../dist/purl-qualifier-names.js'
31-
import { PurlType } from '../dist/purl-type.js'
26+
import { LOOP_SENTINEL } from '../src/constants.js'
3227
import {
3328
encodeComponent,
3429
encodeNamespace,
@@ -37,6 +32,7 @@ import {
3732
encodeSubpath,
3833
encodeVersion,
3934
} from '../src/encode.js'
35+
import { PurlError, formatPurlErrorMessage } from '../src/error.js'
4036
import {
4137
normalizeName,
4238
normalizeNamespace,
@@ -45,6 +41,8 @@ import {
4541
normalizeType,
4642
normalizeVersion,
4743
} from '../src/normalize.js'
44+
import { recursiveFreeze } from '../src/objects.js'
45+
import { PackageURL } from '../src/package-url.js'
4846
import {
4947
PurlComponent,
5048
PurlComponentEncoder,
@@ -53,6 +51,8 @@ import {
5351
componentComparator,
5452
componentSortOrder,
5553
} from '../src/purl-component.js'
54+
import { PurlQualifierNames } from '../src/purl-qualifier-names.js'
55+
import { PurlType } from '../src/purl-type.js'
5656
import {
5757
validateEmptyByType,
5858
validateName,

test/purl-spec.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
toSortedObjectFromEntries,
3232
} from '@socketsecurity/registry/lib/objects'
3333

34-
import { PackageURL } from '../dist/package-url.js'
34+
import { PackageURL } from '../src/package-url.js'
3535

3636
function toUrlSearchParams(search: string) {
3737
const searchParams = new URLSearchParams()

test/purl-types.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { describe, expect, it } from 'vitest'
2424

2525
import npmBuiltinNames from '../data/npm/builtin-names.json'
2626
import npmLegacyNames from '../data/npm/legacy-names.json'
27-
import { PackageURL } from '../dist/package-url.js'
27+
import { PackageURL } from '../src/package-url.js'
2828

2929
function getNpmId(purl: any) {
3030
const { name, namespace } = purl

test/result.test.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ SOFTWARE.
2525
*/
2626
import { describe, expect, it } from 'vitest'
2727

28-
import { PackageURL } from '../dist/package-url.js'
29-
import { Err, Ok, ResultUtils, err, ok } from '../dist/result.js'
28+
import { PackageURL } from '../src/package-url.js'
29+
import { Err, Ok, ResultUtils, err, ok } from '../src/result.js'
3030

3131
describe('Result types', () => {
3232
describe('Ok', () => {

test/url-converter.test.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ SOFTWARE.
2525
*/
2626
import { describe, expect, it } from 'vitest'
2727

28-
import { PackageURL } from '../dist/package-url.js'
29-
import { UrlConverter } from '../dist/url-converter.js'
28+
import { PackageURL } from '../src/package-url.js'
29+
import { UrlConverter } from '../src/url-converter.js'
3030

3131
describe('UrlConverter', () => {
3232
describe('toRepositoryUrl', () => {

0 commit comments

Comments
 (0)