1import { vol } from 'memfs'; 2 3import { findUpProjectRootOrAssert } from '../findUp'; 4 5describe(findUpProjectRootOrAssert, () => { 6 beforeEach(() => { 7 vol.reset(); 8 }); 9 it('gets project root', () => { 10 vol.fromJSON( 11 { 12 '/foo/bar/package.json': '{}', 13 '/foo/bar/another/index': '', 14 }, 15 '.' 16 ); 17 expect(findUpProjectRootOrAssert('/foo/bar/another/index')).toBe('/foo/bar'); 18 }); 19 20 it('throws if project root not found', () => { 21 vol.fromJSON( 22 { 23 '/foo/bar/another/index': '', 24 }, 25 '.' 26 ); 27 expect(() => 28 findUpProjectRootOrAssert('/foo/bar/another/index') 29 ).toThrowErrorMatchingInlineSnapshot( 30 `"Project root directory not found (working directory: /foo/bar/another/index)"` 31 ); 32 }); 33}); 34