@@ -19,12 +19,15 @@ import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { createMockDirectory } from '@backstage/backend-test-utils';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
import { ActionContext } from '@backstage/plugin-scaffolder-node';
|
||||
import * as winston from 'winston';
|
||||
|
||||
/**
|
||||
* A utility method to create a mock action context for scaffolder actions.
|
||||
*
|
||||
* @param input - a schema for user input parameters
|
||||
*
|
||||
* @param workspacePath
|
||||
* @param logger
|
||||
* @public
|
||||
*/
|
||||
export const createMockActionContext = <
|
||||
@@ -32,12 +35,14 @@ export const createMockActionContext = <
|
||||
TActionOutput extends JsonObject = JsonObject,
|
||||
>(
|
||||
input?: TActionInput,
|
||||
workspacePath?: string,
|
||||
logger?: winston.Logger,
|
||||
): ActionContext<TActionInput, TActionOutput> => {
|
||||
const mockDir = createMockDirectory();
|
||||
|
||||
return {
|
||||
workspacePath: mockDir.path,
|
||||
logger: getVoidLogger(),
|
||||
workspacePath: workspacePath
|
||||
? workspacePath
|
||||
: createMockDirectory().resolve('workspace'),
|
||||
logger: logger ? logger : getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
|
||||
@@ -18,11 +18,10 @@ import yaml from 'yaml';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { createPublishAzureAction } from './azure';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { WebApi } from 'azure-devops-node-api';
|
||||
import { PassThrough } from 'stream';
|
||||
import { initRepoAndPush } from '@backstage/plugin-scaffolder-node';
|
||||
import { examples } from './azure.examples';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
|
||||
jest.mock('azure-devops-node-api', () => ({
|
||||
WebApi: jest.fn(),
|
||||
@@ -55,13 +54,7 @@ describe('publish:azure examples', () => {
|
||||
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
const action = createPublishAzureAction({ integrations, config });
|
||||
const mockContext = {
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
const mockContext = createMockActionContext();
|
||||
|
||||
const mockGitClient = {
|
||||
createRepository: jest.fn(),
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
"devDependencies": {
|
||||
"@backstage/backend-test-utils": "workspace:^",
|
||||
"@backstage/cli": "workspace:^",
|
||||
"@backstage/scaffolder-test-utils": "workspace:^",
|
||||
"msw": "^1.0.0"
|
||||
},
|
||||
"files": [
|
||||
|
||||
+5
-13
@@ -32,9 +32,8 @@ import { setupServer } from 'msw/node';
|
||||
import { setupRequestMockHandlers } from '@backstage/backend-test-utils';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { PassThrough } from 'stream';
|
||||
import { initRepoAndPush } from '@backstage/plugin-scaffolder-node';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
|
||||
describe('publish:bitbucketCloud', () => {
|
||||
const config = new ConfigReader({
|
||||
@@ -50,17 +49,10 @@ describe('publish:bitbucketCloud', () => {
|
||||
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
const action = createPublishBitbucketCloudAction({ integrations, config });
|
||||
const mockContext = {
|
||||
input: {
|
||||
repoUrl: 'bitbucket.org?workspace=workspace&project=project&repo=repo',
|
||||
repoVisibility: 'private' as const,
|
||||
},
|
||||
workspacePath: 'wsp',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
const mockContext = createMockActionContext({
|
||||
repoUrl: 'bitbucket.org?workspace=workspace&project=project&repo=repo',
|
||||
repoVisibility: 'private' as const,
|
||||
});
|
||||
const server = setupServer();
|
||||
setupRequestMockHandlers(server);
|
||||
|
||||
|
||||
+2
-10
@@ -14,16 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { rest } from 'msw';
|
||||
import { setupServer } from 'msw/node';
|
||||
import { PassThrough } from 'stream';
|
||||
import { createBitbucketPipelinesRunAction } from './bitbucketCloudPipelinesRun';
|
||||
import yaml from 'yaml';
|
||||
import { examples } from './bitbucketCloudPipelinesRun.examples';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import { setupRequestMockHandlers } from '@backstage/backend-test-utils';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
|
||||
describe('bitbucket:pipelines:run', () => {
|
||||
const config = new ConfigReader({
|
||||
@@ -39,14 +38,7 @@ describe('bitbucket:pipelines:run', () => {
|
||||
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
const action = createBitbucketPipelinesRunAction({ integrations });
|
||||
const mockContext = {
|
||||
input: {},
|
||||
workspacePath: 'wsp',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
const mockContext = createMockActionContext();
|
||||
const responseJson = {
|
||||
repository: {
|
||||
links: {
|
||||
|
||||
+2
-10
@@ -14,14 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { rest } from 'msw';
|
||||
import { setupServer } from 'msw/node';
|
||||
import { setupRequestMockHandlers } from '@backstage/backend-test-utils';
|
||||
import { PassThrough } from 'stream';
|
||||
import { createBitbucketPipelinesRunAction } from './bitbucketCloudPipelinesRun';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
|
||||
describe('bitbucket:pipelines:run', () => {
|
||||
const config = new ConfigReader({
|
||||
@@ -37,14 +36,7 @@ describe('bitbucket:pipelines:run', () => {
|
||||
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
const action = createBitbucketPipelinesRunAction({ integrations });
|
||||
const mockContext = {
|
||||
input: {},
|
||||
workspacePath: 'wsp',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
const mockContext = createMockActionContext();
|
||||
const workspace = 'test-workspace';
|
||||
const repo_slug = 'test-repo-slug';
|
||||
const responseJson = {
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
"devDependencies": {
|
||||
"@backstage/backend-test-utils": "workspace:^",
|
||||
"@backstage/cli": "workspace:^",
|
||||
"@backstage/scaffolder-test-utils": "workspace:^",
|
||||
"msw": "^1.0.0"
|
||||
},
|
||||
"files": [
|
||||
|
||||
+5
-13
@@ -32,9 +32,8 @@ import { setupServer } from 'msw/node';
|
||||
import { setupRequestMockHandlers } from '@backstage/backend-test-utils';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { PassThrough } from 'stream';
|
||||
import { initRepoAndPush } from '@backstage/plugin-scaffolder-node';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
|
||||
describe('publish:bitbucketServer', () => {
|
||||
const config = new ConfigReader({
|
||||
@@ -60,17 +59,10 @@ describe('publish:bitbucketServer', () => {
|
||||
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
const action = createPublishBitbucketServerAction({ integrations, config });
|
||||
const mockContext = {
|
||||
input: {
|
||||
repoUrl: 'hosted.bitbucket.com?project=project&repo=repo',
|
||||
repoVisibility: 'private' as const,
|
||||
},
|
||||
workspacePath: 'wsp',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
const mockContext = createMockActionContext({
|
||||
repoUrl: 'hosted.bitbucket.com?project=project&repo=repo',
|
||||
repoVisibility: 'private' as const,
|
||||
});
|
||||
const server = setupServer();
|
||||
setupRequestMockHandlers(server);
|
||||
|
||||
|
||||
+9
-17
@@ -32,8 +32,7 @@ import { setupServer } from 'msw/node';
|
||||
import { setupRequestMockHandlers } from '@backstage/backend-test-utils';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { PassThrough } from 'stream';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
|
||||
describe('publish:bitbucketServer:pull-request', () => {
|
||||
const config = new ConfigReader({
|
||||
@@ -62,21 +61,14 @@ describe('publish:bitbucketServer:pull-request', () => {
|
||||
integrations,
|
||||
config,
|
||||
});
|
||||
const mockContext = {
|
||||
input: {
|
||||
repoUrl: 'hosted.bitbucket.com?project=project&repo=repo',
|
||||
title: 'Add Scaffolder actions for Bitbucket Server',
|
||||
description:
|
||||
'I just made a Pull Request that Add Scaffolder actions for Bitbucket Server',
|
||||
targetBranch: 'master',
|
||||
sourceBranch: 'develop',
|
||||
},
|
||||
workspacePath: 'wsp',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
const mockContext = createMockActionContext({
|
||||
repoUrl: 'hosted.bitbucket.com?project=project&repo=repo',
|
||||
title: 'Add Scaffolder actions for Bitbucket Server',
|
||||
description:
|
||||
'I just made a Pull Request that Add Scaffolder actions for Bitbucket Server',
|
||||
targetBranch: 'master',
|
||||
sourceBranch: 'develop',
|
||||
});
|
||||
const responseOfBranches = {
|
||||
size: 3,
|
||||
limit: 25,
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
"devDependencies": {
|
||||
"@backstage/backend-test-utils": "workspace:^",
|
||||
"@backstage/cli": "workspace:^",
|
||||
"@backstage/scaffolder-test-utils": "workspace:^",
|
||||
"msw": "^1.0.0"
|
||||
},
|
||||
"files": [
|
||||
|
||||
@@ -32,12 +32,11 @@ import { setupServer } from 'msw/node';
|
||||
import { setupRequestMockHandlers } from '@backstage/backend-test-utils';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { PassThrough } from 'stream';
|
||||
import { initRepoAndPush } from '@backstage/plugin-scaffolder-node';
|
||||
import yaml from 'yaml';
|
||||
import { sep } from 'path';
|
||||
import { examples } from './bitbucket.examples';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
|
||||
describe('publish:bitbucket', () => {
|
||||
const config = new ConfigReader({
|
||||
@@ -61,17 +60,10 @@ describe('publish:bitbucket', () => {
|
||||
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
const action = createPublishBitbucketAction({ integrations, config });
|
||||
const mockContext = {
|
||||
input: {
|
||||
repoUrl: 'bitbucket.org?workspace=workspace&project=project&repo=repo',
|
||||
repoVisibility: 'private' as const,
|
||||
},
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
const mockContext = createMockActionContext({
|
||||
repoUrl: 'bitbucket.org?workspace=workspace&project=project&repo=repo',
|
||||
repoVisibility: 'private' as const,
|
||||
});
|
||||
const server = setupServer();
|
||||
setupRequestMockHandlers(server);
|
||||
|
||||
|
||||
@@ -31,9 +31,8 @@ import { setupServer } from 'msw/node';
|
||||
import { setupRequestMockHandlers } from '@backstage/backend-test-utils';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { PassThrough } from 'stream';
|
||||
import { initRepoAndPush } from '@backstage/plugin-scaffolder-node';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
|
||||
describe('publish:bitbucket', () => {
|
||||
const config = new ConfigReader({
|
||||
@@ -57,17 +56,10 @@ describe('publish:bitbucket', () => {
|
||||
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
const action = createPublishBitbucketAction({ integrations, config });
|
||||
const mockContext = {
|
||||
input: {
|
||||
repoUrl: 'bitbucket.org?workspace=workspace&project=project&repo=repo',
|
||||
repoVisibility: 'private' as const,
|
||||
},
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
const mockContext = createMockActionContext({
|
||||
repoUrl: 'bitbucket.org?workspace=workspace&project=project&repo=repo',
|
||||
repoVisibility: 'private' as const,
|
||||
});
|
||||
const server = setupServer();
|
||||
setupRequestMockHandlers(server);
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
"devDependencies": {
|
||||
"@backstage/backend-test-utils": "workspace:^",
|
||||
"@backstage/cli": "workspace:^",
|
||||
"@backstage/scaffolder-test-utils": "workspace:^",
|
||||
"msw": "^1.0.0"
|
||||
},
|
||||
"files": [
|
||||
|
||||
+4
-7
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { PassThrough } from 'stream';
|
||||
import { createConfluenceToMarkdownAction } from './confluenceToMarkdown';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { UrlReader } from '@backstage/backend-common';
|
||||
@@ -28,6 +27,7 @@ import { setupServer } from 'msw/node';
|
||||
import { examples } from './confluenceToMarkdown.examples';
|
||||
import yaml from 'yaml';
|
||||
import { ActionContext } from '@backstage/plugin-scaffolder-node';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
|
||||
describe('confluence:transform:markdown examples', () => {
|
||||
const baseUrl = `https://confluence.example.com`;
|
||||
@@ -71,14 +71,11 @@ describe('confluence:transform:markdown examples', () => {
|
||||
}),
|
||||
search: jest.fn(),
|
||||
};
|
||||
mockContext = {
|
||||
input: yaml.parse(examples[0].example).steps[0].input,
|
||||
mockContext = createMockActionContext(
|
||||
yaml.parse(examples[0].example).steps[0].input,
|
||||
workspacePath,
|
||||
logger,
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
);
|
||||
|
||||
mockDir.setContent({ 'workspace/mkdocs.yml': 'File contents' });
|
||||
});
|
||||
|
||||
@@ -8227,6 +8227,7 @@ __metadata:
|
||||
"@backstage/errors": "workspace:^"
|
||||
"@backstage/integration": "workspace:^"
|
||||
"@backstage/plugin-scaffolder-node": "workspace:^"
|
||||
"@backstage/scaffolder-test-utils": "workspace:^"
|
||||
fs-extra: ^11.2.0
|
||||
msw: ^1.0.0
|
||||
node-fetch: ^2.6.7
|
||||
@@ -8246,6 +8247,7 @@ __metadata:
|
||||
"@backstage/errors": "workspace:^"
|
||||
"@backstage/integration": "workspace:^"
|
||||
"@backstage/plugin-scaffolder-node": "workspace:^"
|
||||
"@backstage/scaffolder-test-utils": "workspace:^"
|
||||
fs-extra: ^11.2.0
|
||||
msw: ^1.0.0
|
||||
node-fetch: ^2.6.7
|
||||
@@ -8267,6 +8269,7 @@ __metadata:
|
||||
"@backstage/plugin-scaffolder-backend-module-bitbucket-cloud": "workspace:^"
|
||||
"@backstage/plugin-scaffolder-backend-module-bitbucket-server": "workspace:^"
|
||||
"@backstage/plugin-scaffolder-node": "workspace:^"
|
||||
"@backstage/scaffolder-test-utils": "workspace:^"
|
||||
fs-extra: ^11.2.0
|
||||
msw: ^1.0.0
|
||||
node-fetch: ^2.6.7
|
||||
@@ -8286,6 +8289,7 @@ __metadata:
|
||||
"@backstage/errors": "workspace:^"
|
||||
"@backstage/integration": "workspace:^"
|
||||
"@backstage/plugin-scaffolder-node": "workspace:^"
|
||||
"@backstage/scaffolder-test-utils": "workspace:^"
|
||||
fs-extra: ^11.2.0
|
||||
git-url-parse: ^14.0.0
|
||||
msw: ^1.0.0
|
||||
@@ -9877,6 +9881,7 @@ __metadata:
|
||||
"@backstage/types": "workspace:^"
|
||||
"@testing-library/jest-dom": ^6.0.0
|
||||
"@types/react": "*"
|
||||
winston: ^3.2.1
|
||||
peerDependencies:
|
||||
"@types/jest": "*"
|
||||
languageName: unknown
|
||||
|
||||
Reference in New Issue
Block a user