Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

fix(nx-distributed-task): undefined args are not filtered out #52

Merged
merged 1 commit into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 30 additions & 18 deletions packages/nx-distributed-task/src/app/nx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,34 @@ import { Exec } from '@e-square/utils/exec';
import { logger } from '@e-square/utils/logger';
import { assertNxInstalled, nxCommand, nxRunMany } from './nx';

jest.mock('@e-square/utils/logger');
jest.mock('child_process');
jest.mock('fs');
jest.mock('@e-square/utils/logger');

describe('nx', () => {
let exec: Exec;

beforeEach(() => {
exec = new Exec(jest.fn());
jest.spyOn(exec, 'build').mockReturnValue(() => Promise.resolve(''));
jest.spyOn(exec, 'withCommand');
jest.spyOn(exec, 'withArgs');
jest.spyOn(exec, 'withOptions');
});

describe('assertNxInstalled', () => {
it('should fail to assert and throw error', async () => {
const exec = new Exec(jest.fn().mockResolvedValueOnce(0));
await expect(assertNxInstalled(exec)).rejects.toThrow("Couldn't find Nx binary, Have you run npm/yarn install?");
});

it('should success assertion', async () => {
const exec = new Exec(
jest.fn().mockImplementation(async (_, __, opts) => {
opts.listeners.stdout('test');
return Promise.resolve(0);
})
);
jest.spyOn(exec, 'build').mockReturnValue(() => Promise.resolve('test'));

await expect(assertNxInstalled(exec)).resolves.toBeUndefined();
});
});

describe('exec nx', () => {
let exec: Exec;

beforeEach(() => {
exec = new Exec(jest.fn());
jest.spyOn(exec, 'build').mockReturnValue(() => Promise.resolve(''));
jest.spyOn(exec, 'withCommand');
jest.spyOn(exec, 'withArgs');
jest.spyOn(exec, 'withOptions');
});

const cases: [pm.PackageManager, string, string][] = [
['npm', '6.8.0', 'npx -p @nrwl/cli'],
['npm', '7.0.0', 'npx --no -p @nrwl/cli'],
Expand Down Expand Up @@ -67,6 +62,23 @@ describe('nx', () => {
expect(exec.withArgs).toHaveBeenCalledWith('--target=build');
});

it('should not parse withDeps when nx version is >= 14', async () => {
jest.spyOn(exec, 'build').mockReturnValueOnce(() => Promise.resolve('14.0.0'));

await expect(
nxCommand(
'test',
{
target: 'build',
withDeps: true,
'with-deps': true,
},
exec
)
).resolves.toBe('');
expect(exec.withArgs).toHaveBeenCalledWith('--target=build');
});

it('should call nxRunMany', async () => {
await expect(
nxRunMany(
Expand Down
4 changes: 2 additions & 2 deletions packages/nx-distributed-task/src/app/nx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export async function nxCommand(nxCommand: string, args: NxArgs, exec: Exec): Pr

// override with-deps because it was removed in NX 14
if (nxMajorVersion >= '14') {
args.withDeps = undefined;
args['with-deps'] = undefined;
delete args.withDeps;
delete args['with-deps'];
}

const [pmMajorVersion] = getPackageManagerVersion().split('.');
Expand Down