Skip to content

Commit d2321f3

Browse files
committed
test(runtime-handler): add assets redirect integration test
1 parent 0d5aab9 commit d2321f3

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

packages/runtime-handler/__tests__/dev-runtime/__snapshots__/integration.test.ts.snap

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@ Object {
3838
}
3939
`;
4040

41+
exports[`with an express app with inline function handling Assets integration tests index.html should match snapshot 1`] = `
42+
Object {
43+
"body": Object {},
44+
"headers": Object {
45+
"accept-ranges": "bytes",
46+
"cache-control": "no-store, no-cache, must-revalidate, proxy-revalidate",
47+
"connection": "close",
48+
"content-type": "text/html; charset=UTF-8",
49+
"expires": "0",
50+
"pragma": "no-cache",
51+
"surrogate-control": "no-store",
52+
"x-powered-by": "Express",
53+
},
54+
"statusCode": 200,
55+
"text": "<html><body>Hi there!</body></html>",
56+
"type": "text/html",
57+
}
58+
`;
59+
4160
exports[`with an express app with inline function handling Function integration tests basic-twiml.js should match snapshot 1`] = `
4261
Object {
4362
"body": Object {},

packages/runtime-handler/__tests__/dev-runtime/integration.test.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,69 @@ describe('with an express app', () => {
161161
});
162162
});
163163

164+
describe('asset fallback', () => {
165+
test('serves /assets/index.html if no root exists', async () => {
166+
const app = new LocalDevelopmentServer(9000, {
167+
...BASE_CONFIG,
168+
routes: {
169+
assets: [
170+
{
171+
name: '/assets/index.html',
172+
path: '/assets/index.html',
173+
filePath: resolve(TEST_ASSETS_DIR, 'index.html'),
174+
content: '',
175+
access: 'public',
176+
},
177+
],
178+
functions: [],
179+
},
180+
forkProcess: false,
181+
} as ServerConfig).getApp();
182+
183+
const response = await request(app).get('/');
184+
expect(response.statusCode).toEqual(200);
185+
expect(response.text).toEqual('<html><body>Hi there!</body></html>');
186+
});
187+
188+
test('returns 404 if no /assets/index.html & no root exists', async () => {
189+
const app = new LocalDevelopmentServer(9000, {
190+
...BASE_CONFIG,
191+
routes: {
192+
assets: [],
193+
functions: [],
194+
},
195+
forkProcess: false,
196+
} as ServerConfig).getApp();
197+
198+
const response = await request(app).get('/');
199+
expect(response.statusCode).toEqual(404);
200+
expect(response.text).toEqual('Could not find requested resource');
201+
});
202+
203+
test('returns root if it exists', async () => {
204+
const app = new LocalDevelopmentServer(9000, {
205+
...BASE_CONFIG,
206+
routes: {
207+
assets: [
208+
{
209+
name: '/',
210+
path: '/',
211+
filePath: resolve(TEST_ASSETS_DIR, 'index.html'),
212+
content: '',
213+
access: 'public',
214+
},
215+
],
216+
functions: [],
217+
},
218+
forkProcess: false,
219+
} as ServerConfig).getApp();
220+
221+
const response = await request(app).get('/');
222+
expect(response.statusCode).toEqual(200);
223+
expect(response.text).toEqual('<html><body>Hi there!</body></html>');
224+
});
225+
});
226+
164227
describe('with forked process function handling', () => {
165228
beforeAll(async () => {
166229
app = new LocalDevelopmentServer(9000, {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<html><body>Hi there!</body></html>

0 commit comments

Comments
 (0)