-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathstat.test.ts
60 lines (52 loc) · 2 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { join } from 'node:path';
import { describe, expect, test } from 'vitest';
import { getStat, getStatSync } from './stat.js';
const oc = <T>(obj: T) => expect.objectContaining(obj);
const sc = (m: string) => expect.stringContaining(m);
const timeout = 20_000;
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);
},
timeout,
);
test.each`
url | expected
${'https://www.google.com/404'} | ${oc({ message: 'URL not found.', code: 'ENOENT' })}
${'https://httpbingo.org/status/503'} | ${oc({ message: 'Fatal Error' })}
${join(__dirname, 'not-found.nf')} | ${oc({ code: 'ENOENT' })}
`(
'getStat with error $url',
async ({ url, expected }) => {
const r = await getStat(url);
expect(r).toEqual(expected);
},
timeout,
);
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://www.google.com/404'} | ${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);
},
timeout,
);
});