Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove node-fetch, use built-in fetch #843

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"fixtureJson": true,
"fixtureHjson": true,
"fixtureYaml": true,
"fakeFileSystem": true
"fakeFileSystem": true,
"setFetchMock": true
},
"settings": {
"jsdoc": {
Expand Down
2 changes: 0 additions & 2 deletions bin/openwhisk-standalone-config/get-runtimes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

const fetch = require('node-fetch')

const DOCKER_ORG = 'adobeapiplatform'
const DOCKER_REPOS = { // repo-name:kind
'adobe-action-nodejs-v10': 'nodejs:10',
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"junk": "^3.1.0",
"lodash.clonedeep": "^4.5.0",
"node-abort-controller": "^3.1.1",
"node-fetch": "^2.6.7",
"open": "^8.4.2",
"ora": "^5",
"pure-http": "^3",
Expand Down
1 change: 0 additions & 1 deletion src/lib/audit-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
const fetch = require('node-fetch')
const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
Expand Down
1 change: 0 additions & 1 deletion test/__fixtures__/pack/2.all.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@
"dependencies": {
"@adobe/generator-app-excshell": "^0.2.4",
"@adobe/aio-sdk": "^3.0.0",
"node-fetch": "^2.6.0",
"core-js": "^3.6.4",
"react": "^16.13.1",
"react-dom": "^16.13.1",
Expand Down
3 changes: 1 addition & 2 deletions test/__fixtures__/pack/4.all.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@
"version": "0.0.1",
"private": true,
"dependencies": {
"@adobe/aio-sdk": "^3.0.0",
"node-fetch": "^2.6.0"
"@adobe/aio-sdk": "^3.0.0"
},
"devDependencies": {
"jest": "^27.2.4",
Expand Down
3 changes: 1 addition & 2 deletions test/__fixtures__/pack/6.all.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@
"version": "0.0.1-invalidversion",
"private": true,
"dependencies": {
"@adobe/aio-sdk": "^3.0.0",
"node-fetch": "^2.6.0"
"@adobe/aio-sdk": "^3.0.0"
},
"devDependencies": {
"jest": "^27.2.4",
Expand Down
33 changes: 5 additions & 28 deletions test/commands/lib/audit-logger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@ governing permissions and limitations under the License.
*/

const fs = require('fs')
/* eslint-disable no-unused-vars */
const path = require('path')
/* eslint-disable no-unused-vars */
const chalk = require('chalk')
const fetch = require('node-fetch')
jest.mock('node-fetch', () => jest.fn())
const auditLogger = require('../../../src/lib/audit-logger')
const { getCliEnv } = require('@adobe/aio-lib-env')

jest.mock('fs')
jest.mock('chalk', () => ({
Expand All @@ -41,28 +34,12 @@ const mockLogEvent = {
orgId: 'mockorg'
}

const mockResponse = Promise.resolve({
ok: true,
status: 200,
text: () => {
return {}
}
})

const mockErrorResponse = Promise.resolve({
ok: false,
status: 400,
text: () => {
return {}
}
})

beforeEach(() => {
fetch.mockReset()
setFetchMock(true, 200, {})
})

test('sendAuditLogs with valid params', async () => {
fetch.mockReturnValue(mockResponse)
setFetchMock(true, 200, {})
const options = {
method: 'POST',
headers: {
Expand All @@ -78,7 +55,7 @@ test('sendAuditLogs with valid params', async () => {

// NOTE: this test is blocked until the audit service is available in prod
test('sendAuditLogs with default params', async () => {
fetch.mockReturnValue(mockResponse)
setFetchMock(true, 200, {})
const options = {
method: 'POST',
headers: {
Expand All @@ -93,7 +70,7 @@ test('sendAuditLogs with default params', async () => {
})

test('should take prod endpoint if calling sendAuditLogs with non-exisiting env', async () => {
fetch.mockReturnValue(mockResponse)
setFetchMock(true, 200, {})
const options = {
method: 'POST',
headers: {
Expand All @@ -108,7 +85,7 @@ test('should take prod endpoint if calling sendAuditLogs with non-exisiting env'
})

test('sendAuditLogs error response', async () => {
fetch.mockReturnValue(mockErrorResponse)
setFetchMock(false, 400, {})
const options = {
method: 'POST',
headers: {
Expand Down
8 changes: 8 additions & 0 deletions test/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ global.getErrorForCallThatShouldThrowAnError = async (callThatShouldThrowAnError
}
}

global.setFetchMock = (ok = true, status = 200, mockData = {}) => {
global.fetch = jest.fn().mockResolvedValue({
ok,
status,
text: () => Promise.resolve(mockData)
})
}

/* global fixtureFile, fixtureJson */

const fixturesFolder = path.join(__dirname, '__fixtures__')
Expand Down
Loading