Skip to content

Commit

Permalink
Build(WIP): Update TypeScript to 3.4.x and RxJS to 6.5.x
Browse files Browse the repository at this point in the history
Fixes #1788
  • Loading branch information
Santosh Yadav committed Apr 27, 2019
1 parent 0e67a65 commit 0115238
Show file tree
Hide file tree
Showing 18 changed files with 821 additions and 584 deletions.
8 changes: 6 additions & 2 deletions modules/data/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ describe('Data ng-add Schematic', () => {

let appTree: UnitTestTree;

beforeEach(() => {
appTree = createWorkspace(schematicRunner, appTree);
beforeEach(done => {
createWorkspace(schematicRunner).subscribe(
tree => (appTree = tree),
done.fail,
done
);
});

it('should update package.json', () => {
Expand Down
8 changes: 6 additions & 2 deletions modules/effects/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ describe('Effect ng-add Schematic', () => {

let appTree: UnitTestTree;

beforeEach(() => {
appTree = createWorkspace(schematicRunner, appTree);
beforeEach(done => {
createWorkspace(schematicRunner).subscribe(
tree => (appTree = tree),
done.fail,
done
);
});

it('should update package.json', () => {
Expand Down
8 changes: 6 additions & 2 deletions modules/entity/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ describe('Entity ng-add Schematic', () => {

let appTree: UnitTestTree;

beforeEach(() => {
appTree = createWorkspace(schematicRunner, appTree);
beforeEach(done => {
createWorkspace(schematicRunner).subscribe(
tree => (appTree = tree),
done.fail,
done
);
});

it('should update package.json', () => {
Expand Down
8 changes: 6 additions & 2 deletions modules/router-store/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ describe('Router Store ng-add Schematic', () => {

let appTree: UnitTestTree;

beforeEach(() => {
appTree = createWorkspace(schematicRunner, appTree);
beforeEach(done => {
createWorkspace(schematicRunner).subscribe(
tree => (appTree = tree),
done.fail,
done
);
});

it('should update package.json', () => {
Expand Down
57 changes: 28 additions & 29 deletions modules/schematics-core/testing/create-workspace.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {
UnitTestTree,
SchematicTestRunner,
UnitTestTree,
} from '@angular-devkit/schematics/testing';
import { concatMap } from 'rxjs/internal/operators/concatMap';
import { Observable } from 'rxjs';

export const defaultWorkspaceOptions = {
name: 'workspace',
Expand All @@ -20,13 +22,6 @@ export const defaultAppOptions = {
skipTests: false,
};

const defaultModuleOptions = {
name: 'foo',
spec: true,
module: undefined,
flat: false,
};

const defaultLibOptions = {
name: 'baz',
};
Expand All @@ -40,28 +35,32 @@ export function getTestProjectPath(

export function createWorkspace(
schematicRunner: SchematicTestRunner,
appTree: UnitTestTree,
workspaceOptions = defaultWorkspaceOptions,
appOptions = defaultAppOptions,
libOptions = defaultLibOptions
) {
appTree = schematicRunner.runExternalSchematic(
'@schematics/angular',
'workspace',
workspaceOptions
);
appTree = schematicRunner.runExternalSchematic(
'@schematics/angular',
'application',
appOptions,
appTree
);
appTree = schematicRunner.runExternalSchematic(
'@schematics/angular',
'library',
libOptions,
appTree
);

return appTree;
): Observable<UnitTestTree> {
return schematicRunner
.runExternalSchematicAsync(
'@schematics/angular',
'workspace',
workspaceOptions
)
.pipe(
concatMap(tree =>
schematicRunner.runExternalSchematicAsync(
'@schematics/angular',
'application',
appOptions,
tree
)
),
concatMap(tree =>
schematicRunner.runExternalSchematicAsync(
'@schematics/angular',
'library',
libOptions,
tree
)
)
);
}
8 changes: 6 additions & 2 deletions modules/schematics/src/action/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ describe('Action Schematic', () => {

let appTree: UnitTestTree;

beforeEach(() => {
appTree = createWorkspace(schematicRunner, appTree);
beforeEach(done => {
createWorkspace(schematicRunner).subscribe(
tree => (appTree = tree),
done.fail,
done
);
});

it('should create an action to specified project if provided', () => {
Expand Down
18 changes: 12 additions & 6 deletions modules/schematics/src/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@ describe('CLI Schematic', () => {

let appTree: UnitTestTree;

beforeEach(() => {
appTree = createWorkspace(schematicRunner, appTree);
beforeEach(done => {
createWorkspace(schematicRunner).subscribe(
tree => (appTree = tree),
done.fail,
done
);
});

it('should create a class by the angular/cli', () => {
const options = { ...defaultOptions };
const tree = schematicRunner.runSchematic('class', options, appTree);
const content = tree.readContent(`${projectPath}/src/app/foo.ts`);

expect(content).toMatch(/export class Foo/);
schematicRunner
.runSchematicAsync('class', options, appTree)
.subscribe(tree => {
const content = tree.readContent(`${projectPath}/src/app/foo.ts`);
expect(content).toMatch(/export class Foo/);
});
});
});
109 changes: 68 additions & 41 deletions modules/schematics/src/container/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,79 +32,106 @@ describe('Container Schematic', () => {

let appTree: UnitTestTree;

beforeEach(() => {
appTree = createWorkspace(schematicRunner, appTree);
beforeEach(done => {
createWorkspace(schematicRunner).subscribe(
tree => (appTree = tree),
done.fail,
done
);
});

it('should respect the state option if not provided', () => {
const options = { ...defaultOptions, state: undefined };
const tree = schematicRunner.runSchematic('container', options, appTree);
const content = tree.readContent(
`${projectPath}/src/app/foo/foo.component.ts`
);
expect(content).not.toMatch(/import \* as fromStore/);
schematicRunner
.runSchematicAsync('container', options, appTree)
.subscribe(tree => {
const content = tree.readContent(
`${projectPath}/src/app/foo/foo.component.ts`
);
expect(content).not.toMatch(/import \* as fromStore/);
});
});

it('should import the state path if provided', () => {
const options = { ...defaultOptions, state: 'reducers' };
appTree.create(`${projectPath}/src/app/reducers`, '');
const tree = schematicRunner.runSchematic('container', options, appTree);
const content = tree.readContent(
`${projectPath}/src/app/foo/foo.component.ts`
);
expect(content).toMatch(/import \* as fromStore from '..\/reducers';/);
schematicRunner
.runSchematicAsync('container', options, appTree)
.subscribe(tree => {
const content = tree.readContent(
`${projectPath}/src/app/foo/foo.component.ts`
);
expect(content).toMatch(/import \* as fromStore from '..\/reducers';/);
});
});

it('should remove .ts from the state path if provided', () => {
const options = { ...defaultOptions, state: 'reducers/foo.ts' };
appTree.create(`${projectPath}/src/app/reducers/foo.ts`, '');
const tree = schematicRunner.runSchematic('container', options, appTree);
const content = tree.readContent(
`${projectPath}/src/app/foo/foo.component.ts`
);
expect(content).toMatch(/import \* as fromStore from '..\/reducers\/foo';/);
schematicRunner
.runSchematicAsync('container', options, appTree)
.subscribe(tree => {
const content = tree.readContent(
`${projectPath}/src/app/foo/foo.component.ts`
);
expect(content).toMatch(
/import \* as fromStore from '..\/reducers\/foo';/
);
});
});

it('should remove index.ts from the state path if provided', () => {
const options = { ...defaultOptions, state: 'reducers/index.ts' };
appTree.create(`${projectPath}/src/app/reducers/index.ts`, '');
const tree = schematicRunner.runSchematic('container', options, appTree);
const content = tree.readContent(
`${projectPath}/src/app/foo/foo.component.ts`
);
expect(content).toMatch(/import \* as fromStore from '..\/reducers';/);
schematicRunner
.runSchematicAsync('container', options, appTree)
.subscribe(tree => {
const content = tree.readContent(
`${projectPath}/src/app/foo/foo.component.ts`
);
expect(content).toMatch(/import \* as fromStore from '..\/reducers';/);
});
});

it('should import Store into the component', () => {
const options = { ...defaultOptions, state: 'reducers' };
appTree.create(`${projectPath}/src/app/reducers`, '');
const tree = schematicRunner.runSchematic('container', options, appTree);
const content = tree.readContent(
`${projectPath}/src/app/foo/foo.component.ts`
);
expect(content).toMatch(/import\ {\ Store\ }\ from\ '@ngrx\/store';/);
schematicRunner
.runSchematicAsync('container', options, appTree)
.subscribe(tree => {
const content = tree.readContent(
`${projectPath}/src/app/foo/foo.component.ts`
);
expect(content).toMatch(/import\ {\ Store\ }\ from\ '@ngrx\/store';/);
});
});

it('should update the component constructor if the state path if provided', () => {
const options = { ...defaultOptions, state: 'reducers' };
appTree.create(`${projectPath}/src/app/reducers`, '');
const tree = schematicRunner.runSchematic('container', options, appTree);
const content = tree.readContent(
`${projectPath}/src/app/foo/foo.component.ts`
);
expect(content).toMatch(
/constructor\(private store\: Store\<fromStore\.State\>\) { }\n\n/
);
schematicRunner
.runSchematicAsync('container', options, appTree)
.subscribe(tree => {
const content = tree.readContent(
`${projectPath}/src/app/foo/foo.component.ts`
);
expect(content).toMatch(
/constructor\(private store\: Store\<fromStore\.State\>\) { }\n\n/
);
});
});

it('should update the component spec', () => {
const options = { ...defaultOptions, spec: true };
const tree = schematicRunner.runSchematic('container', options, appTree);
const content = tree.readContent(
`${projectPath}/src/app/foo/foo.component.spec.ts`
);
expect(content).toMatch(
/import { Store, StoreModule } from '@ngrx\/store';/
);
schematicRunner
.runSchematicAsync('container', options, appTree)
.subscribe(tree => {
const content = tree.readContent(
`${projectPath}/src/app/foo/foo.component.spec.ts`
);
expect(content).toMatch(
/import { Store, StoreModule } from '@ngrx\/store';/
);
});
});
});
8 changes: 6 additions & 2 deletions modules/schematics/src/effect/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ describe('Effect Schematic', () => {

let appTree: UnitTestTree;

beforeEach(() => {
appTree = createWorkspace(schematicRunner, appTree);
beforeEach(done => {
createWorkspace(schematicRunner).subscribe(
tree => (appTree = tree),
done.fail,
done
);
});

it('should create an effect to specified project if provided', () => {
Expand Down
8 changes: 6 additions & 2 deletions modules/schematics/src/entity/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ describe('Entity Schematic', () => {

let appTree: UnitTestTree;

beforeEach(() => {
appTree = createWorkspace(schematicRunner, appTree);
beforeEach(done => {
createWorkspace(schematicRunner).subscribe(
tree => (appTree = tree),
done.fail,
done
);
});

it('should create 3 files', () => {
Expand Down
8 changes: 6 additions & 2 deletions modules/schematics/src/feature/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ describe('Feature Schematic', () => {

let appTree: UnitTestTree;

beforeEach(() => {
appTree = createWorkspace(schematicRunner, appTree);
beforeEach(done => {
createWorkspace(schematicRunner).subscribe(
tree => (appTree = tree),
done.fail,
done
);
});

it('should create all files of a feature', () => {
Expand Down
8 changes: 6 additions & 2 deletions modules/schematics/src/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ describe('ng-add Schematic', () => {

let appTree: UnitTestTree;

beforeEach(() => {
appTree = createWorkspace(schematicRunner, appTree);
beforeEach(done => {
createWorkspace(schematicRunner).subscribe(
tree => (appTree = tree),
done.fail,
done
);
});

it(`should leave the workspace's cli as default`, () => {
Expand Down
Loading

0 comments on commit 0115238

Please sign in to comment.