|
1 | 1 | import * as child_process from 'child_process';
|
2 | 2 | import * as fs from 'fs';
|
3 | 3 | import * as path from 'path';
|
4 |
| -import { callsites, exec, extractDependencies, findUp } from '../lib/util'; |
| 4 | +import { callsites, exec, extractDependencies, findUp, findUpMultiple } from '../lib/util'; |
5 | 5 |
|
6 | 6 | beforeEach(() => {
|
7 | 7 | jest.clearAllMocks();
|
@@ -33,6 +33,49 @@ describe('findUp', () => {
|
33 | 33 | });
|
34 | 34 | });
|
35 | 35 |
|
| 36 | +describe('findUpMultiple', () => { |
| 37 | + test('Starting at process.cwd()', () => { |
| 38 | + const files = findUpMultiple(['README.md', 'package.json']); |
| 39 | + expect(files).toHaveLength(2); |
| 40 | + expect(files[0]).toMatch(/aws-lambda-nodejs\/README\.md$/); |
| 41 | + expect(files[1]).toMatch(/aws-lambda-nodejs\/package\.json$/); |
| 42 | + }); |
| 43 | + |
| 44 | + test('Non existing files', () => { |
| 45 | + expect(findUpMultiple(['non-existing-file.unknown', 'non-existing-file.unknown2'])).toEqual([]); |
| 46 | + }); |
| 47 | + |
| 48 | + test('Existing and non existing files', () => { |
| 49 | + const files = findUpMultiple(['non-existing-file.unknown', 'README.md']); |
| 50 | + expect(files).toHaveLength(1); |
| 51 | + expect(files[0]).toMatch(/aws-lambda-nodejs\/README\.md$/); |
| 52 | + }); |
| 53 | + |
| 54 | + test('Starting at a specific path', () => { |
| 55 | + const files = findUpMultiple(['util.test.ts', 'function.test.ts'], path.join(__dirname, 'integ-handlers')); |
| 56 | + expect(files).toHaveLength(2); |
| 57 | + expect(files[0]).toMatch(/aws-lambda-nodejs\/test\/util\.test\.ts$/); |
| 58 | + expect(files[1]).toMatch(/aws-lambda-nodejs\/test\/function\.test\.ts$/); |
| 59 | + }); |
| 60 | + |
| 61 | + test('Non existing files starting at a non existing relative path', () => { |
| 62 | + expect(findUpMultiple(['not-to-be-found.txt', 'not-to-be-found2.txt'], 'non-existing/relative/path')).toEqual([]); |
| 63 | + }); |
| 64 | + |
| 65 | + test('Starting at a relative path', () => { |
| 66 | + const files = findUpMultiple(['util.test.ts', 'function.test.ts'], 'test/integ-handlers'); |
| 67 | + expect(files).toHaveLength(2); |
| 68 | + expect(files[0]).toMatch(/aws-lambda-nodejs\/test\/util\.test\.ts$/); |
| 69 | + expect(files[1]).toMatch(/aws-lambda-nodejs\/test\/function\.test\.ts$/); |
| 70 | + }); |
| 71 | + |
| 72 | + test('Files on multiple levels', () => { |
| 73 | + const files = findUpMultiple(['README.md', 'util.test.ts'], path.join(__dirname, 'integ-handlers')); |
| 74 | + expect(files).toHaveLength(1); |
| 75 | + expect(files[0]).toMatch(/aws-lambda-nodejs\/test\/util\.test\.ts$/); |
| 76 | + }); |
| 77 | +}); |
| 78 | + |
36 | 79 | describe('exec', () => {
|
37 | 80 | test('normal execution', () => {
|
38 | 81 | const spawnSyncMock = jest.spyOn(child_process, 'spawnSync').mockReturnValue({
|
|
0 commit comments