-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Split installer into some functions (#33)
* refactor: Add createTempDir() * refactor: Print tempDir to debug log * refactor: Add getBaseLocation() * refactor: Enhance OS type checking * refactor: Prune core.debug * refactor: Prune extra async * refactor: Reduce call count of getBaseLocation() * refactor: Prune extra initialization * refactor: Use node-fetch and test with nock * chore: Add Makefile * docs: Add make command (Maintainer Notes) * ci: Enhance YAML list * style: 💄 reindent * deps: update * test: Add nock.cleanAll() to afterEach()
- Loading branch information
Showing
14 changed files
with
235 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
cmd := "bash" | ||
msg := "" | ||
IMAGE_NAME := actions-mdbook-dev:latest | ||
DOCKER_BUILD := docker build . -t $(IMAGE_NAME) --file ./__tests__/Dockerfile | ||
DOCKER_RUN := docker run --rm -i -t -v ${PWD}:/repo -v ~/.gitconfig:/etc/gitconfig $(IMAGE_NAME) | ||
|
||
|
||
.PHONY: build | ||
build: | ||
$(DOCKER_BUILD) | ||
|
||
.PHONY: run | ||
run: | ||
$(DOCKER_RUN) $(cmd) | ||
|
||
.PHONY: test | ||
test: | ||
$(DOCKER_RUN) npm test | ||
|
||
.PHONY: commit | ||
commit: | ||
$(DOCKER_RUN) git commit -m "$(msg)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,63 @@ | ||
import * as target from '../src/get-latest-version'; | ||
import {getURL, getLatestVersion} from '../src/get-latest-version'; | ||
const nock = require('nock'); | ||
import {FetchError} from 'node-fetch'; | ||
import jsonTestBrew from './data/brew.json'; | ||
import jsonTestGithub from './data/github.json'; | ||
|
||
describe('Test', () => { | ||
test('getURL()', () => { | ||
const org: string = 'rust-lang'; | ||
const repo: string = 'mdbook'; | ||
const urlBrewExpected: string = `https://formulae.brew.sh/api/formula/${repo}.json`; | ||
const urlGithubExpected: string = `https://api.github.com/repos/${org}/${repo}/releases/latest`; | ||
const urlBrew: string = target.getURL(org, repo, 'brew'); | ||
const urlGithub: string = target.getURL(org, repo, 'github'); | ||
beforeEach(() => { | ||
jest.resetModules(); | ||
}); | ||
|
||
afterEach(() => { | ||
nock.cleanAll(); | ||
}); | ||
|
||
const org: string = 'rust-lang'; | ||
const repo: string = 'mdbook'; | ||
const urlBrewExpected: string = `https://formulae.brew.sh/api/formula/${repo}.json`; | ||
const urlGithubExpected: string = `https://api.github.com/repos/${org}/${repo}/releases/latest`; | ||
|
||
describe('getURL()', () => { | ||
test('should return expected URL', () => { | ||
const urlBrew: string = getURL(org, repo, 'brew'); | ||
const urlGithub: string = getURL(org, repo, 'github'); | ||
|
||
expect(urlBrew).toMatch(urlBrewExpected); | ||
expect(urlGithub).toMatch(urlGithubExpected); | ||
}); | ||
}); | ||
|
||
let versionLatest: string = '0.3.5'; | ||
describe('getLatestVersion()', () => { | ||
let versionLatestExpected: string = '0.3.5'; | ||
|
||
test('getLatestBrew()', () => { | ||
const jsonBrew: target.JsonBrew = jsonTestBrew; | ||
const versionBrew: string = target.getLatestBrew(jsonBrew); | ||
expect(versionBrew).toMatch(versionLatest); | ||
test('should return latest version via brew', async () => { | ||
nock('https://formulae.brew.sh') | ||
.get(`/api/formula/${repo}.json`) | ||
.reply(200, jsonTestBrew); | ||
|
||
const versionLatest: string = await getLatestVersion(org, repo, 'brew'); | ||
expect(versionLatest).toMatch(versionLatestExpected); | ||
}); | ||
|
||
test('getLatestGithub()', () => { | ||
const jsonGithub: target.JsonGithub = jsonTestGithub; | ||
const versionGithub: string = target.getLatestGithub(jsonGithub); | ||
expect(versionGithub).toMatch(versionLatest); | ||
test('should return latest version via GitHub', async () => { | ||
nock('https://api.github.com') | ||
.get(`/repos/${org}/${repo}/releases/latest`) | ||
.reply(200, jsonTestGithub); | ||
|
||
const versionLatest: string = await getLatestVersion(org, repo, 'github'); | ||
expect(versionLatest).toMatch(versionLatestExpected); | ||
}); | ||
|
||
test('should return exception 404', async () => { | ||
nock('https://formulae.brew.sh') | ||
.get(`/api/formula/${repo}.json`) | ||
.reply(404); | ||
|
||
try { | ||
const versionLatest: string = await getLatestVersion(org, repo, 'brew'); | ||
console.debug(versionLatest); | ||
} catch (e) { | ||
expect(e).toThrow(FetchError); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.