Skip to content

Commit

Permalink
Build(schematics): 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
santoshyadavdev committed May 3, 2019
1 parent 00c00e0 commit b10fcd4
Showing 28 changed files with 960 additions and 650 deletions.
9 changes: 5 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -11,8 +11,8 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "213dcf7e72f3acd4d1e369b7a356f3e5d9560f380bd655b13b7c0ea425d7c419",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.27.9/rules_nodejs-0.27.9.tar.gz"],
sha256 = "3a3efbf223f6de733475602844ad3a8faa02abda25ab8cfe1d1ed0db134887cf",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.27.12/rules_nodejs-0.27.12.tar.gz"],
)

http_archive(
@@ -38,7 +38,8 @@ check_bazel_version(minimum_bazel_version = "0.24.0")

node_repositories(
node_version = "10.9.0",
yarn_version = "1.9.2",
package_json = ["//:package.json"],
yarn_version = "1.12.1",
)

yarn_install(
@@ -61,7 +62,7 @@ browser_repositories(
firefox = True,
)

load("@npm_bazel_typescript//:defs.bzl", "ts_setup_workspace")
load("@npm_bazel_typescript//:index.bzl", "ts_setup_workspace")

ts_setup_workspace()

12 changes: 8 additions & 4 deletions modules/data/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
@@ -24,8 +24,12 @@ describe('Data ng-add Schematic', () => {

let appTree: UnitTestTree;

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

it('should update package.json', () => {
@@ -260,7 +264,7 @@ describe('Data ng-add Schematic', () => {
NgrxDataModuleConfig,
Pluralizer
} from 'ngrx-data';
const customConfig: NgrxDataModuleConfig = {
root: 'api', // default root path to the server's web api
timeout: 3000, // request timeout
@@ -291,7 +295,7 @@ describe('Data ng-add Schematic', () => {
EntityDataModuleConfig,
Pluralizer
} from '@ngrx/data';
const customConfig: EntityDataModuleConfig = {
root: 'api', // default root path to the server's web api
timeout: 3000, // request timeout
8 changes: 6 additions & 2 deletions modules/effects/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
@@ -31,8 +31,12 @@ describe('Effect ng-add Schematic', () => {

let appTree: UnitTestTree;

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

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

let appTree: UnitTestTree;

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

it('should update package.json', () => {
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
@@ -23,8 +23,12 @@ describe('Router Store ng-add Schematic', () => {

let appTree: UnitTestTree;

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

it('should update package.json', () => {
1 change: 1 addition & 0 deletions modules/schematics-core/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ ts_library(
deps = [
"@npm//@angular-devkit/core",
"@npm//@angular-devkit/schematics",
"@npm//rxjs",
"@npm//typescript",
],
)
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/operators';
import { Observable } from 'rxjs';

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

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

const defaultLibOptions = {
name: 'baz',
};
@@ -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
@@ -28,8 +28,12 @@ describe('Action Schematic', () => {

let appTree: UnitTestTree;

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

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

let appTree: UnitTestTree;

beforeEach(() => {
appTree = createWorkspace(schematicRunner, appTree);
beforeEach((done: DoneFn) => {
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
@@ -32,79 +32,106 @@ describe('Container Schematic', () => {

let appTree: UnitTestTree;

beforeEach(() => {
appTree = createWorkspace(schematicRunner, appTree);
beforeEach((done: DoneFn) => {
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';/
);
});
});
});
Loading

0 comments on commit b10fcd4

Please sign in to comment.