diff --git a/packages/backend-common/src/reading/AwsS3UrlReader.test.ts b/packages/backend-common/src/reading/AwsS3UrlReader.test.ts index 80f59fe182..0bc0e4f97f 100644 --- a/packages/backend-common/src/reading/AwsS3UrlReader.test.ts +++ b/packages/backend-common/src/reading/AwsS3UrlReader.test.ts @@ -135,13 +135,7 @@ describe('AwsS3UrlReader', () => { 'getObject', Buffer.from( require('fs').readFileSync( - path.resolve( - 'src', - 'reading', - '__fixtures__', - 'awsS3', - 'awsS3-mock-object.yaml', - ), + path.resolve(__dirname, '__fixtures__/awsS3/awsS3-mock-object.yaml'), ), ), ); @@ -187,13 +181,7 @@ describe('AwsS3UrlReader', () => { 'getObject', Buffer.from( require('fs').readFileSync( - path.resolve( - 'src', - 'reading', - '__fixtures__', - 'awsS3', - 'awsS3-mock-object.yaml', - ), + path.resolve(__dirname, '__fixtures__/awsS3/awsS3-mock-object.yaml'), ), ), ); @@ -249,13 +237,7 @@ describe('AwsS3UrlReader', () => { 'getObject', Buffer.from( require('fs').readFileSync( - path.resolve( - 'src', - 'reading', - '__fixtures__', - 'awsS3', - 'awsS3-mock-object.yaml', - ), + path.resolve(__dirname, '__fixtures__/awsS3/awsS3-mock-object.yaml'), ), ), ); diff --git a/packages/backend-common/src/reading/AzureUrlReader.test.ts b/packages/backend-common/src/reading/AzureUrlReader.test.ts index e014fa2e75..59968a18e9 100644 --- a/packages/backend-common/src/reading/AzureUrlReader.test.ts +++ b/packages/backend-common/src/reading/AzureUrlReader.test.ts @@ -152,7 +152,7 @@ describe('AzureUrlReader', () => { describe('readTree', () => { const repoBuffer = fs.readFileSync( - path.resolve('src', 'reading', '__fixtures__', 'mock-main.zip'), + path.resolve(__dirname, '__fixtures__/mock-main.zip'), ); const processor = new AzureUrlReader( @@ -264,7 +264,7 @@ describe('AzureUrlReader', () => { describe('search', () => { const repoBuffer = fs.readFileSync( - path.resolve('src', 'reading', '__fixtures__', 'mock-main.zip'), + path.resolve(__dirname, '__fixtures__/mock-main.zip'), ); const processor = new AzureUrlReader( diff --git a/packages/backend-common/src/reading/BitbucketUrlReader.test.ts b/packages/backend-common/src/reading/BitbucketUrlReader.test.ts index ef61452163..5bbf3725ea 100644 --- a/packages/backend-common/src/reading/BitbucketUrlReader.test.ts +++ b/packages/backend-common/src/reading/BitbucketUrlReader.test.ts @@ -104,20 +104,13 @@ describe('BitbucketUrlReader', () => { describe('readTree', () => { const repoBuffer = fs.readFileSync( path.resolve( - 'src', - 'reading', - '__fixtures__', - 'bitbucket-repo-with-commit-hash.tar.gz', + __dirname, + '__fixtures__/bitbucket-repo-with-commit-hash.tar.gz', ), ); const privateBitbucketRepoBuffer = fs.readFileSync( - path.resolve( - 'src', - 'reading', - '__fixtures__', - 'bitbucket-server-repo.tar.gz', - ), + path.resolve(__dirname, '__fixtures__/bitbucket-server-repo.tar.gz'), ); beforeEach(() => { @@ -298,10 +291,8 @@ describe('BitbucketUrlReader', () => { describe('search hosted', () => { const repoBuffer = fs.readFileSync( path.resolve( - 'src', - 'reading', - '__fixtures__', - 'bitbucket-repo-with-commit-hash.tar.gz', + __dirname, + '__fixtures__/bitbucket-repo-with-commit-hash.tar.gz', ), ); @@ -386,12 +377,7 @@ describe('BitbucketUrlReader', () => { describe('search private', () => { const privateBitbucketRepoBuffer = fs.readFileSync( - path.resolve( - 'src', - 'reading', - '__fixtures__', - 'bitbucket-server-repo.tar.gz', - ), + path.resolve(__dirname, '__fixtures__/bitbucket-server-repo.tar.gz'), ); beforeEach(() => { diff --git a/packages/backend-common/src/reading/GithubUrlReader.test.ts b/packages/backend-common/src/reading/GithubUrlReader.test.ts index f9717a862a..e70444cf2c 100644 --- a/packages/backend-common/src/reading/GithubUrlReader.test.ts +++ b/packages/backend-common/src/reading/GithubUrlReader.test.ts @@ -254,12 +254,7 @@ describe('GithubUrlReader', () => { describe('readTree', () => { const repoBuffer = fs.readFileSync( - path.resolve( - 'src', - 'reading', - '__fixtures__', - 'backstage-mock-etag123.tar.gz', - ), + path.resolve(__dirname, '__fixtures__/backstage-mock-etag123.tar.gz'), ); const reposGithubApiResponse = { @@ -540,12 +535,7 @@ describe('GithubUrlReader', () => { describe('search', () => { const repoBuffer = fs.readFileSync( - path.resolve( - 'src', - 'reading', - '__fixtures__', - 'backstage-mock-etag123.tar.gz', - ), + path.resolve(__dirname, '__fixtures__/backstage-mock-etag123.tar.gz'), ); const githubTreeContents: GhTreeResponse['tree'] = [ diff --git a/packages/backend-common/src/reading/GitlabUrlReader.test.ts b/packages/backend-common/src/reading/GitlabUrlReader.test.ts index 51b211e698..331150bde3 100644 --- a/packages/backend-common/src/reading/GitlabUrlReader.test.ts +++ b/packages/backend-common/src/reading/GitlabUrlReader.test.ts @@ -223,7 +223,7 @@ describe('GitlabUrlReader', () => { describe('readTree', () => { const archiveBuffer = fs.readFileSync( - path.resolve('src', 'reading', '__fixtures__', 'gitlab-archive.tar.gz'), + path.resolve(__dirname, '__fixtures__/gitlab-archive.tar.gz'), ); const projectGitlabApiResponse = { @@ -495,7 +495,7 @@ describe('GitlabUrlReader', () => { describe('search', () => { const archiveBuffer = fs.readFileSync( - path.resolve('src', 'reading', '__fixtures__', 'gitlab-archive.tar.gz'), + path.resolve(__dirname, '__fixtures__/gitlab-archive.tar.gz'), ); const projectGitlabApiResponse = { diff --git a/packages/cli-common/src/paths.test.ts b/packages/cli-common/src/paths.test.ts index 894060f2e8..5c1cf8af08 100644 --- a/packages/cli-common/src/paths.test.ts +++ b/packages/cli-common/src/paths.test.ts @@ -46,6 +46,8 @@ describe('paths', () => { const dir = resolvePath(__dirname, '..'); const root = resolvePath(__dirname, '../../..'); + jest.spyOn(process, 'cwd').mockReturnValue(dir); + const paths = findPaths(__dirname); expect(paths.ownDir).toBe(dir); diff --git a/packages/integration/src/azure/config.test.ts b/packages/integration/src/azure/config.test.ts index 385086fbcf..353065a030 100644 --- a/packages/integration/src/azure/config.test.ts +++ b/packages/integration/src/azure/config.test.ts @@ -31,15 +31,17 @@ describe('readAzureIntegrationConfig', () => { data: Partial, ): Promise { const fullSchema = await loadConfigSchema({ - dependencies: [require('../../package.json').name], + dependencies: ['@backstage/integration'], }); const serializedSchema = fullSchema.serialize() as { - schemas: { path: string }[]; + schemas: { value: { properties?: { integrations?: object } } }[]; }; const schema = await loadConfigSchema({ serialized: { - ...serializedSchema, // grab the schema from this package only - schemas: serializedSchema.schemas.filter(s => s.path === 'config.d.ts'), + ...serializedSchema, // only include schemas that apply to integrations + schemas: serializedSchema.schemas.filter( + s => s.value?.properties?.integrations, + ), }, }); const processed = schema.process( diff --git a/packages/integration/src/bitbucket/config.test.ts b/packages/integration/src/bitbucket/config.test.ts index b887566e35..5440b174c8 100644 --- a/packages/integration/src/bitbucket/config.test.ts +++ b/packages/integration/src/bitbucket/config.test.ts @@ -31,15 +31,17 @@ describe('readBitbucketIntegrationConfig', () => { data: Partial, ): Promise { const fullSchema = await loadConfigSchema({ - dependencies: [require('../../package.json').name], + dependencies: ['@backstage/integration'], }); const serializedSchema = fullSchema.serialize() as { - schemas: { path: string }[]; + schemas: { value: { properties?: { integrations?: object } } }[]; }; const schema = await loadConfigSchema({ serialized: { - ...serializedSchema, // grab the schema from this package only - schemas: serializedSchema.schemas.filter(s => s.path === 'config.d.ts'), + ...serializedSchema, // only include schemas that apply to integrations + schemas: serializedSchema.schemas.filter( + s => s.value?.properties?.integrations, + ), }, }); const processed = schema.process( diff --git a/packages/integration/src/github/config.test.ts b/packages/integration/src/github/config.test.ts index eb084b14a9..73efb4f81a 100644 --- a/packages/integration/src/github/config.test.ts +++ b/packages/integration/src/github/config.test.ts @@ -31,15 +31,17 @@ describe('readGitHubIntegrationConfig', () => { data: Partial, ): Promise { const fullSchema = await loadConfigSchema({ - dependencies: [require('../../package.json').name], + dependencies: ['@backstage/integration'], }); const serializedSchema = fullSchema.serialize() as { - schemas: { path: string }[]; + schemas: { value: { properties?: { integrations?: object } } }[]; }; const schema = await loadConfigSchema({ serialized: { - ...serializedSchema, // grab the schema from this package only - schemas: serializedSchema.schemas.filter(s => s.path === 'config.d.ts'), + ...serializedSchema, // only include schemas that apply to integrations + schemas: serializedSchema.schemas.filter( + s => s.value?.properties?.integrations, + ), }, }); const processed = schema.process( diff --git a/packages/integration/src/gitlab/config.test.ts b/packages/integration/src/gitlab/config.test.ts index 1308704e9d..db03285206 100644 --- a/packages/integration/src/gitlab/config.test.ts +++ b/packages/integration/src/gitlab/config.test.ts @@ -31,15 +31,17 @@ describe('readGitLabIntegrationConfig', () => { data: Partial, ): Promise { const fullSchema = await loadConfigSchema({ - dependencies: [require('../../package.json').name], + dependencies: ['@backstage/integration'], }); const serializedSchema = fullSchema.serialize() as { - schemas: { path: string }[]; + schemas: { value: { properties?: { integrations?: object } } }[]; }; const schema = await loadConfigSchema({ serialized: { - ...serializedSchema, // grab the schema from this package only - schemas: serializedSchema.schemas.filter(s => s.path === 'config.d.ts'), + ...serializedSchema, // only include schemas that apply to integrations + schemas: serializedSchema.schemas.filter( + s => s.value?.properties?.integrations, + ), }, }); const processed = schema.process( diff --git a/plugins/catalog-backend/src/ingestion/processors/AwsS3DiscoveryProcessor.test.ts b/plugins/catalog-backend/src/ingestion/processors/AwsS3DiscoveryProcessor.test.ts index 435ad368c7..064a2ad724 100644 --- a/plugins/catalog-backend/src/ingestion/processors/AwsS3DiscoveryProcessor.test.ts +++ b/plugins/catalog-backend/src/ingestion/processors/AwsS3DiscoveryProcessor.test.ts @@ -37,13 +37,8 @@ AWSMock.mock( Buffer.from( require('fs').readFileSync( path.resolve( - 'src', - 'ingestion', - 'processors', - '__fixtures__', - 'fileReaderProcessor', - 'awsS3', - 'awsS3-mock-object.txt', + __dirname, + '__fixtures__/fileReaderProcessor/awsS3/awsS3-mock-object.txt', ), ), ), diff --git a/plugins/catalog-backend/src/ingestion/processors/FileReaderProcessor.test.ts b/plugins/catalog-backend/src/ingestion/processors/FileReaderProcessor.test.ts index 41c7e4f732..8a5f202e5e 100644 --- a/plugins/catalog-backend/src/ingestion/processors/FileReaderProcessor.test.ts +++ b/plugins/catalog-backend/src/ingestion/processors/FileReaderProcessor.test.ts @@ -23,13 +23,7 @@ import { import path from 'path'; describe('FileReaderProcessor', () => { - const fixturesRoot = path.join( - 'src', - 'ingestion', - 'processors', - '__fixtures__', - 'fileReaderProcessor', - ); + const fixturesRoot = path.join(__dirname, '__fixtures__/fileReaderProcessor'); it('should load from file', async () => { const processor = new FileReaderProcessor(); diff --git a/plugins/catalog-backend/src/next/ConfigLocationEntityProvider.test.ts b/plugins/catalog-backend/src/next/ConfigLocationEntityProvider.test.ts index ef3e47eb8b..0663ad8d04 100644 --- a/plugins/catalog-backend/src/next/ConfigLocationEntityProvider.test.ts +++ b/plugins/catalog-backend/src/next/ConfigLocationEntityProvider.test.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import { resolvePackagePath } from '@backstage/backend-common'; import { ConfigReader } from '@backstage/config'; import path from 'path'; import { ConfigLocationEntityProvider } from './ConfigLocationEntityProvider'; @@ -44,10 +43,7 @@ describe('ConfigLocationEntityProvider', () => { { entity: expect.objectContaining({ spec: { - target: path.join( - resolvePackagePath('@backstage/plugin-catalog-backend'), - './lols.yaml', - ), + target: path.join(process.cwd(), 'lols.yaml'), type: 'file', }, }), diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.test.ts index d676af56ca..4befec5a81 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.test.ts @@ -15,10 +15,14 @@ */ import os from 'os'; -import { join as joinPath, resolve as resolvePath } from 'path'; +import { join as joinPath } from 'path'; import fs from 'fs-extra'; import mockFs from 'mock-fs'; -import { getVoidLogger, UrlReader } from '@backstage/backend-common'; +import { + getVoidLogger, + resolvePackagePath, + UrlReader, +} from '@backstage/backend-common'; import { ScmIntegrations } from '@backstage/integration'; import { PassThrough } from 'stream'; import { fetchContents } from './helpers'; @@ -30,9 +34,9 @@ jest.mock('./helpers', () => ({ })); const aBinaryFile = fs.readFileSync( - resolvePath( - 'src', - '../fixtures/test-nested-template/public/react-logo192.png', + resolvePackagePath( + '@backstage/plugin-scaffolder-backend', + 'fixtures/test-nested-template/public/react-logo192.png', ), );