Skip to content

Commit

Permalink
feat(native fetch): create --experimental-fetch as toggle feature (#1240
Browse files Browse the repository at this point in the history
)

* create --experimental-fetch as toggle feature

* add tests and doc

* add documentation
  • Loading branch information
syamsudotdev authored Feb 27, 2024
1 parent d96b3e1 commit a907167
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docs/src/pages/guides/cli-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ You can also set the maximum of delay by using the `--retryMaxDelayMs` flag. Def
monika --retryMaxDelayMs 30000
```

## Experimental Native Node Fetch

Monika use Axios as HTTP client by default, use `--experimental-fetch` to switch to native fetch provided by Node.js runtime.

```sh
monika --experimental-fetch
```

## Follow Redirects

By default Monika will follow redirects 21 times. You can set the value of `--follow-redirects` flag to tell Monika to follow redirects as many as you want. If you don't want to follow redirects, set the value to zero.
Expand Down
6 changes: 6 additions & 0 deletions src/commands/monika.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ export default class Monika extends Command {
'Create config from HAR (-H), postman (-p), insomnia (-I), sitemap (--sitemap), textfile (--text) export file, or open Monika Configuration Generator using default browser',
}),

'experimental-fetch': Flags.boolean({
default: monikaFlagsDefaultValue['experimental-fetch'],
description:
'Use native fetch Node.js API instead of Axios for HTTP client',
}),

flush: Flags.boolean({
description: 'Flush logs',
}),
Expand Down
36 changes: 36 additions & 0 deletions src/components/logger/startup-message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,5 +426,41 @@ describe('Startup message', () => {
// assert
expect(logMessage).include('config file')
})

// delete test on removing toggle
it('should show experimental fetch toggle', () => {
// act
logStartupMessage({
config: defaultConfig,
flags: {
config: ['./monika.yaml'],
verbose: false,
'experimental-fetch': true,
},
isFirstRun: false,
})

// assert
expect(logMessage).include('Using native Node.js fetch for HTTP client')
})

// delete test on removing toggle
it('should hide experimental fetch toggle', () => {
// act
logStartupMessage({
config: defaultConfig,
flags: {
config: ['./monika.yaml'],
verbose: false,
'experimental-fetch': false,
},
isFirstRun: false,
})

// assert
expect(logMessage).not.include(
'Using native Node.js fetch for HTTP client'
)
})
})
})
9 changes: 8 additions & 1 deletion src/components/logger/startup-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ import { createProber } from '../probe/prober/factory'

type LogStartupMessage = {
config: Config
flags: Pick<MonikaFlags, 'config' | 'symonKey' | 'symonUrl' | 'verbose'>
flags: Pick<
MonikaFlags,
'config' | 'symonKey' | 'symonUrl' | 'verbose' | 'experimental-fetch'
>
isFirstRun: boolean
}

Expand All @@ -59,6 +62,10 @@ export function logStartupMessage({
}
}

if (flags['experimental-fetch']) {
log.info('Using native Node.js fetch for HTTP client')
}

const startupMessage = generateStartupMessage({
config,
flags,
Expand Down
2 changes: 2 additions & 0 deletions src/flag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type MonikaFlags = {
'config-filename': string
'config-interval': number
'create-config': boolean
'experimental-fetch'?: boolean
flush: boolean
'follow-redirects': number
force: boolean
Expand Down Expand Up @@ -76,6 +77,7 @@ export const monikaFlagsDefaultValue: MonikaFlags = {
'config-filename': 'monika.yml',
'config-interval': 900,
'create-config': false,
'experimental-fetch': false,
flush: false,
'follow-redirects': 21,
force: false,
Expand Down

0 comments on commit a907167

Please sign in to comment.