attempt at fixing some windows test failures

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2023-09-16 10:46:03 +02:00
parent 3ee520091b
commit 95126b1033
3 changed files with 47 additions and 34 deletions
@@ -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` },
]);
});
+33 -24
View File
@@ -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`]);
});
});
@@ -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,