Files
vercel/packages/go/test/index.test.ts
Chris Barber 6784e77516 [go] Update to esbuild script (#10468)
Co-authored-by: Nathan Rajlich <n@n8.io>
2023-09-08 17:00:40 -05:00

93 lines
2.8 KiB
TypeScript
Vendored

import { getNewHandlerFunctionName } from '../src/index';
describe('getNewHandlerFunctionName', function () {
it('does nothing with empty original function name', async () => {
let error: Error | undefined;
try {
getNewHandlerFunctionName('', 'some/kind-of-file.js');
} catch (err: unknown) {
error = err as Error;
}
expect(error).toBeDefined();
expect(error?.message).toEqual(
'Handler function renaming failed because original function name was empty.'
);
});
it('does nothing with empty original function name', async () => {
let error: Error | undefined;
try {
getNewHandlerFunctionName('Handler', '');
} catch (err: unknown) {
error = err as Error;
}
expect(error).toBeDefined();
expect(error?.message).toEqual(
'Handler function renaming failed because entrypoint was empty.'
);
});
it('generates slug with back slashes in file path', async () => {
const newFunctionName = getNewHandlerFunctionName(
'Handler',
'some\\file.js'
);
expect(newFunctionName).toEqual('Handler_some_file_js');
});
it('generates slug with forward slashes in file path', async () => {
const newFunctionName = getNewHandlerFunctionName(
'Handler',
'some/file.js'
);
expect(newFunctionName).toEqual('Handler_some_file_js');
});
it('generates slug with dashes in file path', async () => {
const newFunctionName = getNewHandlerFunctionName(
'Handler',
'kind-of-file.js'
);
expect(newFunctionName).toEqual('Handler_kind_of_file_js');
});
it('generates slug with dashes in file path', async () => {
const newFunctionName = getNewHandlerFunctionName(
'Handler',
'kind-of-file.js'
);
expect(newFunctionName).toEqual('Handler_kind_of_file_js');
});
it('generates slug with brackets in file path', async () => {
const newFunctionName = getNewHandlerFunctionName(
'Handler',
'[segment].js'
);
// this expects two underscores on each side intentionally
// left (1): there's an added separator between original function name and slug;
// left (2): the opening bracket is replaced
// right (1): the closing bracket is replaced
// right (2): the period is replaced
expect(newFunctionName).toEqual('Handler__segment__js');
});
it('generates slug with space in file path', async () => {
const newFunctionName = getNewHandlerFunctionName(
'Handler',
'kind of file.js'
);
expect(newFunctionName).toEqual('Handler_kind_of_file_js');
});
it('generates slug with periods in file path', async () => {
const newFunctionName = getNewHandlerFunctionName(
'Handler',
'kind.of.file.js'
);
expect(newFunctionName).toEqual('Handler_kind_of_file_js');
});
});