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

Commit 353e717

Browse files
authored
fix(nx-distributed-task): undefined args are not filtered out (#52)
1 parent bec6b3d commit 353e717

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

packages/nx-distributed-task/src/app/nx.spec.ts

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,34 @@ import { Exec } from '@e-square/utils/exec';
66
import { logger } from '@e-square/utils/logger';
77
import { assertNxInstalled, nxCommand, nxRunMany } from './nx';
88

9-
jest.mock('@e-square/utils/logger');
109
jest.mock('child_process');
1110
jest.mock('fs');
11+
jest.mock('@e-square/utils/logger');
1212

1313
describe('nx', () => {
14+
let exec: Exec;
15+
16+
beforeEach(() => {
17+
exec = new Exec(jest.fn());
18+
jest.spyOn(exec, 'build').mockReturnValue(() => Promise.resolve(''));
19+
jest.spyOn(exec, 'withCommand');
20+
jest.spyOn(exec, 'withArgs');
21+
jest.spyOn(exec, 'withOptions');
22+
});
23+
1424
describe('assertNxInstalled', () => {
1525
it('should fail to assert and throw error', async () => {
16-
const exec = new Exec(jest.fn().mockResolvedValueOnce(0));
1726
await expect(assertNxInstalled(exec)).rejects.toThrow("Couldn't find Nx binary, Have you run npm/yarn install?");
1827
});
1928

2029
it('should success assertion', async () => {
21-
const exec = new Exec(
22-
jest.fn().mockImplementation(async (_, __, opts) => {
23-
opts.listeners.stdout('test');
24-
return Promise.resolve(0);
25-
})
26-
);
30+
jest.spyOn(exec, 'build').mockReturnValue(() => Promise.resolve('test'));
31+
2732
await expect(assertNxInstalled(exec)).resolves.toBeUndefined();
2833
});
2934
});
3035

3136
describe('exec nx', () => {
32-
let exec: Exec;
33-
34-
beforeEach(() => {
35-
exec = new Exec(jest.fn());
36-
jest.spyOn(exec, 'build').mockReturnValue(() => Promise.resolve(''));
37-
jest.spyOn(exec, 'withCommand');
38-
jest.spyOn(exec, 'withArgs');
39-
jest.spyOn(exec, 'withOptions');
40-
});
41-
4237
const cases: [pm.PackageManager, string, string][] = [
4338
['npm', '6.8.0', 'npx -p @nrwl/cli'],
4439
['npm', '7.0.0', 'npx --no -p @nrwl/cli'],
@@ -67,6 +62,23 @@ describe('nx', () => {
6762
expect(exec.withArgs).toHaveBeenCalledWith('--target=build');
6863
});
6964

65+
it('should not parse withDeps when nx version is >= 14', async () => {
66+
jest.spyOn(exec, 'build').mockReturnValueOnce(() => Promise.resolve('14.0.0'));
67+
68+
await expect(
69+
nxCommand(
70+
'test',
71+
{
72+
target: 'build',
73+
withDeps: true,
74+
'with-deps': true,
75+
},
76+
exec
77+
)
78+
).resolves.toBe('');
79+
expect(exec.withArgs).toHaveBeenCalledWith('--target=build');
80+
});
81+
7082
it('should call nxRunMany', async () => {
7183
await expect(
7284
nxRunMany(

packages/nx-distributed-task/src/app/nx.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export async function nxCommand(nxCommand: string, args: NxArgs, exec: Exec): Pr
3030

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

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

0 commit comments

Comments
 (0)