|
| 1 | +import { join } from 'path'; |
| 2 | + |
| 3 | +import funpack from '../index'; |
| 4 | + |
| 5 | +process.env.GIT_REPO_URL = 'https://example.com/test/repo.git'; |
| 6 | + |
| 7 | +// TODO: Change to using full examples instead of mocking like that |
| 8 | +jest.mock('../utils/getPackageJsonObject', () => |
| 9 | + jest.fn().mockReturnValue({ |
| 10 | + name: 'my-lambdas', |
| 11 | + version: '0.0.0-dev', |
| 12 | + type: 'module', |
| 13 | + funpack: { |
| 14 | + settings: { |
| 15 | + outputDir: 'example/dist-splitting', |
| 16 | + packageFieldsToCopy: ['version', 'type'], |
| 17 | + cleanupOutputDir: true, |
| 18 | + zip: true, |
| 19 | + esbuildConfigOverride: { |
| 20 | + format: 'esm', |
| 21 | + target: 'node16', |
| 22 | + splitting: true, |
| 23 | + sourcemap: true, |
| 24 | + }, |
| 25 | + }, |
| 26 | + functions: { |
| 27 | + firstSplit: './example/test.ts', |
| 28 | + secondSplit: './example/second.ts', |
| 29 | + }, |
| 30 | + }, |
| 31 | + }) |
| 32 | +); |
| 33 | + |
| 34 | +describe('funpack', () => { |
| 35 | + console.log = jest.fn(); |
| 36 | + it('builds correctly', async () => { |
| 37 | + await funpack(); |
| 38 | + // TODO: Improve test case to check for files? |
| 39 | + expect(console.log).toHaveBeenCalledTimes(2); |
| 40 | + const logMock = console.log as jest.Mock; |
| 41 | + |
| 42 | + expect(logMock.mock.calls[0][0]).toBe( |
| 43 | + join('example', 'dist-splitting', 'secondSplit.zip') |
| 44 | + ); |
| 45 | + expect(logMock.mock.calls[0][2]).toBeCloseTo(67352, -2); |
| 46 | + |
| 47 | + expect(logMock.mock.calls[1][0]).toBe( |
| 48 | + join('example', 'dist-splitting', 'firstSplit.zip') |
| 49 | + ); |
| 50 | + expect(logMock.mock.calls[1][2]).toBeCloseTo(69275, -2); |
| 51 | + }); |
| 52 | +}); |
0 commit comments