-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Handle when an existing plugin begins to fail with the ne…
…w imported project
- Loading branch information
Showing
10 changed files
with
370 additions
and
32 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
145 changes: 145 additions & 0 deletions
145
packages/nx/src/command-line/init/implementation/check-compatible-with-plugins.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,145 @@ | ||
import { | ||
AggregateCreateNodesError, | ||
CreateMetadataError, | ||
MergeNodesError, | ||
ProjectGraphError, | ||
ProjectsWithNoNameError, | ||
} from '../../../project-graph/error-types'; | ||
import { checkCompatibleWithPlugins } from './check-compatible-with-plugins'; | ||
import { retrieveProjectConfigurations } from '../../../project-graph/utils/retrieve-workspace-files'; | ||
|
||
jest.mock('../../../project-graph/utils/retrieve-workspace-files', () => ({ | ||
retrieveProjectConfigurations: jest.fn(), | ||
})); | ||
|
||
describe('checkCompatibleWithPlugins', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should return empty object if no errors are thrown', async () => { | ||
(retrieveProjectConfigurations as any).mockReturnValueOnce( | ||
Promise.resolve({}) | ||
); | ||
const result = await checkCompatibleWithPlugins(); | ||
expect(result).toEqual({}); | ||
}); | ||
|
||
it('should return empty object if error is not ProjectConfigurationsError', async () => { | ||
(retrieveProjectConfigurations as any).mockReturnValueOnce( | ||
Promise.reject(new Error('random error')) | ||
); | ||
const result = await checkCompatibleWithPlugins(); | ||
expect(result).toEqual({}); | ||
}); | ||
|
||
it('should return empty object if error is ProjectsWithNoNameError', async () => { | ||
(retrieveProjectConfigurations as any).mockReturnValueOnce( | ||
Promise.reject( | ||
new ProjectGraphError( | ||
[ | ||
new ProjectsWithNoNameError([], { | ||
project1: { root: 'root1' }, | ||
}), | ||
], | ||
undefined, | ||
undefined | ||
) | ||
) | ||
); | ||
const result = await checkCompatibleWithPlugins(); | ||
expect(result).toEqual({}); | ||
}); | ||
|
||
it('should return incompatible plugin with excluded files if error is AggregateCreateNodesError', async () => { | ||
(retrieveProjectConfigurations as any).mockReturnValueOnce( | ||
Promise.reject( | ||
new ProjectGraphError( | ||
[ | ||
new AggregateCreateNodesError( | ||
[ | ||
['file1', undefined], | ||
['file2', undefined], | ||
], | ||
[], | ||
0 | ||
), | ||
], | ||
undefined, | ||
undefined | ||
) | ||
) | ||
); | ||
const result = await checkCompatibleWithPlugins(); | ||
expect(result).toEqual({ | ||
0: [ | ||
{ file: 'file1', error: undefined }, | ||
{ file: 'file2', error: undefined }, | ||
], | ||
}); | ||
}); | ||
|
||
it('should return true if error is MergeNodesError', async () => { | ||
let error = new MergeNodesError({ | ||
file: 'file2', | ||
pluginName: 'plugin2', | ||
error: new Error(), | ||
pluginIndex: 1, | ||
}); | ||
(retrieveProjectConfigurations as any).mockReturnValueOnce( | ||
Promise.reject(new ProjectGraphError([error], undefined, undefined)) | ||
); | ||
const result = await checkCompatibleWithPlugins(); | ||
expect(result).toEqual({ 1: [{ error, file: 'file2' }] }); | ||
}); | ||
|
||
it('should handle multiple errors', async () => { | ||
let mergeNodesError = new MergeNodesError({ | ||
file: 'file2', | ||
pluginName: 'plugin2', | ||
error: new Error(), | ||
pluginIndex: 2, | ||
}); | ||
(retrieveProjectConfigurations as any).mockReturnValueOnce( | ||
Promise.reject( | ||
new ProjectGraphError( | ||
[ | ||
new ProjectsWithNoNameError([], { | ||
project1: { root: 'root1' }, | ||
}), | ||
new CreateMetadataError(new Error(), 'file1'), | ||
new AggregateCreateNodesError([], [], 0), | ||
new AggregateCreateNodesError( | ||
[ | ||
['file1', undefined], | ||
['file2', undefined], | ||
], | ||
[], | ||
0 | ||
), | ||
mergeNodesError, | ||
new AggregateCreateNodesError( | ||
[ | ||
['file3', undefined], | ||
['file4', undefined], | ||
], | ||
[], | ||
2 | ||
), | ||
], | ||
undefined, | ||
undefined | ||
) | ||
) | ||
); | ||
const result = await checkCompatibleWithPlugins(); | ||
expect(result).toEqual({ | ||
0: [{ file: 'file1' }, { file: 'file2' }], | ||
2: [ | ||
{ file: 'file2', error: mergeNodesError }, | ||
{ file: 'file3' }, | ||
{ file: 'file4' }, | ||
], | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.