Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Mocking @contentstack/cli-utilities to avoid ESM uuid issues and upgrade cli dependencies#159
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
ada3a189980454189764d3b9750ab3aa64db815313781d99daa6f710ec5e3b0f1bb6eb8565cf5060ad9ab529a384fa7cc5File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -25,4 +25,10 @@ export default tseslint.config( | ||
| ] | ||
| }, | ||
| }, | ||
| { | ||
| files: ['src/**/*.test.ts'], | ||
| rules: { | ||
| 'max-len': 'off', | ||
| }, | ||
| }, | ||
| ); | ||
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,10 @@ | ||
| import { fileUploadAdapter as cliUtilitiesJestMock } from '../test/mocks/cli-utilities'; | ||
| import FileUpload from './file-upload'; | ||
| import BaseClass from './base-class'; | ||
| import { cliux } from '@contentstack/cli-utilities'; | ||
| import { DeploymentStatus } from '../types/launch'; | ||
| jest.mock('@contentstack/cli-utilities', () => ({ | ||
| ...jest.requireActual('@contentstack/cli-utilities'), | ||
| cliux: { | ||
| inquire: jest.fn(), | ||
| loader: jest.fn(), | ||
| print: jest.fn(), | ||
| }, | ||
| configHandler: { | ||
| get: jest.fn(), | ||
| }, | ||
| HttpClient: jest.fn(), | ||
| })); | ||
| jest.mock('@contentstack/cli-utilities', () => cliUtilitiesJestMock); | ||
SakshiKoli-CS marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| describe('FileUpload Adapter', () => { | ||
| let logMock: jest.Mock; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import { githubAdapter as cliUtilitiesJestMock } from '../test/mocks/cli-utilities'; | ||
| import GitHub from './github'; | ||
| import { getRemoteUrls } from '../util/create-git-meta'; | ||
| import { repositoriesQuery, userConnectionsQuery } from '../graphql'; | ||
| @@ -6,16 +7,7 @@ import { existsSync } from 'fs'; | ||
| import { DeploymentStatus } from '../types'; | ||
| import { cliux as ux } from '@contentstack/cli-utilities'; | ||
| jest.mock('@contentstack/cli-utilities', () => ({ | ||
| ...jest.requireActual('@contentstack/cli-utilities'), | ||
| cliux: { | ||
| inquire: jest.fn(), | ||
| print: jest.fn(), | ||
| }, | ||
| configHandler: { | ||
| get: jest.fn(), | ||
| }, | ||
| })); | ||
| jest.mock('@contentstack/cli-utilities', () => cliUtilitiesJestMock); | ||
SakshiKoli-CS marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| jest.mock('../util/create-git-meta'); | ||
| jest.mock('fs', () => ({ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| import { functionsCommand as cliUtilitiesJestMock } from '../../test/mocks/cli-utilities'; | ||
| import Functions from './functions'; | ||
| import { Logger } from '../../util'; | ||
| import { Contentfly } from '../../util/cloud-function/contentfly'; | ||
| jest.mock('@contentstack/cli-utilities', () => cliUtilitiesJestMock); | ||
SakshiKoli-CS marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| jest.mock('../../util'); | ||
| jest.mock('../../util/cloud-function/contentfly'); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,26 @@ | ||
| import { launchCommand as cliUtilitiesJestMock } from '../../test/mocks/cli-utilities'; | ||
| import Launch from './index'; | ||
| import { BaseCommand } from '../../base-command'; | ||
| import { FileUpload, GitHub, PreCheck } from '../../adapters'; | ||
| import { cliux } from '@contentstack/cli-utilities'; | ||
| import { cliux, configHandler } from '@contentstack/cli-utilities'; | ||
| jest.mock('../../base-command'); | ||
| jest.mock('@contentstack/cli-utilities', () => cliUtilitiesJestMock); | ||
| jest.mock('@contentstack/cli-utilities', () => { | ||
| const actual = jest.requireActual('@contentstack/cli-utilities'); | ||
| return { | ||
| ...actual, | ||
| configHandler: { | ||
| get: jest.fn((key) => { | ||
| if (key === 'authtoken') return 'dummy-token'; | ||
| if (key === 'authorisationType') return 'OAuth'; | ||
| if (key === 'oauthAccessToken') return 'dummy-oauth-token'; | ||
| return undefined; | ||
| }), | ||
| }, | ||
| cliux: { | ||
| ...actual.cliux, | ||
| inquire: jest.fn(), // mock `inquire` explicitly | ||
| }, | ||
| }; | ||
| }); | ||
| const LaunchWithArgv = Launch as unknown as new (argv: string[], config: unknown) => Launch; | ||
SakshiKoli-CS marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| describe('Run', () => { | ||
| let launchCommandInstance: Launch; | ||
| let prepareApiClientsMock: jest.SpyInstance; | ||
| let preCheckRunMock: jest.SpyInstance; | ||
| beforeEach(() => { | ||
| (configHandler.get as jest.Mock).mockImplementation((key: string) => { | ||
| if (key === 'authtoken') return 'dummy-token'; | ||
| if (key === 'authorisationType') return 'OAuth'; | ||
| if (key === 'oauthAccessToken') return 'dummy-oauth-token'; | ||
| return undefined; | ||
| }); | ||
| prepareApiClientsMock = jest.spyOn(BaseCommand.prototype, 'prepareApiClients').mockResolvedValueOnce(undefined); | ||
| // @ts-expect-error - Override readonly property context on BaseCommand for testing | ||
| BaseCommand.prototype['context'] = { analyticsInfo: {} } as any; | ||
| @@ -45,7 +36,7 @@ describe('Run', () => { | ||
| const githubRunMock = jest.spyOn(GitHub.prototype, 'run').mockResolvedValueOnce(undefined); | ||
| BaseCommand.prototype['sharedConfig'] = { provider: 'GitHub', isExistingProject: true } as any; | ||
| BaseCommand.prototype['flags'] = { init: false }; | ||
| launchCommandInstance = new Launch([], {} as any); | ||
| launchCommandInstance = new LaunchWithArgv([], {} as any); | ||
| await launchCommandInstance.run(); | ||
| @@ -58,7 +49,7 @@ describe('Run', () => { | ||
| const fileUploadRunMock = jest.spyOn(FileUpload.prototype, 'run').mockResolvedValueOnce(undefined); | ||
| BaseCommand.prototype['sharedConfig'] = { provider: 'FileUpload', isExistingProject: true } as any; | ||
| BaseCommand.prototype['flags'] = { init: false }; | ||
| launchCommandInstance = new Launch([], {} as any); | ||
| launchCommandInstance = new LaunchWithArgv([], {} as any); | ||
| await launchCommandInstance.run(); | ||
| @@ -73,7 +64,7 @@ describe('Run', () => { | ||
| .mockResolvedValueOnce(undefined); | ||
| BaseCommand.prototype['sharedConfig'] = { provider: 'OtherProvider', isExistingProject: true } as any; | ||
| BaseCommand.prototype['flags'] = { init: false }; | ||
| launchCommandInstance = new Launch([], {} as any); | ||
| launchCommandInstance = new LaunchWithArgv([], {} as any); | ||
| await launchCommandInstance.run(); | ||
| @@ -89,7 +80,7 @@ describe('Run', () => { | ||
| BaseCommand.prototype['sharedConfig'] = { provider: 'GitHub', isExistingProject: false } as any; | ||
| BaseCommand.prototype['flags'] = { init: false }; | ||
| (cliux.inquire as jest.Mock).mockResolvedValueOnce('GitHub'); | ||
| launchCommandInstance = new Launch([], {} as any); | ||
| launchCommandInstance = new LaunchWithArgv([], {} as any); | ||
| await launchCommandInstance.run(); | ||
| @@ -111,7 +102,7 @@ describe('Run', () => { | ||
| const githubRunMock = jest.spyOn(GitHub.prototype, 'run').mockResolvedValueOnce(undefined); | ||
| BaseCommand.prototype['sharedConfig'] = {isExistingProject: false} as any; | ||
| BaseCommand.prototype['flags'] = { init: false, type: 'GitHub' }; | ||
| launchCommandInstance = new Launch([], {} as any); | ||
| launchCommandInstance = new LaunchWithArgv([], {} as any); | ||
| await launchCommandInstance.run(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import { Args, Command, Errors, Flags, Interfaces } from '@oclif/core'; | ||
| class CLIError extends Error {} | ||
| export const launchCommand = { | ||
| Args, | ||
| Command, | ||
| Errors, | ||
| Flags, | ||
| Interfaces, | ||
| CLIError, | ||
| cliux: { | ||
| inquire: jest.fn(), | ||
| print: jest.fn(), | ||
| loader: jest.fn(), | ||
| registerSearchPlugin: jest.fn(), | ||
| }, | ||
| configHandler: { get: jest.fn() }, | ||
| authHandler: { | ||
| compareOAuthExpiry: jest.fn().mockResolvedValue(undefined), | ||
| host: '', | ||
| }, | ||
| HttpClient: jest.fn(), | ||
| ContentstackClient: jest.fn(), | ||
| isAuthenticated: jest.fn().mockReturnValue(true), | ||
| managementSDKClient: jest.fn(), | ||
| managementSDKInitiator: jest.fn(), | ||
| }; | ||
| export const fileUploadAdapter = { | ||
| cliux: { | ||
| inquire: jest.fn(), | ||
| loader: jest.fn(), | ||
| print: jest.fn(), | ||
| registerSearchPlugin: jest.fn(), | ||
| confirm: jest.fn(), | ||
| prompt: jest.fn(), | ||
| styledJSON: jest.fn(), | ||
| table: jest.fn(), | ||
| }, | ||
| configHandler: { get: jest.fn() }, | ||
| HttpClient: jest.fn(), | ||
| ContentstackClient: jest.fn(), | ||
| authHandler: { | ||
| compareOAuthExpiry: jest.fn().mockResolvedValue(undefined), | ||
| host: '', | ||
| }, | ||
| }; | ||
| export const githubAdapter = { | ||
| cliux: { | ||
| inquire: jest.fn(), | ||
| print: jest.fn(), | ||
| loader: jest.fn(), | ||
| registerSearchPlugin: jest.fn(), | ||
| confirm: jest.fn(), | ||
| prompt: jest.fn(), | ||
| styledJSON: jest.fn(), | ||
| table: jest.fn(), | ||
| }, | ||
| configHandler: { get: jest.fn() }, | ||
| ContentstackClient: jest.fn(), | ||
| authHandler: { | ||
| compareOAuthExpiry: jest.fn().mockResolvedValue(undefined), | ||
| host: '', | ||
| }, | ||
| }; | ||
| export const baseClassAdapter = { | ||
| cliux: { | ||
| inquire: jest.fn(), | ||
| table: jest.fn(), | ||
| print: jest.fn(), | ||
| loader: jest.fn(), | ||
| registerSearchPlugin: jest.fn(), | ||
| confirm: jest.fn(), | ||
| prompt: jest.fn(), | ||
| styledJSON: jest.fn(), | ||
| }, | ||
| ContentstackClient: jest.fn(), | ||
| configHandler: { get: jest.fn() }, | ||
| authHandler: { | ||
| compareOAuthExpiry: jest.fn().mockResolvedValue(undefined), | ||
| host: '', | ||
| }, | ||
| }; | ||
| export const functionsCommand = {}; | ||
| export const logPolling = { | ||
| cliux: { | ||
| loaderV2: jest.fn(() => ({})), | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| import { logPolling as cliUtilitiesJestMock } from '../test/mocks/cli-utilities'; | ||
| type LogPollingCtor = typeof import('./logs-polling-utilities').default; | ||
| jest.mock('@contentstack/cli-utilities', () => cliUtilitiesJestMock); | ||
SakshiKoli-CS marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const CONFIG = { | ||
| deployment: 'd1', | ||
| environment: 'e1', | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,5 +12,8 @@ | ||
| }, | ||
| "include": [ | ||
| "src/**/*" | ||
| ], | ||
| "exclude": [ | ||
| "src/test/**" | ||
| ] | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.