-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added fetch api utility library for building a ConfiguredFetch
- Loading branch information
Showing
23 changed files
with
409 additions
and
23 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,3 @@ | ||
{ | ||
"presets": [["@nrwl/web/babel", { "useBuiltIns": "usage" }]] | ||
} |
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,18 @@ | ||
{ | ||
"extends": ["../../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
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,19 @@ | ||
/* eslint-disable */ | ||
(global as any).testFolderRootPath = '<rootDir>/../../..'; | ||
(global as any).appTestType = 'node'; | ||
|
||
module.exports = { | ||
displayName: 'util-fetch', | ||
preset: '../../../jest.preset.ts', | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: '<rootDir>/tsconfig.spec.json' | ||
} | ||
}, | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.[tj]sx?$': 'ts-jest' | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], | ||
coverageDirectory: '../../../coverage/packages/util/fetch' | ||
}; |
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,4 @@ | ||
{ | ||
"name": "@dereekb/util/fetch", | ||
"version": "0.0.1" | ||
} |
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,34 @@ | ||
{ | ||
"$schema": "../../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "packages/util/fetch/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build-base": { | ||
"executor": "@nrwl/js:tsc", | ||
"outputs": ["{options.outputPath}"], | ||
"options": { | ||
"outputPath": "dist/packages/util/fetch", | ||
"tsConfig": "packages/util/fetch/tsconfig.lib.json", | ||
"packageJson": "packages/util/fetch/package.json", | ||
"main": "packages/util/fetch/src/index.ts", | ||
"assets": ["packages/util/fetch/*.md"] | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nrwl/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["packages/util/fetch/**/*.ts"] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nrwl/jest:jest", | ||
"outputs": ["coverage/packages/util/fetch", "./.reports/jest/util-fetch.junit.xml"], | ||
"options": { | ||
"jestConfig": "packages/util/fetch/jest.config.ts", | ||
"passWithNoTests": true | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
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 @@ | ||
export * from './lib'; |
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,60 @@ | ||
import { itShouldFail, expectFail } from '@dereekb/util/test'; | ||
import { fetchService, fetchRequestFactory, FetchRequestFactory, FetchService } from './fetch'; | ||
import fetch, { Request, RequestInfo, RequestInit } from 'node-fetch'; | ||
|
||
// TEMP: Fetch global is not available in jest? Use node-fetch@2 for now. | ||
|
||
const testFetch: FetchService = fetchService({ | ||
makeFetch: fetch as any, | ||
makeRequest: (x, y) => new Request(x as RequestInfo, y as RequestInit) as any | ||
}); | ||
|
||
describe('fetchRequestFactory()', () => { | ||
describe('function', () => { | ||
describe('with baseUrl', () => { | ||
describe('invalid', () => { | ||
itShouldFail('when creating a factory with an invalid base url', () => { | ||
const baseUrl = 'invalidurl'; | ||
|
||
expectFail(() => | ||
testFetch.fetchRequestFactory({ | ||
baseUrl | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
describe('valid', () => { | ||
const baseUrl = 'https://components.dereekb.com/'; | ||
|
||
const factory = testFetch.fetchRequestFactory({ | ||
baseUrl | ||
}); | ||
|
||
it('should retain the path of an input request.', () => { | ||
const expectedUrl = 'https://google.com/'; | ||
const request = testFetch.makeRequest(expectedUrl); | ||
const result = factory(request); | ||
expect(result.url).toBe(expectedUrl); | ||
}); | ||
|
||
it('should retain the path of an input URL.', () => { | ||
const expectedUrl = 'https://google.com/'; | ||
const request = new URL(expectedUrl); | ||
const result = factory(request); | ||
expect(result.url).toBe(expectedUrl); | ||
}); | ||
|
||
it('should append the base url to the request.', () => { | ||
const result = factory('test'); | ||
expect(result.url).toBe('https://components.dereekb.com/test'); | ||
}); | ||
|
||
it('should append the base url to the request if it has a front slash.', () => { | ||
const result = factory('/test'); | ||
expect(result.url).toBe('https://components.dereekb.com/test'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.