Skip to content

Commit

Permalink
fix(dotnet): update args handling for dotnet format (#678)
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder authored Sep 20, 2023
1 parent 2310556 commit 772303e
Show file tree
Hide file tree
Showing 8 changed files with 402 additions and 22 deletions.
4 changes: 4 additions & 0 deletions e2e/core-e2e/tests/nx-dotnet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ describe('nx-dotnet e2e', () => {
initializeGitRepo(e2eDir);
}, 1500000);

afterEach(() => {
runNxCommand('reset');
});

it('should initialize workspace build customization', async () => {
await runNxCommandAsync(`generate @nx-dotnet/core:init`);

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"ts-node": "ts-node",
"rimraf": "rimraf",
"preinstall": "node ./tools/scripts/hooks/preinstall.js",
"postinstall": "dotnet tool restore",
"documentation:check": "ts-node ./tools/scripts/hooks/documentation.check.ts",
"documentation": "nx g @nx-dotnet/nxdoc:generate-docs",
"publish-dev": "ts-node tools/scripts/publish-dev",
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/graph/process-project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ function visitProject(
try {
projectFile = getProjectFileForNxProjectSync(project);
} catch (e) {
if (process.env['NX_VERBOSE_LOGGING'] === 'true') {
console.error(e);
}
// not a .NET project
}
if (projectFile !== null) {
getDependantProjectsForNxProject(
Expand Down
294 changes: 294 additions & 0 deletions packages/dotnet/src/lib/core/dotnet.client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,298 @@ ASP.NET Core gRPC Service grpc [C#]
}
});
});

describe('format', () => {
it('should call subcommands properly when on .NET 6 and passing --fixWhitespace', () => {
const dotnetClient = new DotNetClient(mockDotnetFactory('6.0.0'));
const spy = jest
.spyOn(dotnetClient, 'logAndExecute')
.mockImplementation(() => ({}));
dotnetClient.format('my-project', {
fixWhitespace: false,
});
expect(spy).toHaveBeenCalledTimes(2);
expect(spy.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Array [
"format",
"style",
"my-project",
],
],
Array [
Array [
"format",
"analyzers",
"my-project",
],
],
]
`);
});

it('should call subcommands properly when on .NET 6 and passing --fixAnalyzers', () => {
const dotnetClient = new DotNetClient(mockDotnetFactory('6.0.0'));
const spy = jest
.spyOn(dotnetClient, 'logAndExecute')
.mockImplementation(() => ({}));
dotnetClient.format('my-project', {
fixAnalyzers: false,
});
expect(spy).toHaveBeenCalledTimes(2);
expect(spy.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Array [
"format",
"whitespace",
"my-project",
],
],
Array [
Array [
"format",
"style",
"my-project",
],
],
]
`);
});

it('should call subcommands properly when on .NET 6 and passing --fixAnalyzers severity', () => {
const dotnetClient = new DotNetClient(mockDotnetFactory('6.0.0'));
const spy = jest
.spyOn(dotnetClient, 'logAndExecute')
.mockImplementation(() => ({}));
dotnetClient.format('my-project', {
fixAnalyzers: 'warn',
});
expect(spy).toHaveBeenCalledTimes(3);
expect(spy.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Array [
"format",
"whitespace",
"my-project",
],
],
Array [
Array [
"format",
"style",
"my-project",
],
],
Array [
Array [
"format",
"analyzers",
"my-project",
"--severity",
"warn",
],
],
]
`);
});

it('should call subcommands properly when on .NET 6 and passing --fixStyle', () => {
const dotnetClient = new DotNetClient(mockDotnetFactory('6.0.0'));
const spy = jest
.spyOn(dotnetClient, 'logAndExecute')
.mockImplementation(() => ({}));
dotnetClient.format('my-project', {
fixStyle: false,
});
expect(spy).toHaveBeenCalledTimes(2);
expect(spy.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Array [
"format",
"whitespace",
"my-project",
],
],
Array [
Array [
"format",
"analyzers",
"my-project",
],
],
]
`);
});

it('should call subcommands properly when on .NET 6 and passing --fixAnalyzers severity', () => {
const dotnetClient = new DotNetClient(mockDotnetFactory('6.0.0'));
const spy = jest
.spyOn(dotnetClient, 'logAndExecute')
.mockImplementation(() => ({}));
dotnetClient.format('my-project', {
fixStyle: 'warn',
});
expect(spy).toHaveBeenCalledTimes(3);
expect(spy.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Array [
"format",
"whitespace",
"my-project",
],
],
Array [
Array [
"format",
"style",
"my-project",
"--severity",
"warn",
],
],
Array [
Array [
"format",
"analyzers",
"my-project",
],
],
]
`);
});

it('should not pass `check` flag when on .NET 6', () => {
const dotnetClient = new DotNetClient(mockDotnetFactory('6.0.0'));
const spy = jest
.spyOn(dotnetClient, 'logAndExecute')
.mockImplementation(() => ({}));
dotnetClient.format('my-project', {
check: true,
});
expect(spy).toHaveBeenCalledTimes(1);
expect(spy.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Array [
"format",
"my-project",
"--verify-no-changes",
],
],
]
`);
});

it('should call single command when on .NET 6 and not passing any options', () => {
const dotnetClient = new DotNetClient(mockDotnetFactory('6.0.0'));
const spy = jest
.spyOn(dotnetClient, 'logAndExecute')
.mockImplementation(() => ({}));
dotnetClient.format('my-project');
expect(spy).toHaveBeenCalledTimes(1);
expect(spy.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Array [
"format",
"my-project",
],
],
]
`);
});

it('should call single command when on .NET 5 and not passing any options', () => {
const dotnetClient = new DotNetClient(mockDotnetFactory('5.0.0'));
const spy = jest
.spyOn(dotnetClient, 'logAndExecute')
.mockImplementation(() => ({}));
dotnetClient.format('my-project');
expect(spy).toHaveBeenCalledTimes(1);
expect(spy.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Array [
"format",
"my-project",
],
],
]
`);
});

it('should call single command when on .NET 5 if passing --fixWhitespace', () => {
const dotnetClient = new DotNetClient(mockDotnetFactory('5.0.0'));
const spy = jest
.spyOn(dotnetClient, 'logAndExecute')
.mockImplementation(() => ({}));
dotnetClient.format('my-project', {
fixWhitespace: false,
});
expect(spy).toHaveBeenCalledTimes(1);
expect(spy.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Array [
"format",
"my-project",
"--fix-whitespace",
"false",
],
],
]
`);
});

it('should call single command when on .NET 5 if passing --fixStyle', () => {
const dotnetClient = new DotNetClient(mockDotnetFactory('5.0.0'));
const spy = jest
.spyOn(dotnetClient, 'logAndExecute')
.mockImplementation(() => ({}));
dotnetClient.format('my-project', {
fixStyle: false,
});
expect(spy).toHaveBeenCalledTimes(1);
expect(spy.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Array [
"format",
"my-project",
"--fix-style",
"false",
],
],
]
`);
});

it('should call single command when on .NET 5 if passing --fixAnalyzers', () => {
const dotnetClient = new DotNetClient(mockDotnetFactory('5.0.0'));
const spy = jest
.spyOn(dotnetClient, 'logAndExecute')
.mockImplementation(() => ({}));
dotnetClient.format('my-project', {
fixAnalyzers: false,
});
expect(spy).toHaveBeenCalledTimes(1);
expect(spy.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Array [
"format",
"my-project",
"--fix-analyzers",
"false",
],
],
]
`);
});
});
});
Loading

0 comments on commit 772303e

Please sign in to comment.