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(@schematics/angular): don't create e2e script when createApplication is false #16203

Merged
merged 1 commit into from Aug 14, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/schematics/angular/e2e/index.ts
Expand Up @@ -17,11 +17,23 @@ import {
move,
url,
} from '@angular-devkit/schematics';
import { JSONFile } from '../utility/json-file';
import { relativePathToWorkspaceRoot } from '../utility/paths';
import { getWorkspace, updateWorkspace } from '../utility/workspace';
import { Builders } from '../utility/workspace-models';
import { Schema as E2eOptions } from './schema';

function addScriptsToPackageJson(): Rule {
return host => {
const pkgJson = new JSONFile(host, 'package.json');
const e2eScriptPath = ['scripts', 'e2e'];

if (!pkgJson.get(e2eScriptPath)) {
pkgJson.modify(e2eScriptPath, 'ng e2e', false);
}
};
}

export default function (options: E2eOptions): Rule {
return async (host: Tree) => {
const appProject = options.relatedAppName;
Expand Down Expand Up @@ -65,6 +77,7 @@ export default function (options: E2eOptions): Rule {
}),
move(root),
])),
addScriptsToPackageJson(),
]);
};
}
7 changes: 7 additions & 0 deletions packages/schematics/angular/e2e/index_spec.ts
Expand Up @@ -99,4 +99,11 @@ describe('Application Schematic', () => {
expect(e2eOptions.devServerTarget).toEqual('foo:serve');
});
});

it('should add an e2e script in package.json', async () => {
const tree = await schematicRunner.runSchematicAsync('e2e', defaultOptions, applicationTree)
.toPromise();
const pkg = JSON.parse(tree.readContent('/package.json'));
expect(pkg.scripts['e2e']).toBe('ng e2e');
});
});
Expand Up @@ -6,8 +6,7 @@
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
"lint": "ng lint"
},
"private": true,
"dependencies": {
Expand Down