Skip to content

Commit 5c7d00f

Browse files
committed
Add initial tests
1 parent dd3984c commit 5c7d00f

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

.github/workflows/test.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: 'Run tests'
2+
3+
on: [push]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: Cache node modules
11+
uses: actions/cache@v2
12+
env:
13+
cache-name: cache-node-modules
14+
with:
15+
path: |
16+
~/.npm
17+
**/node_modules
18+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
19+
restore-keys: |
20+
${{ runner.os }}-build-${{ env.cache-name }}-
21+
${{ runner.os }}-build-
22+
${{ runner.os }}-
23+
- name: Run tests
24+
run: |
25+
npm install --dev
26+
npm run test

src/server.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as server from './server';
2+
3+
import {ExecutionContext} from 'ava';
4+
import test from 'ava';
5+
6+
test('Test parseHostname', (t: ExecutionContext) => {
7+
t.deepEqual(
8+
server.parseHostname('sitename-refname-dot-fileset2-dot-appid.appspot.com'),
9+
{
10+
siteId: 'sitename',
11+
branchOrRef: 'refname',
12+
}
13+
);
14+
});

src/server.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import * as fsPath from 'path';
2+
13
import {Datastore} from '@google-cloud/datastore';
24
import {GoogleAuth} from 'google-auth-library';
3-
import * as fsPath from 'path';
5+
46
import express = require('express');
57
import httpProxy = require('http-proxy');
68

@@ -48,7 +50,7 @@ const getManifest = async (siteId: string, branchOrRef: string) => {
4850
// }
4951
};
5052

51-
const parseHostname = (hostname: string) => {
53+
export function parseHostname(hostname: string) {
5254
// TODO: Make this more robust
5355
if (hostname.includes('-dot-')) {
5456
const prefix = hostname.split('-dot-fileset2-')[0];
@@ -63,7 +65,7 @@ const parseHostname = (hostname: string) => {
6365
branchOrRef: '',
6466
};
6567
}
66-
};
68+
}
6769

6870
export function createApp(siteId: string, branchOrRef: string) {
6971
console.log(`Starting server for site: ${siteId} @ ${branchOrRef}`);
@@ -82,6 +84,7 @@ export function createApp(siteId: string, branchOrRef: string) {
8284

8385
const manifest = await getManifest(requestSiteId, requestBranchOrRef);
8486
if (!manifest || !manifest.paths) {
87+
console.log(`Site: ${requestSiteId}, Ref: ${requestBranchOrRef}`);
8588
res
8689
.status(404)
8790
.sendFile(

0 commit comments

Comments
 (0)