diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 2e82716..e790d3a 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -12,3 +12,4 @@ on: jobs: build: uses: adobe/aio-reusable-workflows/.github/workflows/node.js.yml@main + secrets: inherit diff --git a/jest.setup.js b/jest.setup.js index 309fc53..3efa0e4 100644 --- a/jest.setup.js +++ b/jest.setup.js @@ -17,6 +17,13 @@ const eol = require('eol') jest.setTimeout(30000) +global.setFetchMock = (ok = true, mockData = {}) => { + global.fetch = jest.fn().mockResolvedValue({ + ok, + json: () => Promise.resolve(mockData) + }) +} + const fixturesFolder = path.join(__dirname, 'test/__fixtures__') global.fixturePath = (file) => { return `${fixturesFolder}/${file}` diff --git a/package.json b/package.json index 1a8ddde..8c7d363 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ "fs-extra": "^10.1.0", "inquirer": "^8.2.4", "js-yaml": "^3.14.1", - "node-fetch": "^2.6.7", "ora": "^4.1.1", "yeoman-environment": "^4.2.1" }, diff --git a/src/lib/npm-helper.js b/src/lib/npm-helper.js index cf82c01..9122a1b 100644 --- a/src/lib/npm-helper.js +++ b/src/lib/npm-helper.js @@ -10,7 +10,6 @@ * governing permissions and limitations under the License. */ -const fetch = require('node-fetch') const fs = require('fs-extra') const path = require('path') const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app-templates:lib-npm-helper', { provider: 'debug' }) diff --git a/test/commands/templates/rollback.test.js b/test/commands/templates/rollback.test.js index 57de563..33d804d 100644 --- a/test/commands/templates/rollback.test.js +++ b/test/commands/templates/rollback.test.js @@ -15,7 +15,6 @@ const BaseCommand = require('../../../src/BaseCommand') const { TEMPLATE_PACKAGE_JSON_KEY, getNpmLocalVersion, hideNPMWarnings, readPackageJson, writeObjectToPackageJson } = require('../../../src/lib/npm-helper') const { prompt } = require('../../../src/lib/helper') -// const fetch = require('node-fetch') const inquirer = require('inquirer') const { stdout } = require('stdout-stderr') diff --git a/test/lib/npm-helper.test.js b/test/lib/npm-helper.test.js index b1c5a25..e1af12c 100644 --- a/test/lib/npm-helper.test.js +++ b/test/lib/npm-helper.test.js @@ -21,7 +21,6 @@ const { hideNPMWarnings } = require('../../src/lib/npm-helper') -const fetch = require('node-fetch') const fs = require('fs-extra') const { stderr } = require('stdout-stderr') const path = require('path') @@ -29,17 +28,13 @@ const os = require('os') const processCwd = process.cwd() jest.mock('fs-extra') // do not touch the real fs -jest.mock('node-fetch') - -const createMockResponse = _json => { - return { - json: async () => _json - } -} beforeEach(() => { fs.readJson.mockReset() fs.writeJson.mockReset() + if (global.fetch && typeof global.fetch.mockReset === 'function') { + global.fetch.mockReset() + } }) describe('processNpmPackageSpec', () => { @@ -189,7 +184,7 @@ test('npmTextSearch', async () => { const json = { objects: [] } - fetch.mockResolvedValueOnce(createMockResponse(json)) + global.setFetchMock(true, json) return expect(npmTextSearch()).resolves.toStrictEqual(json) }) @@ -201,7 +196,7 @@ test('getNpmLatestVersion', async () => { } } - fetch.mockResolvedValueOnce(createMockResponse(json)) + global.setFetchMock(true, json) return expect(getNpmLatestVersion('foo')).resolves.toStrictEqual(json['dist-tags'].latest) })