Skip to content

Commit

Permalink
test(nx-plugin): add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton committed Jul 12, 2024
1 parent ccef3a1 commit dffbad0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
7 changes: 5 additions & 2 deletions packages/nx-plugin/src/executors/internal/cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { CliArgsObject } from '@code-pushup/utils';

export function createCliCommand(
command: string,
args: Record<string, unknown>,
Expand All @@ -8,6 +6,11 @@ export function createCliCommand(
}

type ArgumentValue = number | string | boolean | string[];
export type CliArgsObject<T extends object = Record<string, ArgumentValue>> =
T extends never
? // eslint-disable-next-line @typescript-eslint/naming-convention
Record<string, ArgumentValue | undefined> | { _: string }
: T;
// @TODO import from @code-pushup/utils => get rid of poppins for cjs support
// eslint-disable-next-line sonarjs/cognitive-complexity
export function objectToCliArgs<
Expand Down
9 changes: 8 additions & 1 deletion packages/nx-plugin/src/executors/internal/cli.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { objectToCliArgs } from './cli';
import { createCliCommand, objectToCliArgs } from './cli';

describe('objectToCliArgs', () => {
it('should handle the "_" argument as script', () => {
Expand Down Expand Up @@ -64,3 +64,10 @@ describe('objectToCliArgs', () => {
);
});
});

describe('createCliCommand', () => {
it('should create command out of command name and an object for arguments', () => {
const result = createCliCommand('autorun', { verbose: true });
expect(result).toEqual('npx @code-pushup/cli autorun --verbose');
});
});
6 changes: 4 additions & 2 deletions packages/nx-plugin/src/executors/internal/config.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { afterEach, beforeEach, describe, expect } from 'vitest';
import { toUnixPath } from '@code-pushup/test-utils';
import { ENV } from '../../../mock/fixtures/env';
import { globalConfig, persistConfig, uploadConfig } from './config';
import {toUnixPath} from "@code-pushup/test-utils";

describe('globalConfig', () => {
it('should provide default global verbose options', () => {
Expand Down Expand Up @@ -78,7 +78,9 @@ describe('globalConfig', () => {
),
).toStrictEqual(
expect.objectContaining({
config: expect.stringContaining(toUnixPath('packages/project-root/code-pushup.config.json')),
config: expect.stringContaining(
toUnixPath('packages/project-root/code-pushup.config.json'),
),
}),
);
});
Expand Down

0 comments on commit dffbad0

Please sign in to comment.