Skip to content

Commit

Permalink
fix(testing): remove root from the cypress ci-e2e group (#22468)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored Mar 22, 2024
1 parent 777fbd1 commit 1391bc7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/cypress/src/plugins/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ describe('@nx/cypress/plugin', () => {
".": {
"metadata": {
"targetGroups": {
".:e2e-ci": [
"e2e-ci": [
"e2e-ci--src/test.cy.ts",
"e2e-ci",
],
Expand Down
30 changes: 14 additions & 16 deletions packages/cypress/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const createNodes: CreateNodes<CypressPluginOptions> = [
getLockFileName(detectPackageManager(context.workspaceRoot)),
]);

const { targets, ciTestingGroup } = targetsCache[hash]
const { targets, targetGroups } = targetsCache[hash]
? targetsCache[hash]
: await buildCypressTargets(
configFilePath,
Expand All @@ -75,7 +75,7 @@ export const createNodes: CreateNodes<CypressPluginOptions> = [
context
);

calculatedTargets[hash] = { targets, ciTestingGroup };
calculatedTargets[hash] = { targets, targetGroups };

const project: Omit<ProjectConfiguration, 'root'> = {
projectType: 'application',
Expand All @@ -85,10 +85,8 @@ export const createNodes: CreateNodes<CypressPluginOptions> = [
},
};

if (ciTestingGroup) {
project.metadata.targetGroups = {
[`${projectRoot}:e2e-ci`]: ciTestingGroup,
};
if (targetGroups) {
project.metadata.targetGroups = targetGroups;
}

return {
Expand Down Expand Up @@ -149,7 +147,7 @@ function getOutputs(

interface CypressTargets {
targets: Record<string, TargetConfiguration>;
ciTestingGroup: string[];
targetGroups: Record<string, string[]> | null;
}

async function buildCypressTargets(
Expand All @@ -174,7 +172,7 @@ async function buildCypressTargets(
const namedInputs = getNamedInputs(projectRoot, context);

const targets: Record<string, TargetConfiguration> = {};
let ciTestingGroup: string[] = [];
let targetGroups: Record<string, string[]>;

if ('e2e' in cypressConfig) {
targets[options.targetName] = {
Expand Down Expand Up @@ -221,11 +219,14 @@ async function buildCypressTargets(
const dependsOn: TargetConfiguration['dependsOn'] = [];
const outputs = getOutputs(projectRoot, cypressConfig, 'e2e');
const inputs = getInputs(namedInputs);

targetGroups = { [options.ciTargetName]: [] };
const ciTargetGroup = targetGroups[options.ciTargetName];
for (const file of specFiles) {
const relativeSpecFilePath = normalizePath(relative(projectRoot, file));
const targetName = options.ciTargetName + '--' + relativeSpecFilePath;

ciTestingGroup.push(targetName);
ciTargetGroup.push(targetName);
targets[targetName] = {
outputs,
inputs,
Expand All @@ -241,7 +242,6 @@ async function buildCypressTargets(
params: 'forward',
});
}
targets[options.ciTargetName] ??= {};

targets[options.ciTargetName] = {
executor: 'nx:noop',
Expand All @@ -250,7 +250,9 @@ async function buildCypressTargets(
outputs,
dependsOn,
};
ciTestingGroup.push(options.ciTargetName);
ciTargetGroup.push(options.ciTargetName);
} else {
targetGroups = null;
}
}

Expand All @@ -265,11 +267,7 @@ async function buildCypressTargets(
};
}

if (ciTestingGroup.length === 0) {
ciTestingGroup = null;
}

return { targets, ciTestingGroup };
return { targets, targetGroups };
}

function normalizeOptions(options: CypressPluginOptions): CypressPluginOptions {
Expand Down

0 comments on commit 1391bc7

Please sign in to comment.