Skip to content

Commit

Permalink
feat(up): support urls with variables
Browse files Browse the repository at this point in the history
  • Loading branch information
rofe committed Sep 2, 2024
1 parent 14eea47 commit 3eaf846
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/up.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ export default class UpCommand extends AbstractServerCommand {
}
if (!this._url) {
await this.verifyUrl(this._gitUrl, ref);
} else if (/\{\{(owner|repo)+\}\}/.test(this._url)) {
const { owner, repo } = await GitUtils.getOriginURL(this.directory);
this._url = this._url
.replace(/\{\{owner\}\}/, owner)
.replace(/\{\{repo\}\}/, repo);
}
this._project.withProxyUrl(this._url);
await this.initServerOptions();
Expand Down
43 changes: 43 additions & 0 deletions test/up-cmd.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,49 @@ describe('Integration test for up command with helix pages', function suite() {
assert.strictEqual(opened, `http://localhost:${port}/`);
});

it('up command correctly replaces variables in url', async () => {
const MockedCommand = await esmock('../src/up.cmd.js', {
'../src/abstract-server.cmd.js': await esmock('../src/abstract-server.cmd.js'),
});
initGit(testDir, 'https://github.com/adobe/dummy-foo.git', 'test');
const cmd = new MockedCommand()
.withLiveReload(false)
.withDirectory(testDir)
.withOpen(false)
.withHttpPort(0)
.withUrl('https://main--{{repo}}--{{owner}}.hlx.page');

nock('https://main--dummy-foo--adobe.hlx.page')
.get('/index.html')
.reply(200, '## Welcome');

let port;
await new Promise((resolve, reject) => {
let error = null;
cmd
.on('started', async () => {
try {
// eslint-disable-next-line no-underscore-dangle
assert.equal(cmd._url, 'https://main--dummy-foo--adobe.hlx.page');
port = cmd.project.server.port;
const ret = await assertHttp(`http://127.0.0.1:${port}/index.html`, 200);
assert.strictEqual(ret.trim(), '## Welcome');
} catch (e) {
error = e;
}
await cmd.stop();
})
.on('stopped', () => {
if (error) {
reject(error);
}
resolve();
})
.run()
.catch(reject);
});
});

it('up command delivers correct response (branch with slash).', (done) => {
initGit(testDir, 'https://github.com/adobe/dummy-foo.git', 'tripod/test');
let error = null;
Expand Down

0 comments on commit 3eaf846

Please sign in to comment.