mirror of
https://github.com/actions/configure-pages.git
synced 2026-03-30 18:14:51 +00:00
Add dedicated Actions-outputs module
This commit is contained in:
10
src/output-pages-base-url.js
Normal file
10
src/output-pages-base-url.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
const core = require('@actions/core')
|
||||||
|
|
||||||
|
function outputPagesBaseUrl(siteUrl) {
|
||||||
|
core.setOutput('base_url', siteUrl.href)
|
||||||
|
core.setOutput('origin', siteUrl.origin)
|
||||||
|
core.setOutput('host', siteUrl.host)
|
||||||
|
core.setOutput('base_path', siteUrl.pathname)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = outputPagesBaseUrl
|
||||||
62
src/output-pages-base-url.test.js
Normal file
62
src/output-pages-base-url.test.js
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
const core = require('@actions/core')
|
||||||
|
|
||||||
|
const outputPagesBaseUrl = require('./output-pages-base-url')
|
||||||
|
|
||||||
|
describe('outputPagesBaseUrl', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.restoreAllMocks()
|
||||||
|
|
||||||
|
jest.spyOn(core, 'setOutput').mockImplementation((key, value) => {
|
||||||
|
key, value
|
||||||
|
})
|
||||||
|
jest.spyOn(core, 'setFailed').mockImplementation(param => param)
|
||||||
|
|
||||||
|
// Mock error/warning/info/debug
|
||||||
|
jest.spyOn(core, 'error').mockImplementation(jest.fn())
|
||||||
|
jest.spyOn(core, 'warning').mockImplementation(jest.fn())
|
||||||
|
jest.spyOn(core, 'info').mockImplementation(jest.fn())
|
||||||
|
jest.spyOn(core, 'debug').mockImplementation(jest.fn())
|
||||||
|
})
|
||||||
|
|
||||||
|
it('gets expected outputs for profile site', async () => {
|
||||||
|
const baseUrl = 'https://octocat.github.io/'
|
||||||
|
|
||||||
|
outputPagesBaseUrl(new URL(baseUrl))
|
||||||
|
|
||||||
|
expect(core.setOutput).toHaveBeenCalledWith('base_url', baseUrl)
|
||||||
|
expect(core.setOutput).toHaveBeenCalledWith(
|
||||||
|
'origin',
|
||||||
|
'https://octocat.github.io'
|
||||||
|
)
|
||||||
|
expect(core.setOutput).toHaveBeenCalledWith('host', 'octocat.github.io')
|
||||||
|
expect(core.setOutput).toHaveBeenCalledWith('base_path', '/')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('gets expected outputs for project site', async () => {
|
||||||
|
const baseUrl = 'https://octocat.github.io/my-repo/'
|
||||||
|
|
||||||
|
outputPagesBaseUrl(new URL(baseUrl))
|
||||||
|
|
||||||
|
expect(core.setOutput).toHaveBeenCalledWith('base_url', baseUrl)
|
||||||
|
expect(core.setOutput).toHaveBeenCalledWith(
|
||||||
|
'origin',
|
||||||
|
'https://octocat.github.io'
|
||||||
|
)
|
||||||
|
expect(core.setOutput).toHaveBeenCalledWith('host', 'octocat.github.io')
|
||||||
|
expect(core.setOutput).toHaveBeenCalledWith('base_path', '/my-repo/')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('gets expected outputs for site with custom domain name', async () => {
|
||||||
|
const baseUrl = 'https://www.example.com/'
|
||||||
|
|
||||||
|
outputPagesBaseUrl(new URL(baseUrl))
|
||||||
|
|
||||||
|
expect(core.setOutput).toHaveBeenCalledWith('base_url', baseUrl)
|
||||||
|
expect(core.setOutput).toHaveBeenCalledWith(
|
||||||
|
'origin',
|
||||||
|
'https://www.example.com'
|
||||||
|
)
|
||||||
|
expect(core.setOutput).toHaveBeenCalledWith('host', 'www.example.com')
|
||||||
|
expect(core.setOutput).toHaveBeenCalledWith('base_path', '/')
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user