-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a9445b
commit d8a7450
Showing
75 changed files
with
543 additions
and
713 deletions.
There are no files selected for viewing
Submodule tempreponx
added at
ba31de
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
packages/store/schematics/factories/actions/actions.factory.ts
This file was deleted.
Oops, something went wrong.
76 changes: 0 additions & 76 deletions
76
packages/store/schematics/factories/ng-add/ng-add.factory.spec.ts
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
packages/store/schematics/factories/starter-kit/starter-kit.factory.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
packages/store/schematics/src/actions/actions.factory.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; | ||
import { workspaceRoot } from '@nrwl/devkit'; | ||
|
||
import * as path from 'path'; | ||
|
||
import { ActionsSchema } from './actions.schema'; | ||
|
||
describe('NGXS Actions', () => { | ||
const runner: SchematicTestRunner = new SchematicTestRunner( | ||
'.', | ||
path.join(workspaceRoot, 'packages/store/schematics/collection.json') | ||
); | ||
it('should create action in a folder by default', async () => { | ||
const options: ActionsSchema = { | ||
name: 'todos' | ||
}; | ||
const tree: UnitTestTree = await runner.runSchematicAsync('actions', options).toPromise(); | ||
const files: string[] = tree.files; | ||
expect(files).toEqual(['/todos/todos.actions.ts']); | ||
}); | ||
it('should create action without folder if "flat" is set to "true"', async () => { | ||
const options: ActionsSchema = { | ||
name: 'todos', | ||
flat: true | ||
}; | ||
const tree: UnitTestTree = await runner.runSchematicAsync('actions', options).toPromise(); | ||
const files: string[] = tree.files; | ||
expect(files).toEqual(['/todos.actions.ts']); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Rule, SchematicsException, url } from '@angular-devkit/schematics'; | ||
import { ActionsSchema } from './actions.schema'; | ||
import { generateFiles } from '../utils/generate-utils'; | ||
import { isEmpty } from '../utils/common/properties'; | ||
import { normalizeBaseOptions } from '../utils/normalize-options'; | ||
import { join } from 'path'; | ||
|
||
export function actions(options: ActionsSchema): Rule { | ||
if (isEmpty(options.name)) { | ||
throw new SchematicsException('Invalid options, "name" is required.'); | ||
} | ||
|
||
const normalizedOptions = normalizeBaseOptions(options); | ||
const path = options.flat | ||
? normalizedOptions.path | ||
: join(normalizedOptions.path, normalizedOptions.name); | ||
|
||
return generateFiles(url('./files'), path, { | ||
name: normalizedOptions.name | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
packages/store/schematics/src/ng-add/ng-add.factory.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; | ||
import { workspaceRoot } from '@nrwl/devkit'; | ||
import { join } from 'path'; | ||
import { Schema as ApplicationOptions } from '@schematics/angular/application/schema'; | ||
import { Schema as WorkspaceOptions } from '@schematics/angular/workspace/schema'; | ||
|
||
import { LIBRARIES } from '../utils/common/lib.config'; | ||
import { NgxsPackageSchema } from './ng-add.schema'; | ||
|
||
describe('Ngxs ng-add Schematic', () => { | ||
const angularSchematicRunner = new SchematicTestRunner( | ||
'@schematics/angular', | ||
join(workspaceRoot, 'node_modules/@schematics/angular/collection.json') | ||
); | ||
|
||
const ngxsSchematicRunner = new SchematicTestRunner( | ||
'@ngxs/store/schematics', | ||
join(workspaceRoot, 'packages/store/schematics/collection.json') | ||
); | ||
|
||
const defaultOptions: NgxsPackageSchema = { | ||
skipInstall: false, | ||
packages: [] | ||
}; | ||
|
||
const workspaceOptions: WorkspaceOptions = { | ||
name: 'workspace', | ||
newProjectRoot: 'projects', | ||
version: '1.0.0' | ||
}; | ||
|
||
const appOptions: ApplicationOptions = { | ||
name: 'foo', | ||
inlineStyle: false, | ||
inlineTemplate: false, | ||
routing: true, | ||
skipTests: false, | ||
skipPackageJson: false | ||
}; | ||
|
||
let appTree: UnitTestTree; | ||
beforeEach(async () => { | ||
appTree = await angularSchematicRunner | ||
.runSchematicAsync('workspace', workspaceOptions) | ||
.toPromise(); | ||
appTree = await angularSchematicRunner | ||
.runSchematicAsync('application', appOptions, appTree) | ||
.toPromise(); | ||
}); | ||
|
||
describe('importing the Ngxs module', () => { | ||
test.each` | ||
project | ||
${undefined} | ||
${'foo'} | ||
`('should import the module when project is $project ', async ({ project }) => { | ||
// Arrange | ||
const options: NgxsPackageSchema = { ...defaultOptions, project }; | ||
// Act | ||
const tree = await ngxsSchematicRunner | ||
.runSchematicAsync('ngxs-init', options, appTree) | ||
.toPromise(); | ||
// Assert | ||
const content = tree.readContent('/projects/foo/src/app/app.module.ts'); | ||
expect(content).toMatch(/import { NgxsModule } from '@ngxs\/store'/); | ||
expect(content).toMatch(/imports: \[[^\]]*NgxsModule.forRoot\(\[\],[^\]]*\]/m); | ||
expect(content).toContain( | ||
'NgxsModule.forRoot([], { developmentMode: /** !environment.production */ false, selectorOptions: { suppressErrors: false, injectContainerState: false } })' | ||
); | ||
}); | ||
it('should throw if invalid project is specified', async () => { | ||
// Arrange | ||
const options: NgxsPackageSchema = { ...defaultOptions, project: 'hello' }; | ||
await expect( | ||
ngxsSchematicRunner.runSchematicAsync('ng-add', options, appTree).toPromise() | ||
).rejects.toThrow(`Project "${options.project}" does not exist.`); | ||
}); | ||
}); | ||
|
||
describe('ng-add package in package.json', () => { | ||
it('should add ngxs store with provided plugins in package.json', async () => { | ||
const packages = [LIBRARIES.DEVTOOLS, LIBRARIES.LOGGER]; | ||
const options: NgxsPackageSchema = { packages }; | ||
appTree = await ngxsSchematicRunner | ||
.runSchematicAsync('ng-add', options, appTree) | ||
.toPromise(); | ||
const packageJsonText = appTree.readContent('/package.json'); | ||
const packageJson = JSON.parse(packageJsonText); | ||
expect(packages.every(p => !!packageJson.dependencies[p])).toBeTruthy(); | ||
}); | ||
|
||
it('should add ngxs store with all plugins in package.json', async () => { | ||
const packages = Object.values(LIBRARIES).filter(v => v !== LIBRARIES.STORE); | ||
const options: NgxsPackageSchema = { packages }; | ||
appTree = await ngxsSchematicRunner | ||
.runSchematicAsync('ng-add', options, appTree) | ||
.toPromise(); | ||
const packageJsonText = appTree.readContent('/package.json'); | ||
const packageJson = JSON.parse(packageJsonText); | ||
expect(packages.every(p => !!packageJson.dependencies[p])).toBeTruthy(); | ||
}); | ||
|
||
it('should not attempt to add non-existent package', async () => { | ||
const packages = ['who-am-i']; | ||
const options: NgxsPackageSchema = { packages }; | ||
await expect( | ||
ngxsSchematicRunner.runSchematicAsync('ng-add', options, appTree).toPromise() | ||
).rejects.toThrow(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.