Skip to content

Commit

Permalink
test(up): add positive test for h5
Browse files Browse the repository at this point in the history
  • Loading branch information
trieloff committed Jan 12, 2024
1 parent 77ea3a9 commit f792d83
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions test/up-cmd.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,69 @@ describe('Integration test for up command with helix pages', function suite() {
assert.strictEqual(opened, `http://localhost:${port}/`);
});

it('up command opens browser and delivers correct response on helix 5.', async () => {
let opened;
const MockedCommand = await esmock('../src/up.cmd.js', {
'../src/abstract-server.cmd.js': await esmock('../src/abstract-server.cmd.js', {
open: (url) => {
opened = url;
},
}),
});
initGit(testDir, 'https://github.com/adobe/dummy-foo.git');
const cmd = new MockedCommand()
.withLiveReload(false)
.withDirectory(testDir)
.withOpen('/')
.withHttpPort(0);

nock('https://master--dummy-foo--adobe.aem.page')
.get('/fstab.yaml')
.reply(200, 'dummy')
.get('/index.html')
.reply(200, '## Welcome')
.get('/not-found.txt')
.reply(404);

nock('https://admin.hlx.page:443')
.get('/sidekick/dummy-foo/adobe/master/config.json')
.reply(200, {
host: 'example.com',
liveHost: 'master--dummy-foo--adobe.aem.live',
previewHost: 'master--dummy-foo--adobe..aem.page',
project: 'Example Project on Helix 5',
testProperty: 'header',
});

let port;
await new Promise((resolve, reject) => {
let error = null;
cmd
.on('started', async () => {
try {
port = cmd.project.server.port;
let ret = await assertHttp(`http://127.0.0.1:${port}/index.html`, 200);
assert.strictEqual(ret.trim(), '## Welcome');
ret = await assertHttp(`http://127.0.0.1:${port}/local.txt`, 200);
assert.strictEqual(ret.trim(), 'Hello, world.');
await assertHttp(`http://127.0.0.1:${port}/not-found.txt`, 404);
} catch (e) {
error = e;
}
await cmd.stop();
})
.on('stopped', () => {
if (error) {
reject(error);
}
resolve();
})
.run()
.catch(reject);
});
assert.strictEqual(opened, `http://localhost:${port}/`);
});

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 f792d83

Please sign in to comment.