Skip to content

Commit 06e2b71

Browse files
authored
fix: update code for new version of severless-api (#46)
* fix: update code for new version of severless-api re twilio-labs/serverless-api#8 * chore(npm): upgrade @twilio-labs/serverless-api * fix(tests): fix integration tests Remove the reliance on stacktraces in the error integration tests
1 parent 4e0455d commit 06e2b71

File tree

11 files changed

+807
-1473
lines changed

11 files changed

+807
-1473
lines changed

__tests__/runtime/__snapshots__/integration.test.ts.snap

-417
Large diffs are not rendered by default.

__tests__/runtime/integration.test.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
jest.unmock('twilio');
22

3-
import request from 'supertest';
4-
import { createServer } from '../../src/runtime/server';
5-
import { resolve, basename } from 'path';
6-
import cheerio from 'cheerio';
3+
import { Express } from 'express';
74
import { readdirSync } from 'fs';
8-
import { Response as ExpressResponse, Express } from 'express';
5+
import { basename, resolve } from 'path';
6+
import request from 'supertest';
97
import { StartCliConfig } from '../../src/runtime/cli/config';
8+
import { createServer } from '../../src/runtime/server';
109

1110
const TEST_DIR = resolve(__dirname, '../../fixtures');
1211

@@ -36,9 +35,9 @@ function responseToSnapshotJson(response: InternalResponse) {
3635
// stack traces are different in every environment
3736
// let's not snapshot values that rely on it
3837
text = `${text.split('\n')[0]} ...`;
39-
delete headers['content-length'];
40-
delete headers['etag'];
4138
}
39+
delete headers['content-length'];
40+
delete headers['etag'];
4241

4342
return {
4443
statusCode,
@@ -63,8 +62,12 @@ describe('Function integration tests', () => {
6362
for (const testFnCode of availableFunctions) {
6463
test(`${testFnCode.name} should match snapshot`, async () => {
6564
const response = await request(app).get(testFnCode.url);
66-
const result = responseToSnapshotJson(response as InternalResponse);
67-
expect(result).toMatchSnapshot();
65+
if (response.status === 500) {
66+
expect(response.text).toMatch(/Error/);
67+
} else {
68+
const result = responseToSnapshotJson(response as InternalResponse);
69+
expect(result).toMatchSnapshot();
70+
}
6871
});
6972
}
7073
});

__tests__/runtime/internal/runtime-paths.test.ts

+40-18
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,30 @@ jest.doMock('@twilio-labs/serverless-api', () => {
66
return Promise.resolve({
77
assets: [
88
{
9-
name: 'example.html',
10-
path: '/var/task/handlers/example.html',
9+
name: '/example.html',
10+
path: '/example.html',
11+
access: 'public',
12+
content: '',
1113
},
1214
{
13-
name: 'secret.private.html',
14-
path: '/var/task/handlers/secret.private.html',
15+
name: '/secret.html',
16+
path: '/secret.html',
17+
access: 'private',
18+
content: '',
1519
},
1620
],
1721
functions: [
1822
{
19-
name: 'sms/reply.js',
20-
path: '/var/task/handlers/sms/reply.js',
23+
name: '/sms/reply.js',
24+
path: '/sms/reply.js',
25+
access: 'public',
26+
content: '',
2127
},
2228
{
23-
name: 'token.protected.js',
24-
path: '/var/task/handlers/token.protected.js',
29+
name: '/token.js',
30+
path: '/token.js',
31+
access: 'protected',
32+
content: '',
2533
},
2634
],
2735
});
@@ -32,30 +40,44 @@ jest.doMock('@twilio-labs/serverless-api', () => {
3240
return mod;
3341
});
3442

35-
import { getFunctionsAndAssets } from '../../../src/runtime/internal/runtime-paths';
36-
3743
import { fsHelpers } from '@twilio-labs/serverless-api';
44+
import { getFunctionsAndAssets } from '../../../src/runtime/internal/runtime-paths';
3845

3946
test('calls the right functions', async () => {
4047
const result = await getFunctionsAndAssets('/var/task/handlers');
4148
expect(fsHelpers.getListOfFunctionsAndAssets).toHaveBeenCalled();
42-
expect(fsHelpers.getPathAndAccessFromFileInfo).toHaveBeenCalled();
4349
});
4450

4551
test('returns the right functions and assets', async () => {
46-
const { functions } = await getFunctionsAndAssets('/var/task/handlers');
52+
const { functions, assets } = await getFunctionsAndAssets(
53+
'/var/task/handlers'
54+
);
4755
expect(functions).toEqual([
4856
{
49-
functionPath: '/sms/reply',
57+
name: '/sms/reply.js',
58+
path: '/sms/reply.js',
5059
access: 'public',
51-
name: 'sms/reply.js',
52-
path: '/var/task/handlers/sms/reply.js',
60+
content: '',
5361
},
5462
{
55-
functionPath: '/token',
63+
name: '/token.js',
64+
path: '/token.js',
5665
access: 'protected',
57-
name: 'token.protected.js',
58-
path: '/var/task/handlers/token.protected.js',
66+
content: '',
67+
},
68+
]);
69+
expect(assets).toEqual([
70+
{
71+
name: '/example.html',
72+
path: '/example.html',
73+
access: 'public',
74+
content: '',
75+
},
76+
{
77+
name: '/secret.html',
78+
path: '/secret.html',
79+
access: 'private',
80+
content: '',
5981
},
6082
]);
6183
});

0 commit comments

Comments
 (0)