|
1 | 1 | import * as fs from './fs-impl' |
2 | | -import { Loader } from './loader' |
| 2 | +import { resolve } from 'path' |
| 3 | +import { Loader, LookupType } from './loader' |
| 4 | +import { toValueSync } from '../util/async' |
3 | 5 |
|
4 | 6 | describe('fs/loader', function () { |
5 | 7 | describe('.candidates()', function () { |
6 | | - it('should resolve relatively', async function () { |
| 8 | + it('should resolve relatively', function () { |
7 | 9 | const loader = new Loader({ relativeReference: true, fs, extname: '' } as any) |
8 | | - const candidates = [...loader.candidates('./foo/bar', ['/root', '/root/foo'], '/root/current', true)] |
9 | | - expect(candidates).toContain('/root/foo/bar') |
| 10 | + const candidates = [...loader.candidates('./foo/bar', ['/root', '/root/foo'], '/root/current')] |
| 11 | + expect(candidates).toContain(resolve('/root/foo/bar')) |
10 | 12 | }) |
11 | | - it('should not include out of root candidates', async function () { |
12 | | - const loader = new Loader({ relativeReference: true, fs, extname: '' } as any) |
13 | | - const candidates = [...loader.candidates('../foo/bar', ['/root'], '/root/current', true)] |
14 | | - expect(candidates).toHaveLength(0) |
| 13 | + }) |
| 14 | + describe('.lookup()', function () { |
| 15 | + it('should not include out of root candidates', function () { |
| 16 | + const mockFs = { ...fs, existsSync: () => true, exists: async () => true } |
| 17 | + const loader = new Loader({ relativeReference: true, fs: mockFs, extname: '', partials: ['/root'] } as any) |
| 18 | + expect(() => toValueSync(loader.lookup('../foo/bar', LookupType.Partials, true, '/root/current'))) |
| 19 | + .toThrow(/ENOENT/) |
15 | 20 | }) |
16 | | - it('should treat root as a terminated path', async function () { |
17 | | - const loader = new Loader({ relativeReference: true, fs, extname: '' } as any) |
18 | | - const candidates = [...loader.candidates('../root-dir/bar', ['/root'], '/root/current', true)] |
19 | | - expect(candidates).toHaveLength(0) |
| 21 | + it('should treat root as a terminated path', function () { |
| 22 | + const mockFs = { ...fs, existsSync: () => true, exists: async () => true } |
| 23 | + const loader = new Loader({ relativeReference: true, fs: mockFs, extname: '', partials: ['/root'] } as any) |
| 24 | + expect(() => toValueSync(loader.lookup('../root-dir/bar', LookupType.Partials, true, '/root/current'))) |
| 25 | + .toThrow(/ENOENT/) |
20 | 26 | }) |
21 | | - it('should default `.contains()` to () => true', async function () { |
22 | | - const customFs = { |
23 | | - ...fs, |
24 | | - contains: undefined |
25 | | - } |
26 | | - const loader = new Loader({ relativeReference: true, fs: customFs, extname: '' } as any) |
27 | | - const candidates = [...loader.candidates('../foo/bar', ['/root'], '/root/current', true)] |
28 | | - expect(candidates).toContain('/foo/bar') |
| 27 | + it('should use permissive contains when fs.contains is omitted', function () { |
| 28 | + const mockFs = { ...fs, existsSync: () => true, exists: async () => true, contains: undefined, containsSync: undefined } |
| 29 | + const loader = new Loader({ relativeReference: true, fs: mockFs, extname: '', partials: ['/root'] } as any) |
| 30 | + const result = toValueSync(loader.lookup('./foo/bar', LookupType.Partials, true, '/root/current')) |
| 31 | + expect(result).toBe(resolve('/root/foo/bar')) |
29 | 32 | }) |
30 | 33 | }) |
31 | 34 | }) |
0 commit comments