Skip to content

bug(generate): fix relative path module generations #3162

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

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 1 addition & 5 deletions packages/angular-cli/blueprints/module/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ module.exports = {
},

afterInstall: function (options) {
// Note that `this.generatePath` already contains `this.dasherizedModuleName`
// So, the path will end like `name/name`,
// which is correct for `name.component.ts` created in module `name`
var componentPath = path.join(this.generatePath, this.dasherizedModuleName);
options.entity.name = path.relative(this.dynamicPath.appRoot, componentPath);
options.entity.name = path.join(this.entityName, options.entity.name);
options.flat = true;
options.route = false;
options.inlineTemplate = false;
Expand Down
28 changes: 28 additions & 0 deletions tests/e2e/tests/generate/module/module-relative-path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {join} from 'path';
import {ng} from '../../../utils/process';
import {expectFileToExist, createDir} from '../../../utils/fs';
import {expectToFail} from '../../../utils/utils';


export default function() {
const moduleDir = join('src', 'app', 'test-module');


return Promise.resolve()
.then(() => createDir('src/app/fldr'))
.then(() => process.chdir('./src/app/fldr'))
.then(() => process.env.PWD = process.cwd())
.then(() => ng('generate', 'module', '../test-module'))
.then(() => process.chdir('../../..')) // Reset directory after generation for verification
.then(() => process.env.PWD = process.cwd())
.then(() => expectFileToExist(moduleDir))
.then(() => expectFileToExist(join(moduleDir, 'test-module.module.ts')))
.then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test-module.routing.ts'))))
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.ts')))
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.spec.ts')))
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.html')))
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.css')))

// Try to run the unit tests.
.then(() => ng('test', '--single-run'));
}
7 changes: 7 additions & 0 deletions tests/e2e_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ testsToRun.reduce((previous, relativeName) => {
throw new Error('Invalid test module.');
};

let currentDir = null;
let clean = true;
return Promise.resolve()
.then(() => printHeader(currentFileName))
.then(() => currentDir = process.cwd())
.then(() => fn(argv, () => clean = false))
.then(() => console.log(' ----'))
.then(() => {
Expand All @@ -103,6 +105,11 @@ testsToRun.reduce((previous, relativeName) => {
return gitClean();
}
})
.then(() => {
if (allSetups.indexOf(relativeName) == -1) {
process.chdir(currentDir);
}
})
.then(() => printFooter(currentFileName, start),
(err) => {
printFooter(currentFileName, start);
Expand Down