1
1
import { execa } from "execa" ;
2
+ import fs from "node:fs" ;
2
3
import { URL , fileURLToPath } from "node:url" ;
3
4
import os from "node:os" ;
4
- import { readFile } from "./helpers.js" ;
5
5
6
6
const root = new URL ( "../" , import . meta. url ) ;
7
7
const cwd = os . platform ( ) === "win32" ? fileURLToPath ( root ) : root ; // execa bug: fileURLToPath required on Windows
@@ -14,58 +14,52 @@ describe("CLI", () => {
14
14
test (
15
15
"GitHub API" ,
16
16
async ( ) => {
17
- const expected = readFile ( new URL ( "./examples/github-api.ts" , root ) ) . trim ( ) ;
18
17
const { stdout } = await execa ( cmd , [ "./examples/github-api.yaml" ] , { cwd } ) ;
19
- expect ( stdout ) . toBe ( expected ) ;
18
+ expect ( stdout ) . toMatchFileSnapshot ( fileURLToPath ( new URL ( "./examples/github-api.ts" , root ) ) ) ;
20
19
} ,
21
20
TIMEOUT ,
22
21
) ;
23
22
test (
24
23
"GitHub API (next)" ,
25
24
async ( ) => {
26
- const expected = readFile ( new URL ( "./examples/github-api-next.ts" , root ) ) . trim ( ) ;
27
25
const { stdout } = await execa ( cmd , [ "./examples/github-api-next.yaml" ] , { cwd } ) ;
28
- expect ( stdout ) . toBe ( expected ) ;
26
+ expect ( stdout ) . toMatchFileSnapshot ( fileURLToPath ( new URL ( "./examples/github-api-next.ts" , root ) ) ) ;
29
27
} ,
30
28
TIMEOUT ,
31
29
) ;
32
30
test (
33
31
"Octokit GHES 3.6 Diff to API" ,
34
32
async ( ) => {
35
- const expected = readFile ( new URL ( "./examples/octokit-ghes-3.6-diff-to-api.ts" , root ) ) . trim ( ) ;
36
33
const { stdout } = await execa ( cmd , [ "./examples/octokit-ghes-3.6-diff-to-api.json" ] , { cwd } ) ;
37
- expect ( stdout ) . toBe ( expected ) ;
34
+ expect ( stdout ) . toMatchFileSnapshot ( fileURLToPath ( new URL ( "./examples/octokit-ghes-3.6-diff-to-api.ts" , root ) ) ) ;
38
35
} ,
39
36
TIMEOUT ,
40
37
) ;
41
38
test (
42
39
"Stripe API" ,
43
40
async ( ) => {
44
- const expected = readFile ( new URL ( "./examples/stripe-api.ts" , root ) ) . trim ( ) ;
45
41
const { stdout } = await execa ( cmd , [ "./examples/stripe-api.yaml" ] , { cwd } ) ;
46
- expect ( stdout ) . toBe ( expected ) ;
42
+ expect ( stdout ) . toMatchFileSnapshot ( fileURLToPath ( new URL ( "./examples/stripe-api.ts" , root ) ) ) ;
47
43
} ,
48
44
TIMEOUT ,
49
45
) ;
50
46
// this test runs too slowly on macos / windows in GitHub Actions (but not natively)
51
47
test . skipIf ( process . env . CI_ENV === "macos" || process . env . CI_ENV === "windows" ) (
52
48
"DigitalOcean API (remote $refs)" ,
53
49
async ( ) => {
54
- const expected = readFile ( new URL ( "./examples/digital-ocean-api.ts" , root ) ) . trim ( ) ;
55
50
const { stdout } = await execa ( cmd , [ "./examples/digital-ocean-api/DigitalOcean-public.v2.yaml" ] , {
56
51
cwd,
57
52
} ) ;
58
- expect ( stdout ) . toBe ( expected ) ;
53
+ expect ( stdout ) . toMatchFileSnapshot ( fileURLToPath ( new URL ( "./examples/digital-ocean-api.ts" , root ) ) ) ;
59
54
} ,
60
55
TIMEOUT ,
61
56
) ;
62
57
test (
63
58
"stdin" ,
64
59
async ( ) => {
65
- const expected = readFile ( new URL ( "./examples/stripe-api.ts" , root ) ) . trim ( ) ;
66
- const input = readFile ( new URL ( "./examples/stripe-api.yaml" , root ) ) ;
60
+ const input = fs . readFileSync ( new URL ( "./examples/stripe-api.yaml" , root ) ) ;
67
61
const { stdout } = await execa ( cmd , { input } ) ;
68
- expect ( stdout ) . toBe ( expected ) ;
62
+ expect ( stdout ) . toMatchFileSnapshot ( fileURLToPath ( new URL ( "./examples/stripe-api.ts" , root ) ) ) ;
69
63
} ,
70
64
TIMEOUT ,
71
65
) ;
0 commit comments