Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
BuZZ-T committed Apr 10, 2022
1 parent 95cfe16 commit a35f6dc
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 34 deletions.
45 changes: 16 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ E.g.:

## Use as API

rusted-chromium can be used as API as well. See more examples [here]().

### Import store

To import a store file, use `importAndMergeStore`:
Expand All @@ -302,47 +304,32 @@ To download a chromium version, use `downloadChromium`:
import { ComparableVersion, downloadChromium } from 'rusted-chromium';

downloadChromium({
min: new ComparableVersion(0, 0, 0, 0),
max: new ComparableVersion(1000, 0, 0, 0),
results: 10,
os: 'linux',
arch: 'x64',
onFail: 'nothing',
autoUnzip: false,
interactive: false,
store: true,
download: true,
hideNegativeHits: boolean
downloadFolder: null,
onlyNewestMajor: false
single: null,
hideNegativeHits: false,
interactive: true,
inverse: false,
});
```

### Download a specific version of chromium

This is probably the most useful version in a CI envionment. This requires less config options, as many of them are not regarded when using `single`.

```ts
import { downloadChromium } from 'rusted-chromium';

downloadChromium({
arch: 'x64',
single: "10.0.0.0",
max: new ComparableVersion(95, 0, 0, 0),
min: new ComparableVersion(0,0,0,0),
onFail: 'nothing',
onlyNewestMajor: false,
os: 'linux',
autoUnzip: false,
download: true,
quiet: false,
store: true,
results: 10,
downloadFolder: null,
});
single: null,
})
```

### Directly pass CLI flags
If you want to directly pass `process.argv` and extend or restrict the available flags, directly import `rusted`:
```ts
import { rusted } from 'rusted-chromium';
import { rusted } from 'rusted-chromium'

rusted(process.argv, 'linux')

rusted(process.argv);
```

## FAQ
Expand Down
22 changes: 22 additions & 0 deletions download.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,28 @@ describe('download', () => {
expect(fetchChromeZipFileMock).toHaveBeenCalledWith('chromeUrl')
})

it.only('should fetch the zip with defaults', async () => {
getChromeDownloadUrlMock.mockResolvedValue(createGetChromeDownloadUrlReturn())

fetchChromeZipFileMock.mockResolvedValue(zipFileResource)

// Act
await downloadChromium.withDefaults()

expect(progressConstructorMock).toHaveBeenCalledTimes(1)
expect(progressConstructorMock).toHaveBeenCalledWith(zipFileResource, { throttle: 100 })

expect(progressMock.start).toHaveBeenCalledTimes(0)
expect(progressMock.fraction).toHaveBeenCalledTimes(0)

expect(fetchChromeZipFileMock).toHaveBeenCalledTimes(1)
expect(fetchChromeZipFileMock).toHaveBeenCalledWith('chromeUrl')
})

it.skip('should', () => {
//
})

it('should fetch and exract the zip', async () => {
getChromeDownloadUrlMock.mockResolvedValue(createGetChromeDownloadUrlReturn())

Expand Down
15 changes: 10 additions & 5 deletions download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { DEFAULT_FULL_CONFIG, DEFAULT_SINGLE_CONFIG } from './commons/constants'
import { DOWNLOAD_ZIP, EXTRACT_ZIP } from './commons/loggerTexts'
import { NoChromiumDownloadError } from './errors'
import type { IChromeConfig } from './interfaces/interfaces'
import { ProgressConfig } from './interfaces/interfaces'
import { logger } from './log/logger'
import { progress } from './log/progress'
import { spinner } from './log/spinner'
Expand Down Expand Up @@ -72,6 +71,12 @@ async function extractZip(downloadPath: string) {
}
}

/**
* Downloads a chromium zip file based on the given config
* @see DEFAULT_FULL_CONFIG
* @see DEFAULT_SINGLE_CONFIG
* @param additionalConfig Manually set config, which will override the settings in the default config
*/
async function downloadForConfig(config: IChromeConfig): Promise<void> {

const versions = await loadVersions()
Expand Down Expand Up @@ -138,11 +143,11 @@ async function downloadForConfig(config: IChromeConfig): Promise<void> {
}

/**
* Downlodas a chromium zip file based on the given config
* @param pConfig
* Downlodas a chromium zip file with default config, which can be partially overridden
* @param config IChromeConfig to override the default config. May omit fields and can be ommited entirely
* @returns
*/
const withDefaults = (pConfig: Partial<IChromeConfig> = {}) => downloadForConfig(enrichAdditionalConfig(pConfig))
const withDefaults = (config: Partial<IChromeConfig> = {}) => downloadForConfig(enrichAdditionalConfig(config))

/**
* Downloads a chromium zip file based on the given config
Expand All @@ -151,6 +156,6 @@ const withDefaults = (pConfig: Partial<IChromeConfig> = {}) => downloadForConfig
* @param additionalConfig Manually set config, which will override the settings in the default config
*/
export const downloadChromium = Object.assign(
(config: IChromeConfig) => downloadForConfig(config),
downloadForConfig,
{ withDefaults }
)
8 changes: 8 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,11 @@ importAndMergeLocalstore({
url: 'https://rusted.buzz-t.eu/localstore.json'
})
```

### example-pass-cli-flags.ts
Directly pass the cli flags to `rusted-chromium` and it interpret it.
```ts
import { rusted } from 'rusted-chromium'

rusted(process.argv, 'linux')
```
3 changes: 3 additions & 0 deletions examples/example-pass-cli-flags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { rusted } from 'rusted-chromium'

rusted(process.argv, 'linux')

0 comments on commit a35f6dc

Please sign in to comment.