-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wp now: add codespaces support (#41)
Allow running `wp-now` in GitHub codespaces
- Loading branch information
Showing
5 changed files
with
66 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* True if the current environment is a GitHub Codespace | ||
*/ | ||
export const isGitHubCodespace = Boolean( | ||
process.env.CODESPACE_NAME && | ||
process.env.GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN | ||
); | ||
|
||
/* | ||
* Returns the URL in the current GitHub Codespace | ||
* e.g: https://sejas-fluffy-space-eureka-wrj7r95qhvq4x-8881.preview.app.github.dev | ||
*/ | ||
export function getCodeSpaceURL(port: number): string { | ||
return `https://${process.env.CODESPACE_NAME}-${port}.${process.env.GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}`; | ||
} |
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,35 @@ | ||
import getWpNowConfig from '../config'; | ||
import * as codespaces from '../github-codespaces'; | ||
|
||
describe('Test GitHub Codespaces', () => { | ||
let processEnv; | ||
beforeAll(() => { | ||
processEnv = process.env; | ||
process.env = {}; | ||
}); | ||
|
||
afterAll(() => { | ||
process.env = processEnv; | ||
}); | ||
|
||
test('getAbsoluteURL returns the localhost URL', async () => { | ||
vi.spyOn(codespaces, 'isGitHubCodespace', 'get').mockReturnValue(false); | ||
const options = await getWpNowConfig({ port: 7777 }); | ||
|
||
expect(options.absoluteUrl).toBe('http://localhost:7777'); | ||
vi.resetAllMocks(); | ||
}); | ||
|
||
test('getAbsoluteURL returns the codespace URL', async () => { | ||
vi.spyOn(codespaces, 'isGitHubCodespace', 'get').mockReturnValue(true); | ||
process.env.CODESPACE_NAME = 'my-codespace-name'; | ||
process.env.GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN = | ||
'preview.app.github.dev'; | ||
const options = await getWpNowConfig({ port: 7777 }); | ||
|
||
expect(options.absoluteUrl).toBe( | ||
'https://my-codespace-name-7777.preview.app.github.dev' | ||
); | ||
vi.resetAllMocks(); | ||
}); | ||
}); |