Skip to content

Commit

Permalink
Merge branch 'master' into projects-on-schema
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry authored Dec 7, 2023
2 parents 1b203af + 61429c0 commit 1f8ae49
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ describe('Cypress e2e configuration', () => {
await cypressE2EConfigurationGenerator(tree, {
project: 'my-app',
baseUrl: 'http://localhost:4200',
webServerCommands: {
default: 'nx run my-app:serve',
production: 'nx run my-app:serve:production',
},
ciWebServerCommand: 'nx run my-app:serve-static',
});
expect(tree.read('apps/my-app/cypress.config.ts', 'utf-8'))
.toMatchInlineSnapshot(`
Expand Down
14 changes: 10 additions & 4 deletions packages/cypress/src/generators/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export interface CypressE2EConfigSchema {
port?: number | 'cypress-auto';
jsx?: boolean;
rootProject?: boolean;

webServerCommands?: Record<string, string>;
ciWebServerCommand?: string;
}

type NormalizedSchema = ReturnType<typeof normalizeOptions>;
Expand Down Expand Up @@ -166,9 +169,12 @@ async function addFiles(
const cyFile = joinPathFragments(projectConfig.root, 'cypress.config.ts');
let webServerCommands: Record<string, string>;

let ciDevServerTarget: string;
let ciWebServerCommand: string;

if (hasPlugin && options.devServerTarget) {
if (hasPlugin && options.webServerCommands && options.ciWebServerCommand) {
webServerCommands = options.webServerCommands;
ciWebServerCommand = options.ciWebServerCommand;
} else if (hasPlugin && options.devServerTarget) {
webServerCommands = {};

webServerCommands.default = 'nx run ' + options.devServerTarget;
Expand All @@ -192,7 +198,7 @@ async function addFiles(
}
// Add ci/static e2e target if serve target is found
if (devServerProjectConfig.targets?.['serve-static']) {
ciDevServerTarget = `nx run ${parsedTarget.project}:serve-static`;
ciWebServerCommand = `nx run ${parsedTarget.project}:serve-static`;
}
}
const updatedCyConfig = await addDefaultE2EConfig(
Expand All @@ -201,7 +207,7 @@ async function addFiles(
cypressDir: options.directory,
bundler: options.bundler === 'vite' ? 'vite' : undefined,
webServerCommands,
ciWebServerCommand: ciDevServerTarget,
ciWebServerCommand: ciWebServerCommand,
},
options.baseUrl
);
Expand Down
3 changes: 2 additions & 1 deletion packages/nx/src/nx-cloud/update-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ async function downloadAndExtractClientBundle(
const writeStream = createWriteStream(outputFilePath);
stream.pipe(writeStream);

stream.on('end', function () {
// Continue the tar stream after the write stream closes
writeStream.on('close', () => {
next();
});

Expand Down
17 changes: 13 additions & 4 deletions packages/react/src/generators/application/lib/add-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export async function addE2e(
): Promise<GeneratorCallback> {
switch (options.e2eTestRunner) {
case 'cypress': {
if (
(options.bundler === 'webpack' && !hasWebpackPlugin(tree)) ||
(options.bundler === 'vite' && !hasVitePlugin(tree))
) {
const hasNxBuildPlugin =
(options.bundler === 'webpack' && hasWebpackPlugin(tree)) ||
(options.bundler === 'vite' && hasVitePlugin(tree));
if (!hasNxBuildPlugin) {
webStaticServeGenerator(tree, {
buildTarget: `${options.projectName}:build`,
targetName: 'serve-static',
Expand Down Expand Up @@ -52,6 +52,15 @@ export async function addE2e(
baseUrl: 'http://localhost:4200',
jsx: true,
rootProject: options.rootProject,
webServerCommands: hasNxBuildPlugin
? {
default: `nx run ${options.projectName}:serve`,
production: `nx run ${options.projectName}:preview`,
}
: undefined,
ciWebServerCommand: hasNxBuildPlugin
? `nx run ${options.projectName}:serve-static`
: undefined,
});
}
case 'playwright': {
Expand Down

0 comments on commit 1f8ae49

Please sign in to comment.