Merge pull request #10394 from backstage/blam/swc2

This commit is contained in:
Ben Lambert
2022-08-23 12:22:49 +02:00
committed by GitHub
38 changed files with 753 additions and 436 deletions
@@ -20,6 +20,14 @@ import { OAuthResult } from '../../lib/oauth';
import { PassportProfile } from '../../lib/passport/types';
import { AuthResolverContext } from '../types';
jest.mock('../../lib/passport/PassportStrategyHelper', () => {
return {
executeFrameHandlerStrategy: jest.fn(),
executeRefreshTokenStrategy: jest.fn(),
executeFetchUserProfileStrategy: jest.fn(),
};
});
const mockFrameHandler = jest.spyOn(
helpers,
'executeFrameHandlerStrategy',
@@ -25,6 +25,14 @@ const mockFrameHandler = jest.spyOn(
() => Promise<{ result: BitbucketOAuthResult; privateInfo: any }>
>;
jest.mock('../../lib/passport/PassportStrategyHelper', () => {
return {
executeFrameHandlerStrategy: jest.fn(),
executeRefreshTokenStrategy: jest.fn(),
executeFetchUserProfileStrategy: jest.fn(),
};
});
describe('createBitbucketProvider', () => {
it('should auth', async () => {
const provider = new BitbucketAuthProvider({
@@ -21,6 +21,15 @@ import { makeProfileInfo } from '../../lib/passport/PassportStrategyHelper';
import { OAuthStartRequest, encodeState } from '../../lib/oauth';
import { AuthResolverContext } from '../types';
jest.mock('../../lib/passport/PassportStrategyHelper', () => {
return {
...jest.requireActual('../../lib/passport/PassportStrategyHelper'),
executeFrameHandlerStrategy: jest.fn(),
executeRefreshTokenStrategy: jest.fn(),
executeFetchUserProfileStrategy: jest.fn(),
};
});
const mockFrameHandler = jest.spyOn(
helpers,
'executeFrameHandlerStrategy',
@@ -23,6 +23,14 @@ import { PassportProfile } from '../../lib/passport/types';
import { OAuthResult } from '../../lib/oauth';
import { AuthResolverContext } from '../types';
jest.mock('../../lib/passport/PassportStrategyHelper', () => {
return {
executeFrameHandlerStrategy: jest.fn(),
executeRefreshTokenStrategy: jest.fn(),
executeFetchUserProfileStrategy: jest.fn(),
};
});
const mockFrameHandler = jest.spyOn(
helpers,
'executeFrameHandlerStrategy',
@@ -19,6 +19,14 @@ import * as helpers from '../../lib/passport/PassportStrategyHelper';
import { OAuthResult } from '../../lib/oauth';
import { AuthResolverContext } from '../types';
jest.mock('../../lib/passport/PassportStrategyHelper', () => {
return {
executeFrameHandlerStrategy: jest.fn(),
executeRefreshTokenStrategy: jest.fn(),
executeFetchUserProfileStrategy: jest.fn(),
};
});
const mockFrameHandler = jest.spyOn(
helpers,
'executeFrameHandlerStrategy',
@@ -23,6 +23,12 @@ import { rest } from 'msw';
import { setupServer } from 'msw/node';
import { AuthResolverContext } from '../types';
jest.mock('../../lib/passport/PassportStrategyHelper', () => {
return {
executeFrameHandlerStrategy: jest.fn(),
};
});
const mockFrameHandler = jest.spyOn(
helpers,
'executeFrameHandlerStrategy',
@@ -19,6 +19,14 @@ import * as helpers from '../../lib/passport/PassportStrategyHelper';
import { OAuthResult } from '../../lib/oauth';
import { AuthResolverContext } from '../types';
jest.mock('../../lib/passport/PassportStrategyHelper', () => {
return {
executeFrameHandlerStrategy: jest.fn(),
executeRefreshTokenStrategy: jest.fn(),
executeFetchUserProfileStrategy: jest.fn(),
};
});
const mockFrameHandler = jest.spyOn(
helpers,
'executeFrameHandlerStrategy',
@@ -19,6 +19,14 @@ import * as helpers from '../../lib/passport/PassportStrategyHelper';
import { OAuthResult } from '../../lib/oauth';
import { AuthResolverContext } from '../types';
jest.mock('../../lib/passport/PassportStrategyHelper', () => {
return {
executeFrameHandlerStrategy: jest.fn(),
executeRefreshTokenStrategy: jest.fn(),
executeFetchUserProfileStrategy: jest.fn(),
};
});
const mockFrameHandler = jest.spyOn(
helpers,
'executeFrameHandlerStrategy',
@@ -20,7 +20,7 @@ import { BitriseBuildDetailsDialog } from './BitriseBuildDetailsDialog';
import { BitriseBuildResult } from '../../api/bitriseApi.model';
jest.mock('../BitriseArtifactsComponent', () => ({
BitriseArtifactsComponent: (_props: { build: string }) => <></>,
BitriseArtifactsComponent: (_props: { build: string }) => <>VISIBLE</>,
}));
describe('BitriseArtifactsComponent', () => {
@@ -42,18 +42,14 @@ describe('BitriseArtifactsComponent', () => {
expect(await rendered.findByTestId('btn')).toBeInTheDocument();
});
it('should change the state when the button is clicked', async () => {
const setOpen = jest.fn();
const useStateMock: any = (initState: any) => [initState, setOpen];
jest.spyOn(React, 'useState').mockImplementation(useStateMock);
it('should open the modal when clicked to render the ArtifactsComponent', async () => {
const rendered = renderComponent();
const btn = await rendered.findByTestId('btn');
expect(await rendered.queryByText('VISIBLE')).not.toBeInTheDocument();
btn.click();
expect(setOpen).toHaveBeenCalled();
expect(rendered.getByText('VISIBLE')).toBeInTheDocument();
});
});
@@ -21,6 +21,11 @@ import { EntityProviderConnection } from '@backstage/plugin-catalog-backend';
import { GitHubEntityProvider } from './GitHubEntityProvider';
import * as helpers from '../lib/github';
jest.mock('../lib/github', () => {
return {
getOrganizationRepositories: jest.fn(),
};
});
class PersistingTaskRunner implements TaskRunner {
private tasks: TaskInvocationDefinition[] = [];
@@ -37,7 +37,7 @@ const octokit = {
},
};
jest.doMock('@octokit/rest', () => {
jest.mock('@octokit/rest', () => {
class Octokit {
constructor() {
return octokit;
@@ -13,16 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const executeShellCommand = jest.fn();
const commandExists = jest.fn();
const fetchContents = jest.fn();
jest.mock('@backstage/plugin-scaffolder-backend', () => ({
...jest.requireActual('@backstage/plugin-scaffolder-backend'),
fetchContents,
executeShellCommand,
}));
jest.mock('command-exists', () => commandExists);
import {
getVoidLogger,
@@ -39,6 +29,23 @@ import { createFetchCookiecutterAction } from './cookiecutter';
import { join } from 'path';
import type { ActionContext } from '@backstage/plugin-scaffolder-backend';
const executeShellCommand = jest.fn();
const commandExists = jest.fn();
const fetchContents = jest.fn();
jest.mock('@backstage/plugin-scaffolder-backend', () => ({
...jest.requireActual('@backstage/plugin-scaffolder-backend'),
fetchContents: (...args: any[]) => fetchContents(...args),
executeShellCommand: (...args: any[]) => executeShellCommand(...args),
}));
jest.mock(
'command-exists',
() =>
(...args: any[]) =>
commandExists(...args),
);
describe('fetch:cookiecutter', () => {
const integrations = ScmIntegrations.fromConfig(
new ConfigReader({
@@ -18,17 +18,20 @@ const executeShellCommand = jest.fn();
const commandExists = jest.fn();
jest.mock('@backstage/plugin-scaffolder-backend', () => ({
executeShellCommand,
executeShellCommand: (...args: any[]) => executeShellCommand(...args),
}));
jest.mock('command-exists', () => commandExists);
jest.mock(
'command-exists',
() =>
(...args: any[]) =>
commandExists(...args),
);
jest.mock('fs-extra');
import { ContainerRunner } from '@backstage/backend-common';
import fs from 'fs-extra';
import path from 'path';
import { PassThrough } from 'stream';
import { RailsNewRunner } from './railsNewRunner';
describe('Rails Templater', () => {
@@ -14,20 +14,6 @@
* limitations under the License.
*/
const mockAccess = jest.fn();
jest.doMock('fs-extra', () => ({
access: mockAccess,
promises: {
access: mockAccess,
},
constants: {
F_OK: 0,
W_OK: 1,
},
mkdir: jest.fn(),
remove: jest.fn(),
}));
import {
DatabaseManager,
getVoidLogger,
@@ -55,6 +41,21 @@ import {
import { createRouter, DatabaseTaskStore, TaskBroker } from '../index';
import { StorageTaskBroker } from '../scaffolder/tasks/StorageTaskBroker';
const mockAccess = jest.fn();
jest.mock('fs-extra', () => ({
access: (...args: any[]) => mockAccess(...args),
promises: {
access: (...args: any[]) => mockAccess(...args),
},
constants: {
F_OK: 0,
W_OK: 1,
},
mkdir: jest.fn(),
remove: jest.fn(),
}));
function createDatabase(): PluginDatabaseManager {
return DatabaseManager.fromConfig(
new ConfigReader({
@@ -29,12 +29,12 @@ import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
const useTechDocsReaderDom = jest.fn();
jest.mock('./dom', () => ({
...jest.requireActual('./dom'),
useTechDocsReaderDom,
useTechDocsReaderDom: (...args: any[]) => useTechDocsReaderDom(...args),
}));
const useReaderState = jest.fn();
jest.mock('../useReaderState', () => ({
...jest.requireActual('../useReaderState'),
useReaderState,
useReaderState: (...args: any[]) => useReaderState(...args),
}));
import { TechDocsReaderPageContent } from './TechDocsReaderPageContent';