Skip to content

Commit

Permalink
fix(core): manually reset context for e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli committed Sep 7, 2023
1 parent 6ae0d3f commit c1bee5b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion e2e/utils/project-config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function readResolvedConfiguration(): Promise<
> {
process.env.NX_PROJECT_GLOB_CACHE = 'false';
const root = tmpProjPath();
return (await retrieveProjectConfigurations(root, readNxJson(root)))
return (await retrieveProjectConfigurations(root, readNxJson(root), true))
.projectNodes;
}

Expand Down
18 changes: 14 additions & 4 deletions packages/nx/src/project-graph/utils/retrieve-workspace-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ export async function retrieveWorkspaceFiles(
*
* @param workspaceRoot
* @param nxJson
* @param resetWorkspaceContext manually reset the workspace context so that files are updated (this should only be used for testing)
*/
export async function retrieveProjectConfigurations(
workspaceRoot: string,
nxJson: NxJsonConfiguration
nxJson: NxJsonConfiguration,
resetWorkspaceContext = false
): Promise<{
externalNodes: Record<string, ProjectGraphExternalNode>;
projectNodes: Record<string, ProjectConfiguration>;
Expand All @@ -115,7 +117,13 @@ export async function retrieveProjectConfigurations(
);

const globs = configurationGlobs(workspaceRoot, plugins);
return _retrieveProjectConfigurations(workspaceRoot, nxJson, plugins, globs);
return _retrieveProjectConfigurations(
workspaceRoot,
nxJson,
plugins,
globs,
resetWorkspaceContext
);
}

export async function retrieveProjectConfigurationsWithAngularProjects(
Expand Down Expand Up @@ -166,7 +174,8 @@ function _retrieveProjectConfigurations(
workspaceRoot: string,
nxJson: NxJsonConfiguration,
plugins: NxPluginV2[],
globs: string[]
globs: string[],
resetWorkspaceContext = false
): {
externalNodes: Record<string, ProjectGraphExternalNode>;
projectNodes: Record<string, ProjectConfiguration>;
Expand All @@ -186,7 +195,8 @@ function _retrieveProjectConfigurations(
projectNodes: projectConfigurations.projects,
externalNodes: projectConfigurations.externalNodes,
};
}
},
resetWorkspaceContext
) as {
externalNodes: Record<string, ProjectGraphExternalNode>;
projectNodes: Record<string, ProjectConfiguration>;
Expand Down
16 changes: 12 additions & 4 deletions packages/nx/src/utils/workspace-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,22 @@ export function getProjectConfigurationFilesFromContext(
export function getProjectConfigurationsFromContext(
workspaceRoot: string,
globs: string[],
parseConfigurations: (files: string[]) => ConfigurationParserResult
parseConfigurations: (files: string[]) => ConfigurationParserResult,
resetWorkspaceContext = false
) {
ensureContextAvailable(workspaceRoot);
ensureContextAvailable(workspaceRoot, resetWorkspaceContext);
return workspaceContext.getProjectConfigurations(globs, parseConfigurations);
}

function ensureContextAvailable(workspaceRoot: string) {
if (!workspaceContext && workspaceContext?.workspaceRoot !== workspaceRoot) {
function ensureContextAvailable(
workspaceRoot: string,
resetWorkspaceContext = false
) {
if (
!workspaceContext ||
workspaceContext?.workspaceRoot !== workspaceRoot ||
resetWorkspaceContext
) {
setupWorkspaceContext(workspaceRoot);
}
}
Expand Down

0 comments on commit c1bee5b

Please sign in to comment.