Skip to content

Commit

Permalink
fix(node): update generated spec file to work better for standalone p…
Browse files Browse the repository at this point in the history
…rojects
  • Loading branch information
jaysoo authored and Jack Hsu committed Jan 18, 2023
1 parent 99b4918 commit e5fe3d2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
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

0 comments on commit e5fe3d2

Please sign in to comment.