Skip to content

Commit

Permalink
fix(misc): pass e2eTestRunner to child preset generator (nrwl#16414)
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Apr 19, 2023
1 parent 338dc64 commit a798576
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 4 deletions.
5 changes: 5 additions & 0 deletions docs/generated/packages/workspace/generators/new.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
"description": "Enable experimental app directory for the project",
"type": "boolean",
"default": false
},
"e2eTestRunner": {
"description": "The tool to use for running e2e tests.",
"type": "string",
"enum": ["cypress", "jest", "detox", "none"]
}
},
"additionalProperties": true,
Expand Down
5 changes: 5 additions & 0 deletions docs/generated/packages/workspace/generators/preset.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
"description": "Enable experimental app/ for the project",
"type": "boolean",
"default": false
},
"e2eTestRunner": {
"description": "The tool to use for running e2e tests.",
"type": "string",
"enum": ["cypress", "jest", "detox", "none"]
}
},
"presets": []
Expand Down
6 changes: 5 additions & 1 deletion packages/workspace/src/generators/new/generate-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ export function generatePreset(host: Tree, opts: NormalizedSchema) {
: null,
parsedArgs.interactive ? '--interactive=true' : '--interactive=false',
opts.routing !== undefined ? `--routing=${opts.routing}` : null,
opts.e2eTestRunner !== undefined
? `--e2eTestRunner=${opts.e2eTestRunner}`
: null,
].filter((e) => !!e);
}
}
Expand All @@ -92,6 +95,7 @@ function getPresetDependencies({
preset,
presetVersion,
bundler,
e2eTestRunner,
}: NormalizedSchema) {
switch (preset) {
case Preset.TS:
Expand Down Expand Up @@ -126,7 +130,7 @@ function getPresetDependencies({
dependencies: {},
dev: {
'@nx/react': nxVersion,
'@nx/cypress': nxVersion,
'@nx/cypress': e2eTestRunner !== 'none' ? nxVersion : undefined,
'@nx/jest': bundler !== 'vite' ? nxVersion : undefined,
'@nx/vite': bundler === 'vite' ? nxVersion : undefined,
'@nx/webpack': bundler === 'webpack' ? nxVersion : undefined,
Expand Down
1 change: 1 addition & 0 deletions packages/workspace/src/generators/new/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface Schema {
standaloneApi?: boolean;
routing?: boolean;
packageManager?: PackageManager;
e2eTestRunner?: 'cypress' | 'detox' | 'jest' | 'none';
}

export interface NormalizedSchema extends Schema {
Expand Down
5 changes: 5 additions & 0 deletions packages/workspace/src/generators/new/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
"description": "Enable experimental app directory for the project",
"type": "boolean",
"default": false
},
"e2eTestRunner": {
"description": "The tool to use for running e2e tests.",
"type": "string",
"enum": ["cypress", "jest", "detox", "none"]
}
},
"additionalProperties": true
Expand Down
14 changes: 11 additions & 3 deletions packages/workspace/src/generators/preset/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ async function createPreset(tree: Tree, options: Schema) {
linter: options.linter,
standalone: options.standaloneApi,
routing: options.routing,
e2eTestRunner: options.e2eTestRunner,
});
} else if (options.preset === Preset.AngularStandalone) {
const {
Expand All @@ -46,6 +47,7 @@ async function createPreset(tree: Tree, options: Schema) {
routing: options.routing,
rootProject: true,
standalone: options.standaloneApi,
e2eTestRunner: options.e2eTestRunner ?? 'cypress',
});
} else if (options.preset === Preset.ReactMonorepo) {
const { applicationGenerator: reactApplicationGenerator } = require('@nx' +
Expand All @@ -56,6 +58,7 @@ async function createPreset(tree: Tree, options: Schema) {
style: options.style,
linter: options.linter,
bundler: options.bundler ?? 'webpack',
e2eTestRunner: options.e2eTestRunner ?? 'cypress',
});
} else if (options.preset === Preset.ReactStandalone) {
const { applicationGenerator: reactApplicationGenerator } = require('@nx' +
Expand All @@ -67,7 +70,7 @@ async function createPreset(tree: Tree, options: Schema) {
linter: options.linter,
rootProject: true,
bundler: options.bundler ?? 'vite',
e2eTestRunner: 'cypress',
e2eTestRunner: options.e2eTestRunner ?? 'cypress',
unitTestRunner: options.bundler === 'vite' ? 'vitest' : 'jest',
});
} else if (options.preset === Preset.NextJs) {
Expand All @@ -78,6 +81,7 @@ async function createPreset(tree: Tree, options: Schema) {
name: options.name,
style: options.style,
linter: options.linter,
e2eTestRunner: options.e2eTestRunner ?? 'cypress',
});
} else if (options.preset === Preset.NextJsStandalone) {
const { applicationGenerator: nextApplicationGenerator } = require('@nx' +
Expand All @@ -98,6 +102,7 @@ async function createPreset(tree: Tree, options: Schema) {
style: options.style,
linter: options.linter,
bundler: 'vite',
e2eTestRunner: options.e2eTestRunner ?? 'cypress',
});
} else if (options.preset === Preset.Nest) {
const { applicationGenerator: nestApplicationGenerator } = require('@nx' +
Expand All @@ -106,6 +111,7 @@ async function createPreset(tree: Tree, options: Schema) {
return nestApplicationGenerator(tree, {
name: options.name,
linter: options.linter,
e2eTestRunner: options.e2eTestRunner ?? 'jest',
});
} else if (options.preset === Preset.Express) {
const {
Expand All @@ -114,21 +120,22 @@ async function createPreset(tree: Tree, options: Schema) {
return expressApplicationGenerator(tree, {
name: options.name,
linter: options.linter,
e2eTestRunner: options.e2eTestRunner ?? 'jest',
});
} else if (options.preset === Preset.ReactNative) {
const { reactNativeApplicationGenerator } = require('@nx' +
'/react-native');
return reactNativeApplicationGenerator(tree, {
name: options.name,
linter: options.linter,
e2eTestRunner: 'detox',
e2eTestRunner: options.e2eTestRunner ?? 'detox',
});
} else if (options.preset === Preset.Expo) {
const { expoApplicationGenerator } = require('@nx' + '/expo');
return expoApplicationGenerator(tree, {
name: options.name,
linter: options.linter,
e2eTestRunner: 'detox',
e2eTestRunner: options.e2eTestRunner ?? 'detox',
});
} else if (options.preset === Preset.TS) {
const c = readNxJson(tree);
Expand All @@ -149,6 +156,7 @@ async function createPreset(tree: Tree, options: Schema) {
framework: options.framework,
docker: options.docker,
rootProject: true,
e2eTestRunner: options.e2eTestRunner ?? 'jest',
});
} else {
throw new Error(`Invalid preset ${options.preset}`);
Expand Down
1 change: 1 addition & 0 deletions packages/workspace/src/generators/preset/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export interface Schema {
nextAppDir?: boolean;
routing?: boolean;
standaloneApi?: boolean;
e2eTestRunner?: 'cypress' | 'jest' | 'detox' | 'none';
}
5 changes: 5 additions & 0 deletions packages/workspace/src/generators/preset/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
"description": "Enable experimental app/ for the project",
"type": "boolean",
"default": false
},
"e2eTestRunner": {
"description": "The tool to use for running e2e tests.",
"type": "string",
"enum": ["cypress", "jest", "detox", "none"]
}
}
}

0 comments on commit a798576

Please sign in to comment.