|
1 | | -import {mkdirSync, mkdtempSync, writeFileSync} from 'node:fs'; |
| 1 | +import {mkdirSync, mkdtempSync, symlinkSync, writeFileSync} from 'node:fs'; |
2 | 2 | import {tmpdir} from 'node:os'; |
3 | 3 | import {join} from 'node:path'; |
4 | 4 | import {imageSize, readImageSizes} from './image-sizes'; |
@@ -42,6 +42,22 @@ describe('imageSize', () => { |
42 | 42 | }); |
43 | 43 |
|
44 | 44 | describe('readImageSizes', () => { |
| 45 | + it('reads a directory whose path has a space', () => { |
| 46 | + const dir = mkdtempSync(join(tmpdir(), 'image sizes ')); |
| 47 | + writeFileSync(join(dir, 'a.png'), png(2, 1)); |
| 48 | + expect(readImageSizes(dir)).toEqual({'/a.png': [2, 1]}); |
| 49 | + }); |
| 50 | + |
| 51 | + it('returns nothing when there is no public directory', () => { |
| 52 | + expect(readImageSizes(join(tmpdir(), 'image-sizes-missing-dir'))).toEqual({}); |
| 53 | + }); |
| 54 | + |
| 55 | + it('fails when an image cannot be read, instead of leaving it out', () => { |
| 56 | + const dir = mkdtempSync(join(tmpdir(), 'image-sizes-')); |
| 57 | + symlinkSync(join(dir, 'gone.png'), join(dir, 'broken.png')); |
| 58 | + expect(() => readImageSizes(dir)).toThrow(/ENOENT/); |
| 59 | + }); |
| 60 | + |
45 | 61 | it('keys the sizes by URL path', () => { |
46 | 62 | const dir = mkdtempSync(join(tmpdir(), 'image-sizes-')); |
47 | 63 | mkdirSync(join(dir, 'images/panel'), {recursive: true}); |
|
0 commit comments