-
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
8 changed files
with
354 additions
and
3 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
151 changes: 151 additions & 0 deletions
151
packages/nx/src/command-line/import/utils/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,151 @@ | ||
import { | ||
AggregateCreateNodesError, | ||
MergeNodesError, | ||
ProjectConfigurationsError, | ||
ProjectsWithNoNameError, | ||
} from '../../../project-graph/error-types'; | ||
import { checkCompatibleWithPlugins } from './check-compatible-with-plugins'; | ||
import { retrieveProjectConfigurations } from '../../../project-graph/utils/retrieve-workspace-files'; | ||
import { tmpdir } from 'os'; | ||
|
||
jest.mock('../../../project-graph/plugins/internal-api', () => ({ | ||
loadNxPlugins: jest.fn().mockReturnValue([[], []]), | ||
})); | ||
jest.mock('../../../project-graph/utils/retrieve-workspace-files', () => ({ | ||
retrieveProjectConfigurations: jest.fn(), | ||
})); | ||
|
||
describe('checkCompatibleWithPlugins', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should return emptry object if no errors are thrown', async () => { | ||
(retrieveProjectConfigurations as any).mockReturnValueOnce( | ||
Promise.resolve({}) | ||
); | ||
const result = await checkCompatibleWithPlugins( | ||
['plugin1', 'plugin2'], | ||
'projectRootPathToCheck', | ||
tmpdir() | ||
); | ||
expect(result).toEqual({}); | ||
}); | ||
|
||
it('should return emptry object if error is not ProjectConfigurationsError', async () => { | ||
(retrieveProjectConfigurations as any).mockReturnValueOnce( | ||
Promise.reject(new Error('random error')) | ||
); | ||
const result = await checkCompatibleWithPlugins( | ||
['plugin1', 'plugin2'], | ||
'projectRootPathToCheck', | ||
tmpdir() | ||
); | ||
expect(result).toEqual({}); | ||
}); | ||
|
||
it('should return emptry object if error is ProjectsWithNoNameError', async () => { | ||
(retrieveProjectConfigurations as any).mockReturnValueOnce( | ||
Promise.reject( | ||
new ProjectConfigurationsError( | ||
[ | ||
new ProjectsWithNoNameError([], { | ||
project1: { root: 'root1' }, | ||
}), | ||
], | ||
undefined | ||
) | ||
) | ||
); | ||
const result = await checkCompatibleWithPlugins( | ||
['plugin1', 'plugin2'], | ||
'projectRootPathToCheck', | ||
tmpdir() | ||
); | ||
expect(result).toEqual({}); | ||
}); | ||
|
||
it('should return imcompatible plugin with excluded files if error is AggregateCreateNodesError', async () => { | ||
(retrieveProjectConfigurations as any).mockReturnValueOnce( | ||
Promise.reject( | ||
new ProjectConfigurationsError( | ||
[ | ||
new AggregateCreateNodesError( | ||
[ | ||
['file1', undefined], | ||
['file2', undefined], | ||
], | ||
[], | ||
'plugin1' | ||
), | ||
], | ||
undefined | ||
) | ||
) | ||
); | ||
const result = await checkCompatibleWithPlugins( | ||
['plugin1', 'plugin2'], | ||
'projectRootPathToCheck', | ||
tmpdir() | ||
); | ||
expect(result).toEqual({ plugin1: ['file1', 'file2'] }); | ||
}); | ||
|
||
it('should return true if error is MergeNodesError', async () => { | ||
(retrieveProjectConfigurations as any).mockReturnValueOnce( | ||
Promise.reject( | ||
new ProjectConfigurationsError( | ||
[ | ||
new MergeNodesError({ | ||
file: 'file2', | ||
pluginName: 'plugin2', | ||
error: new Error(), | ||
}), | ||
], | ||
undefined | ||
) | ||
) | ||
); | ||
const result = await checkCompatibleWithPlugins( | ||
['plugin1', 'plugin2'], | ||
'projectRootPathToCheck', | ||
tmpdir() | ||
); | ||
expect(result).toEqual({ plugin2: ['file2'] }); | ||
}); | ||
|
||
it('should handle multiple errors', async () => { | ||
(retrieveProjectConfigurations as any).mockReturnValueOnce( | ||
Promise.reject( | ||
new ProjectConfigurationsError( | ||
[ | ||
new ProjectsWithNoNameError([], { | ||
project1: { root: 'root1' }, | ||
}), | ||
new AggregateCreateNodesError([], [], 'randomPlugin'), | ||
new AggregateCreateNodesError( | ||
[ | ||
['file1', undefined], | ||
['file2', undefined], | ||
], | ||
[], | ||
'plugin1' | ||
), | ||
new MergeNodesError({ | ||
file: 'file2', | ||
pluginName: 'plugin2', | ||
error: new Error(), | ||
}), | ||
], | ||
undefined | ||
) | ||
) | ||
); | ||
const result = await checkCompatibleWithPlugins( | ||
['plugin1', 'plugin2'], | ||
'projectRootPathToCheck', | ||
tmpdir() | ||
); | ||
expect(result).toEqual({ plugin1: ['file1', 'file2'], plugin2: ['file2'] }); | ||
}); | ||
}); |
Oops, something went wrong.