Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node): update generated spec file to work better for standalone projects #14461

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions packages/node/src/generators/e2e-project/e2e-project.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Tree } from '@nrwl/devkit/';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import { applicationGenerator } from '../application/application';
import { e2eProjectGenerator } from './e2e-project';

describe('e2eProjectGenerator', () => {
let tree: Tree;
beforeEach(async () => {
tree = createTreeWithEmptyWorkspace();
});

it('should generate default spec for server app (integrated)', async () => {
await applicationGenerator(tree, {
name: 'api',
framework: 'express',
e2eTestRunner: 'none',
});
await e2eProjectGenerator(tree, {
projectType: 'server',
project: 'api',
});

expect(tree.exists(`api-e2e/src/api/api.spec.ts`)).toBeTruthy();
});

it('should generate default spec for server app (standalone)', async () => {
await applicationGenerator(tree, {
name: 'api',
framework: 'express',
e2eTestRunner: 'none',
rootProject: true,
});
await e2eProjectGenerator(tree, {
projectType: 'server',
project: 'api',
rootProject: true,
});

expect(tree.exists(`e2e/src/server/server.spec.ts`)).toBeTruthy();
});
});
12 changes: 9 additions & 3 deletions packages/node/src/generators/e2e-project/e2e-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function e2eProjectGenerator(host: Tree, _options: Schema) {
options.projectRoot,
{
...options,
...names(options.projectName),
...names(options.rootProject ? 'server' : options.project),
offsetFromRoot: offsetFromRoot(options.projectRoot),
tmpl: '',
}
Expand All @@ -59,7 +59,7 @@ export async function e2eProjectGenerator(host: Tree, _options: Schema) {
options.projectRoot,
{
...options,
...names(options.projectName),
...names(options.rootProject ? 'server' : options.project),
mainFile,
offsetFromRoot: offsetFromRoot(options.projectRoot),
tmpl: '',
Expand Down Expand Up @@ -116,7 +116,13 @@ function normalizeOptions(
? 'e2e'
: joinPathFragments(appsDir, appDirectory);

return { ...options, projectRoot, projectName, port: options.port ?? 3000 };
return {
...options,
projectRoot,
projectName,
port: options.port ?? 3000,
rootProject: !!options.rootProject,
};
}

export default e2eProjectGenerator;
Expand Down