-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): update-swagger executor always reinstalls tool (#757)
- Loading branch information
1 parent
12d89ac
commit 63cf4b4
Showing
9 changed files
with
247 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/utils/src/lib/models/dotnet-tools-manifest.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export interface DotnetToolsManifestV1 { | ||
version: 1; | ||
isRoot: boolean; | ||
tools: { | ||
[key: string]: { | ||
version: string; | ||
commands: string[]; | ||
}; | ||
}; | ||
} | ||
|
||
export type DotnetToolsManifest = DotnetToolsManifestV1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './cmd-line-parameter'; | ||
export * from './nx-dotnet-config.interface'; | ||
export * from './nx'; | ||
export * from './dotnet-tools-manifest.interface'; |
143 changes: 143 additions & 0 deletions
143
packages/utils/src/lib/utility-functions/dotnet-tools-manifest.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import { | ||
readDotnetToolsManifest, | ||
readInstalledDotnetToolVersion, | ||
} from './dotnet-tools-manifest'; | ||
import * as devkit from '@nrwl/devkit'; | ||
import * as fs from 'fs'; | ||
|
||
const root = '/virtual'; | ||
jest.mock('@nrwl/devkit', () => ({ | ||
...jest.requireActual('@nrwl/devkit'), | ||
workspaceRoot: '/virtual', | ||
})); | ||
|
||
const existsSyncMock = jest.spyOn(fs, 'existsSync'); | ||
const readJsonFileMock = jest.spyOn(devkit, 'readJsonFile'); | ||
|
||
describe('dotnet tools util functions', () => { | ||
describe('readDotnetToolsManifest', () => { | ||
beforeEach(() => { | ||
existsSyncMock.mockReset(); | ||
readJsonFileMock.mockReset(); | ||
existsSyncMock.mockReturnValue(true); | ||
readJsonFileMock.mockImplementation((p: string): object => { | ||
if (p === `${root}/.config/dotnet-tools.json`) { | ||
return { | ||
version: 1, | ||
isRoot: true, | ||
tools: { | ||
'swashbuckle.aspnetcore.cli': { | ||
version: '99.99.99', | ||
commands: ['swagger'], | ||
}, | ||
}, | ||
}; | ||
} | ||
throw new Error(`Attempted to read unexpected file: ${p}`); | ||
}); | ||
}); | ||
|
||
it('should read from workspace root', async () => { | ||
const result = readDotnetToolsManifest(); | ||
expect(result).toEqual({ | ||
version: 1, | ||
isRoot: true, | ||
tools: { | ||
'swashbuckle.aspnetcore.cli': { | ||
version: '99.99.99', | ||
commands: ['swagger'], | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should return undefined if file missing', async () => { | ||
existsSyncMock.mockReturnValue(false); | ||
const result = readDotnetToolsManifest(); | ||
expect(result).toBeUndefined(); | ||
expect(readJsonFileMock).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should return undefined if file wrong version', async () => { | ||
readJsonFileMock.mockImplementation((p: string): object => { | ||
if (p === `${root}/.config/dotnet-tools.json`) { | ||
return { | ||
version: 99, | ||
isRoot: true, | ||
tools: {}, | ||
}; | ||
} | ||
throw new Error(`Attempted to read unexpected file: ${p}`); | ||
}); | ||
const result = readDotnetToolsManifest(); | ||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
it('read from overridden file path if provided', async () => { | ||
readJsonFileMock.mockImplementation((p: string): object => { | ||
if (p === '/custom/path/file.json') { | ||
return { | ||
version: 1, | ||
isRoot: true, | ||
tools: {}, | ||
}; | ||
} | ||
throw new Error(`Attempted to read unexpected file: ${p}`); | ||
}); | ||
const result = readDotnetToolsManifest('/custom/path/file.json'); | ||
expect(result).toEqual({ | ||
version: 1, | ||
isRoot: true, | ||
tools: {}, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('readInstalledDotnetToolVersion', () => { | ||
beforeEach(() => { | ||
existsSyncMock.mockReturnValue(true); | ||
readJsonFileMock.mockImplementation((p: string): object => { | ||
if (p === `${root}/.config/dotnet-tools.json`) { | ||
return { | ||
version: 1, | ||
isRoot: true, | ||
tools: { | ||
'swashbuckle.aspnetcore.cli': { | ||
version: '99.99.99', | ||
commands: ['swagger'], | ||
}, | ||
}, | ||
}; | ||
} | ||
throw new Error(`Attempted to read unexpected file: ${p}`); | ||
}); | ||
}); | ||
|
||
it('should read version', async () => { | ||
const result = readInstalledDotnetToolVersion( | ||
'swashbuckle.aspnetcore.cli', | ||
); | ||
expect(result).toEqual('99.99.99'); | ||
}); | ||
|
||
it('should read version if tool case mismatch', async () => { | ||
const result = readInstalledDotnetToolVersion( | ||
'SwashBuckle.AspNetCore.Cli', | ||
); | ||
expect(result).toEqual('99.99.99'); | ||
}); | ||
|
||
it('should return undefined if tool not installed', async () => { | ||
const result = readInstalledDotnetToolVersion('Not.There'); | ||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
it('should return undefined if no tool manifest file', async () => { | ||
existsSyncMock.mockReturnValue(false); | ||
const result = readInstalledDotnetToolVersion( | ||
'swashbuckle.aspnetcore.cli', | ||
); | ||
expect(result).toBeUndefined(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.