From 95126b10339cb2a6baa7da7e9e251e676de79f96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Sat, 16 Sep 2023 10:46:03 +0200 Subject: [PATCH] attempt at fixing some windows test failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .../src/sources/ConfigSources.test.ts | 21 ++++--- packages/repo-tools/src/lib/paths.test.ts | 57 +++++++++++-------- .../publish/bitbucket.examples.test.ts | 3 +- 3 files changed, 47 insertions(+), 34 deletions(-) diff --git a/packages/config-loader/src/sources/ConfigSources.test.ts b/packages/config-loader/src/sources/ConfigSources.test.ts index 190515aa12..cbdb405cb6 100644 --- a/packages/config-loader/src/sources/ConfigSources.test.ts +++ b/packages/config-loader/src/sources/ConfigSources.test.ts @@ -15,6 +15,7 @@ */ import fs from 'fs-extra'; +import { resolve as resolvePath } from 'path'; import { ConfigSources } from './ConfigSources'; import { ConfigSource } from './types'; import { MutableConfigSource } from './MutableConfigSource'; @@ -41,6 +42,8 @@ function mergeSources(source: ConfigSource): ConfigSource[] { ] as ConfigSource[]; } +const root = resolvePath('/'); + describe('ConfigSources', () => { it('should parse args', () => { expect(ConfigSources.parseArgs([])).toEqual([]); @@ -70,7 +73,7 @@ describe('ConfigSources', () => { mergeSources( ConfigSources.defaultForTargets({ rootDir: '/', targets: [] }), ), - ).toEqual([{ name: 'FileConfigSource', path: '/app-config.yaml' }]); + ).toEqual([{ name: 'FileConfigSource', path: `${root}app-config.yaml` }]); const fsSpy = jest.spyOn(fs, 'pathExistsSync').mockReturnValue(true); expect( @@ -78,8 +81,8 @@ describe('ConfigSources', () => { ConfigSources.defaultForTargets({ rootDir: '/', targets: [] }), ), ).toEqual([ - { name: 'FileConfigSource', path: '/app-config.yaml' }, - { name: 'FileConfigSource', path: '/app-config.local.yaml' }, + { name: 'FileConfigSource', path: `${root}app-config.yaml` }, + { name: 'FileConfigSource', path: `${root}app-config.local.yaml` }, ]); fsSpy.mockRestore(); @@ -90,7 +93,7 @@ describe('ConfigSources', () => { targets: [{ type: 'path', target: '/config.yaml' }], }), ), - ).toEqual([{ name: 'FileConfigSource', path: '/config.yaml' }]); + ).toEqual([{ name: 'FileConfigSource', path: `${root}config.yaml` }]); const subFunc = async () => undefined; expect( @@ -104,7 +107,7 @@ describe('ConfigSources', () => { ).toEqual([ { name: 'FileConfigSource', - path: '/config.yaml', + path: `${root}config.yaml`, substitutionFunc: subFunc, }, ]); @@ -156,7 +159,7 @@ describe('ConfigSources', () => { }), ), ).toEqual([ - { name: 'FileConfigSource', path: '/app-config.yaml' }, + { name: 'FileConfigSource', path: `${root}app-config.yaml` }, { name: 'EnvConfigSource', env: { HOME: '/' } }, ]); @@ -190,9 +193,9 @@ describe('ConfigSources', () => { ]), ), ).toEqual([ - { name: 'FileConfigSource', path: '/a.yaml' }, - { name: 'FileConfigSource', path: '/b.yaml' }, - { name: 'FileConfigSource', path: '/c.yaml' }, + { name: 'FileConfigSource', path: `${root}a.yaml` }, + { name: 'FileConfigSource', path: `${root}b.yaml` }, + { name: 'FileConfigSource', path: `${root}c.yaml` }, ]); }); diff --git a/packages/repo-tools/src/lib/paths.test.ts b/packages/repo-tools/src/lib/paths.test.ts index bec93617ff..1ccab92d61 100644 --- a/packages/repo-tools/src/lib/paths.test.ts +++ b/packages/repo-tools/src/lib/paths.test.ts @@ -14,76 +14,85 @@ * limitations under the License. */ -import { resolve as resolvePath } from 'path'; +import { resolve as resolvePath, sep } from 'path'; import { resolvePackagePaths } from './paths'; describe('resolvePackages', () => { it('should return all packages', async () => { const paths = await resolvePackagePaths(); expect(paths.length).toBeGreaterThan(10); - expect(paths).toContain('packages/cli'); - expect(paths).toContain('packages/repo-tools'); + expect(paths).toContain(`packages${sep}cli`); + expect(paths).toContain(`packages${sep}repo-tools`); }); it('should filter by path', async () => { await expect( - resolvePackagePaths({ paths: ['packages/repo-tools'] }), - ).resolves.toEqual(['packages/repo-tools']); + resolvePackagePaths({ paths: [`packages${sep}repo-tools`] }), + ).resolves.toEqual([`packages${sep}repo-tools`]); await expect( - resolvePackagePaths({ paths: [resolvePath('packages/repo-tools')] }), - ).resolves.toEqual(['packages/repo-tools']); + resolvePackagePaths({ paths: [resolvePath('packages', 'repo-tools')] }), + ).resolves.toEqual([`packages${sep}repo-tools`]); await expect( resolvePackagePaths({ - paths: [resolvePath('packages/repo-tools/package.json')], + paths: [resolvePath('packages', 'repo-tools', 'package.json')], }), - ).resolves.toEqual(['packages/repo-tools']); + ).resolves.toEqual([`packages${sep}repo-tools`]); await expect( resolvePackagePaths({ - paths: ['packages/repo-tools/src/some/made/up/file.ts'], + paths: [ + `packages${sep}repo-tools${sep}src${sep}some${sep}made${sep}up${sep}file.ts`, + ], }), - ).resolves.toEqual(['packages/repo-tools']); + ).resolves.toEqual([`packages${sep}repo-tools`]); await expect( resolvePackagePaths({ - paths: ['packages/repo-tools/src/some/made/up/file.ts', 'packages/cli'], + paths: [ + `packages${sep}repo-tools${sep}src${sep}some${sep}made${sep}up${sep}file.ts`, + `packages${sep}cli`, + ], }), - ).resolves.toEqual(['packages/cli', 'packages/repo-tools']); + ).resolves.toEqual([`packages${sep}cli`, `packages${sep}repo-tools`]); }); it('should filter with include', async () => { const allPackages = await resolvePackagePaths(); const pluginPackages = await resolvePackagePaths({ - include: ['plugins/*'], + include: [`plugins${sep}*`], }); expect(allPackages.length).toBeGreaterThan(10); expect(pluginPackages.length).toBeGreaterThan(10); expect(allPackages.length).toBeGreaterThan(pluginPackages.length); - expect(pluginPackages).toContain('plugins/catalog'); + expect(pluginPackages).toContain(`plugins${sep}catalog`); await expect( - resolvePackagePaths({ include: ['packages/repo-t??ls'] }), - ).resolves.toEqual(['packages/repo-tools']); + resolvePackagePaths({ include: [`packages${sep}repo-t??ls`] }), + ).resolves.toEqual([`packages${sep}repo-tools`]); }); it('should filter with exclude', async () => { const nonPluginPackages = await resolvePackagePaths({ - exclude: ['plugins/*'], + exclude: [`plugins${sep}*`], }); - expect(nonPluginPackages).toContain('packages/app'); - expect(nonPluginPackages).not.toContain('plugins/catalog'); + expect(nonPluginPackages).toContain(`packages${sep}app`); + expect(nonPluginPackages).not.toContain(`plugins${sep}catalog`); }); it('should combine all options', async () => { await expect( resolvePackagePaths({ - paths: ['packages/cli', 'packages/backend', 'packages/app'], - include: ['packages/app'], - exclude: ['packages/back*'], + paths: [ + `packages${sep}cli`, + `packages${sep}backend`, + `packages${sep}app`, + ], + include: [`packages${sep}app`], + exclude: [`packages${sep}back*`], }), - ).resolves.toEqual(['packages/app']); + ).resolves.toEqual([`packages${sep}app`]); }); }); diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.examples.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.examples.test.ts index 2514c44637..a1564d0498 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.examples.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.examples.test.ts @@ -35,6 +35,7 @@ import { getVoidLogger } from '@backstage/backend-common'; import { PassThrough } from 'stream'; import { initRepoAndPush } from '../helpers'; import yaml from 'yaml'; +import { sep } from 'path'; import { examples } from './bitbucket.examples'; describe('publish:bitbucket', () => { @@ -189,7 +190,7 @@ describe('publish:bitbucket', () => { input: yaml.parse(examples[4].example).steps[0].input, }); expect(initRepoAndPush).toHaveBeenCalledWith({ - dir: `${mockContext.workspacePath}/repoRoot`, + dir: `${mockContext.workspacePath}${sep}repoRoot`, remoteUrl: 'https://bitbucket.org/workspace/cloneurl', auth: { username: 'x-token-auth', password: 'tokenlols' }, logger: mockContext.logger,