/
stat.test.ts
42 lines (37 loc) · 1.9 KB
/
stat.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { getStat, getStatSync } from './stat';
import { join } from 'path';
const oc = expect.objectContaining;
const sc = expect.stringContaining;
describe('stat', () => {
test.each`
url | expected
${'https://raw.githubusercontent.com/streetsidesoftware/cspell/main/tsconfig.json'} | ${oc({ eTag: sc('W/') })}
${__filename} | ${oc({ mtimeMs: expect.any(Number) })}
`('getStat $url', async ({ url, expected }) => {
const r = await getStat(url);
expect(r).toEqual(expected);
});
test.each`
url | expected
${'https://raw.gitubusrcotent.com/streetsidesoftware/cspell/main/tsconfig.json'} | ${oc({ code: 'ENOTFOUND' })}
${join(__dirname, 'not-found.nf')} | ${oc({ code: 'ENOENT' })}
`('getStat with error $url', async ({ url, expected }) => {
const r = await getStat(url);
expect(r).toEqual(expected);
});
test.each`
url | expected
${__filename} | ${oc({ mtimeMs: expect.any(Number) })}
`('getStatSync $url', ({ url, expected }) => {
const r = getStatSync(url);
expect(r).toEqual(expected);
});
test.each`
url | expected
${'https://raw.githubusercontent.com/streetsidesoftware/cspell/main/tsconfig.json'} | ${oc({ code: 'ENOENT' })}
${join(__dirname, 'not-found.nf')} | ${oc({ code: 'ENOENT' })}
`('getStatSync with error $url', async ({ url, expected }) => {
const r = await getStatSync(url);
expect(r).toEqual(expected);
});
});