Skip to content

fix(schematics): remove temp path #11198 #11424

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

Merged
merged 3 commits into from
Jun 7, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 3 additions & 7 deletions src/lib/schematics/update/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,15 @@ export default function(): Rule {
// Delete the temporary schematics directory.
context.addTask(
new RunSchematicTask('ng-post-update', {
deleteFiles: updateSrcs
.map(entry => entry.path.replace(schematicsSrcPath, schematicsTmpPath))
deletePath: schematicsTmpPath
}), [upgradeTask]);
};
}

/** Post-update schematic to be called when ng update is finished. */
export function postUpdate(options: {deleteFiles: string[]}): Rule {
export function postUpdate(options: {deletePath: string}): Rule {
return (tree: Tree, context: SchematicContext) => {
for (let file of options.deleteFiles) {
tree.delete(file);
}

tree.delete(options.deletePath);
context.addTask(new RunSchematicTask('ng-post-post-update', {}));
};
}
Expand Down
31 changes: 31 additions & 0 deletions src/lib/schematics/update/update_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {SchematicTestRunner} from '@angular-devkit/schematics/testing';
import {join} from 'path';
import {Tree} from '@angular-devkit/schematics';
import {createTestApp} from '../utils/testing';
import {getFileContent} from '@schematics/angular/utility/test';

const collectionPath = join(__dirname, '../collection.json');

describe('material-nav-schematic', () => {
let runner: SchematicTestRunner;

beforeEach(() => {
runner = new SchematicTestRunner('schematics', collectionPath);
});

it('should remove the temp directory', () => {
const tree = runner.runSchematic('update', {}, createTestApp());
const files = tree.files;

let has = false;
for (const file of files) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If files is an array, you should be able to reduce the assertion to this:

expect(files.find(file => file.includes('angular_material_schematics-'))).toBeTruthy();

if (file.indexOf('angular_material_schematics-')) {
has = true;
break;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't it be just const hasTempFile = tree.files.indexOf('angular_material_schematics-') !== -1;?


expect(has).toBe(false);
});

});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a newline at the end of the file.