-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add http-server tests and clean up some deep source issues (#1201)
* Refactor common to esm module
- Loading branch information
1 parent
954656f
commit 0c5b486
Showing
6 changed files
with
99 additions
and
53 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
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
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,29 @@ | ||
import { vi, } from 'vitest'; | ||
import { Server as HTTPServer } from 'http'; | ||
import { ERROR_STRING_ADDRESS, ERROR_NO_ADDRESS, getServerPort } from "./HttpServer.js"; | ||
|
||
describe('getServerPort', () => { | ||
it('throws if no address is returned', () => { | ||
const address = vi.fn().mockImplementation(() => undefined); | ||
expect(() => getServerPort({ | ||
address, | ||
} as unknown as HTTPServer)).toThrowError(ERROR_NO_ADDRESS); | ||
}); | ||
|
||
it('throws if string address is returned', () => { | ||
const address = vi.fn().mockImplementation(() => 'foo'); | ||
expect(() => getServerPort({ | ||
address, | ||
} as unknown as HTTPServer)).toThrowError(ERROR_STRING_ADDRESS); | ||
}); | ||
|
||
it('returns valid port', () => { | ||
const port = 123; | ||
const address = vi.fn().mockImplementation(() => ({ | ||
port, | ||
})); | ||
expect(getServerPort({ | ||
address, | ||
} as unknown as HTTPServer)).toEqual(port); | ||
}); | ||
}); |
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
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,19 @@ | ||
export const serverHeaders = [ | ||
{ | ||
"source": "**/*", | ||
"headers": [ | ||
{ | ||
"key": "Bypass-Tunnel-Reminder", | ||
"value": "true", | ||
}, | ||
{ | ||
"key": "Access-Control-Allow-Origin", | ||
"value": "*", | ||
}, | ||
{ | ||
"key": "Access-Control-Allow-Headers", | ||
"value": "Origin, X-Requested-With, Content-Type, Accept, Range", | ||
} | ||
] | ||
} | ||
]; |
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