-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(build-env): add unit tests for parseRegistryData
- Loading branch information
Showing
2 changed files
with
75 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
tooling/build-env/src/internal/verdaccio/verdaccio-registry.unit-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { parseRegistryData } from './verdaccio-registry'; // Adjust import path | ||
|
||
describe('parseRegistryData', () => { | ||
it('should correctly parse protocol host and port from stdout', () => { | ||
const stdout = | ||
'warn --- http address - http://localhost:4873/ - verdaccio/5.31.1'; | ||
const result = parseRegistryData(stdout); | ||
|
||
expect(result).toEqual({ | ||
protocol: 'http', | ||
host: 'localhost', | ||
port: 4873, | ||
url: 'http://localhost:4873', | ||
}); | ||
}); | ||
|
||
it('should correctly parse https protocol', () => { | ||
const stdout = | ||
'warn --- http address - https://localhost:4873/ - verdaccio/5.31.1'; | ||
const result = parseRegistryData(stdout); | ||
|
||
expect(result.protocol).toEqual('https'); | ||
}); | ||
|
||
it('should throw an error if the protocol is invalid', () => { | ||
const stdout = 'ftp://localhost:4873'; // Invalid protocol | ||
expect(() => parseRegistryData(stdout)).toThrowError( | ||
'Could not parse registry data from stdout' | ||
); | ||
}); | ||
|
||
it('should throw an error if the host is missing', () => { | ||
const stdout = 'http://:4873'; // Missing host | ||
expect(() => parseRegistryData(stdout)).toThrowError( | ||
'Could not parse registry data from stdout' | ||
); | ||
}); | ||
|
||
it('should throw an error if the stdout is empty', () => { | ||
const stdout = ''; // Empty output | ||
expect(() => parseRegistryData(stdout)).toThrowError( | ||
'Could not parse registry data from stdout' | ||
); | ||
}); | ||
|
||
it('should throw an error if the port is missing', () => { | ||
const stdout = 'http://localhost:'; // Missing port | ||
expect(() => parseRegistryData(stdout)).toThrowError( | ||
'Could not parse registry data from stdout' | ||
); | ||
}); | ||
}); |