Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
417 changes: 0 additions & 417 deletions __tests__/runtime/__snapshots__/integration.test.ts.snap

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions __tests__/runtime/integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
jest.unmock('twilio');

import request from 'supertest';
import { createServer } from '../../src/runtime/server';
import { resolve, basename } from 'path';
import cheerio from 'cheerio';
import { Express } from 'express';
import { readdirSync } from 'fs';
import { Response as ExpressResponse, Express } from 'express';
import { basename, resolve } from 'path';
import request from 'supertest';
import { StartCliConfig } from '../../src/runtime/cli/config';
import { createServer } from '../../src/runtime/server';

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

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

return {
statusCode,
Expand All @@ -63,8 +62,12 @@ describe('Function integration tests', () => {
for (const testFnCode of availableFunctions) {
test(`${testFnCode.name} should match snapshot`, async () => {
const response = await request(app).get(testFnCode.url);
const result = responseToSnapshotJson(response as InternalResponse);
expect(result).toMatchSnapshot();
if (response.status === 500) {
expect(response.text).toMatch(/Error/);
} else {
const result = responseToSnapshotJson(response as InternalResponse);
expect(result).toMatchSnapshot();
}
});
}
});
58 changes: 40 additions & 18 deletions __tests__/runtime/internal/runtime-paths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,30 @@ jest.doMock('@twilio-labs/serverless-api', () => {
return Promise.resolve({
assets: [
{
name: 'example.html',
path: '/var/task/handlers/example.html',
name: '/example.html',
path: '/example.html',
access: 'public',
content: '',
},
{
name: 'secret.private.html',
path: '/var/task/handlers/secret.private.html',
name: '/secret.html',
path: '/secret.html',
access: 'private',
content: '',
},
],
functions: [
{
name: 'sms/reply.js',
path: '/var/task/handlers/sms/reply.js',
name: '/sms/reply.js',
path: '/sms/reply.js',
access: 'public',
content: '',
},
{
name: 'token.protected.js',
path: '/var/task/handlers/token.protected.js',
name: '/token.js',
path: '/token.js',
access: 'protected',
content: '',
},
],
});
Expand All @@ -32,30 +40,44 @@ jest.doMock('@twilio-labs/serverless-api', () => {
return mod;
});

import { getFunctionsAndAssets } from '../../../src/runtime/internal/runtime-paths';

import { fsHelpers } from '@twilio-labs/serverless-api';
import { getFunctionsAndAssets } from '../../../src/runtime/internal/runtime-paths';

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

test('returns the right functions and assets', async () => {
const { functions } = await getFunctionsAndAssets('/var/task/handlers');
const { functions, assets } = await getFunctionsAndAssets(
'/var/task/handlers'
);
expect(functions).toEqual([
{
functionPath: '/sms/reply',
name: '/sms/reply.js',
path: '/sms/reply.js',
access: 'public',
name: 'sms/reply.js',
path: '/var/task/handlers/sms/reply.js',
content: '',
},
{
functionPath: '/token',
name: '/token.js',
path: '/token.js',
access: 'protected',
name: 'token.protected.js',
path: '/var/task/handlers/token.protected.js',
content: '',
},
]);
expect(assets).toEqual([
{
name: '/example.html',
path: '/example.html',
access: 'public',
content: '',
},
{
name: '/secret.html',
path: '/secret.html',
access: 'private',
content: '',
},
]);
});
Loading