11import { describe , test , expect } from 'vitest'
2- import { Config } from '@oclif/core'
32import { runCommand } from '@oclif/test'
43import nock from 'nock'
54
65nock . disableNetConnect ( )
76
87describe ( 'extremes' , async ( ) => {
9- const config = await Config . load ( new URL ( '../..' , import . meta. url ) . pathname )
8+ function run ( args : string [ ] ) {
9+ return runCommand ( [ 'extremes' , ...args ] )
10+ }
11+
12+ test ( '--help' , async ( ) => {
13+ const { stdout } = await run ( [ '--help' ] )
14+ expect ( stdout ) . toMatch ( / e x t r e m e s / )
15+ expect ( stdout ) . toMatch ( / - - s t a t i o n / )
16+ expect ( stdout ) . toMatch ( / - - s t a r t / )
17+ expect ( stdout ) . toMatch ( / - - e n d / )
18+ expect ( stdout ) . toMatch ( / - - f o r m a t / )
19+ } )
1020
1121 test ( '--station <id>' , async ( ) => {
12- const { stdout } = await runCommand (
13- [ 'extremes' , '--station' , '9414290' , '--start' , '2026-01-01' ] ,
14- config
15- )
22+ const { stdout } = await run ( [
23+ '--station' ,
24+ '9414290' ,
25+ '--start' ,
26+ '2026-01-01'
27+ ] )
1628 expect ( stdout ) . toMatch ( / S A N F R A N C I S C O / )
1729 } )
1830
1931 test ( '--near 22.24,-75.75' , async ( ) => {
20- const { stdout } = await runCommand (
21- [ 'extremes' , '--near' , '22.24,-75.75' ] ,
22- config
23- )
32+ const { stdout } = await run ( [ '--near' , '22.24,-75.75' ] )
2433 expect ( stdout ) . toMatch ( / N u r s e C h a n n e l / )
2534 } )
2635
@@ -30,7 +39,7 @@ describe('extremes', async () => {
3039 longitude : - 77.3524
3140 } )
3241
33- const { stdout, error } = await runCommand ( [ 'extremes' , ' --ip'] , config )
42+ const { stdout, error } = await run ( [ '--ip' ] )
3443 expect ( error ) . toBeUndefined ( )
3544 expect ( stdout ) . toMatch ( / N a s s a u , N e w P r o v i d e n c e I s l a n d / )
3645 } )
@@ -39,62 +48,73 @@ describe('extremes', async () => {
3948 test ( 'defaults to today' , async ( ) => {
4049 const today = new Date ( ) . toISOString ( ) . split ( 'T' ) [ 0 ]
4150
42- const { stdout } = await runCommand (
43- [ 'extremes' , '--station' , '9414290' ] ,
44- config
45- )
51+ const { stdout } = await run ( [ '--station' , '9414290' ] )
4652 expect ( stdout ) . toMatch ( new RegExp ( today ) )
4753 } )
4854
4955 test ( 'accepts partial date' , async ( ) => {
50- const { stdout } = await runCommand (
51- [ 'extremes' , '--station' , '9414290' , '--start' , '2025-12-25' ] ,
52- config
53- )
56+ const { stdout } = await run ( [
57+ '--station' ,
58+ '9414290' ,
59+ '--start' ,
60+ '2025-12-25'
61+ ] )
5462 expect ( stdout ) . toMatch ( / 2 0 2 5 - 1 2 - 2 5 / )
5563 } )
5664
5765 test ( 'accepts full date' , async ( ) => {
58- const { stdout } = await runCommand (
59- [ 'extremes' , '--station' , '9414290' , '--start' , '2025-12-25T00:00:00Z' ] ,
60- config
61- )
66+ const { stdout } = await run ( [
67+ '--station' ,
68+ '9414290' ,
69+ '--start' ,
70+ '2025-12-25T00:00:00Z'
71+ ] )
6272 expect ( stdout ) . toMatch ( / 2 0 2 5 - 1 2 - 2 5 / )
6373 } )
6474
6575 test ( 'with invalid input' , async ( ) => {
66- const { error } = await runCommand (
67- [ 'extremes' , '--station' , '9414290' , '--start' , 'invalid-date' ] ,
68- config
69- )
76+ const { error } = await run ( [
77+ '--station' ,
78+ '9414290' ,
79+ '--start' ,
80+ 'invalid-date'
81+ ] )
7082 expect ( error ?. message ) . toMatch ( / I n v a l i d t i m e v a l u e / )
7183 } )
7284 } )
7385
7486 describe ( '--end' , ( ) => {
7587 test ( 'defaults to 72 hours from start' , async ( ) => {
76- const { stdout } = await runCommand (
77- [ 'extremes' , '--station' , '9414290' , '--start' , '2025-12-25' ] ,
78- config
79- )
88+ const { stdout } = await run ( [
89+ '--station' ,
90+ '9414290' ,
91+ '--start' ,
92+ '2025-12-25'
93+ ] )
8094 expect ( stdout ) . toMatch ( / 2 0 2 5 - 1 2 - 2 7 / )
8195 } )
8296
8397 test ( 'accepts partial date' , async ( ) => {
84- const { stdout } = await runCommand (
85- [
86- 'extremes' ,
87- '--station' ,
88- '9414290' ,
89- '--start' ,
90- '2025-12-25' ,
91- '--end' ,
92- '2025-12-26'
93- ] ,
94- config
95- )
98+ const { stdout } = await run ( [
99+ '--station' ,
100+ '9414290' ,
101+ '--start' ,
102+ '2025-12-25' ,
103+ '--end' ,
104+ '2025-12-26'
105+ ] )
96106 expect ( stdout ) . toMatch ( / 2 0 2 5 - 1 2 - 2 5 / )
97107 expect ( stdout ) . not . toMatch ( / 2 0 2 5 - 1 2 - 2 6 / )
98108 } )
99109 } )
110+
111+ describe ( '--format' , ( ) => {
112+ test ( 'json' , async ( ) => {
113+ const { stdout } = await run ( [ '--station' , '9414290' , '--format' , 'json' ] )
114+ const result = JSON . parse ( stdout )
115+ expect ( result . station . name ) . toMatch ( / S A N F R A N C I S C O / i)
116+ expect ( result . datum ) . toEqual ( 'MLLW' )
117+ expect ( result . extremes . length ) . toBeGreaterThan ( 0 )
118+ } )
119+ } )
100120} )
0 commit comments