diff --git a/package.json b/package.json index a245b9e..867af8f 100644 --- a/package.json +++ b/package.json @@ -15,11 +15,11 @@ }, "schematics": "./src/collection.json", "dependencies": { - "@angular-devkit/core": "~7.3.9", - "@angular-devkit/schematics": "~7.3.9", + "@angular-devkit/core": "~8.0.0", + "@angular-devkit/schematics": "~8.0.0", "@nativescript/tslint-rules": "~0.0.1", "@phenomnomnominal/tsquery": "^3.0.0", - "@schematics/angular": "~7.3.9", + "@schematics/angular": "~8.0.0", "tslint": "^5.16.0" }, "devDependencies": { @@ -28,7 +28,7 @@ "conventional-changelog-cli": "^2.0.1", "jasmine": "^2.8.0", "jasmine-spec-reporter": "^4.2.1", - "typescript": "3.2.4" + "typescript": "3.4.5" }, "repository": { "type": "git", diff --git a/src/add-ns/_ns-files/__sourceDir__/package.json b/src/add-ns/_ns-files/__sourceDir__/package.json index 2cbb50d..061b19d 100644 --- a/src/add-ns/_ns-files/__sourceDir__/package.json +++ b/src/add-ns/_ns-files/__sourceDir__/package.json @@ -2,7 +2,5 @@ "android": { "v8Flags": "--expose_gc" }, - "main": "<%= main %><%= nsext %>.js", - "name": "migration-ng", - "version": "4.1.0" + "main": "<%= main %><%= nsext %>.js" } diff --git a/src/add-ns/index.ts b/src/add-ns/index.ts index 65b750c..02bf19b 100644 --- a/src/add-ns/index.ts +++ b/src/add-ns/index.ts @@ -251,13 +251,18 @@ const modifyWebTsconfig = (tree: Tree, context: SchematicContext) => { const tsConfigPath = projectSettings.tsConfig; const tsConfig: any = getJsonFile(tree, tsConfigPath); + const srcDir = projectSettings.sourceRoot; + // files - const defaultFiles = ["main.ts", "polyfills.ts"]; + const defaultFiles = [ + `${srcDir}/main.ts`, + `${srcDir}/polyfills.ts`, + ]; + tsConfig.files = tsConfig.files || []; tsConfig.files.push(...defaultFiles); // paths - const srcDir = projectSettings.sourceRoot; const webPaths = { "@src/*": [ `${srcDir}/*.web`, @@ -302,16 +307,16 @@ const addDependencies = () => (tree: Tree, context: SchematicContext) => { // @UPGRADE: Update all versions whenever {N} version updates const depsToAdd = { - 'nativescript-angular': '~7.2.0', + 'nativescript-angular': '~8.0.1', 'nativescript-theme-core': '~1.0.4', 'reflect-metadata': '~0.1.12', - 'tns-core-modules': '~5.2.0' + 'tns-core-modules': '~5.4.0' }; packageJson.dependencies = Object.assign({}, depsToAdd, packageJson.dependencies); const devDepsToAdd = { - 'nativescript-dev-webpack': '^0.20.0', - '@nativescript/schematics': '~0.4.0', + 'nativescript-dev-webpack': '~0.24.0', + '@nativescript/schematics': '~0.6.0', }; packageJson.devDependencies = Object.assign({}, devDepsToAdd, packageJson.devDependencies); diff --git a/src/add-ns/index_spec.ts b/src/add-ns/index_spec.ts index 371248b..3d1c940 100644 --- a/src/add-ns/index_spec.ts +++ b/src/add-ns/index_spec.ts @@ -22,14 +22,15 @@ describe('Add {N} schematic', () => { let appTree: UnitTestTree; - beforeEach(() => { + beforeEach(async () => { appTree = new UnitTestTree(new HostTree); - appTree = setupProject(appTree, schematicRunner, project); + appTree = await setupProject(appTree, schematicRunner, project); }); describe('when using the default options', () => { - beforeEach(() => { - appTree = schematicRunner.runSchematic('add-ns', defaultOptions, appTree); + beforeEach(async () => { + appTree = await schematicRunner.runSchematicAsync('add-ns', defaultOptions, appTree) + .toPromise(); }); it('should add dependency to NativeScript schematics', () => { @@ -107,16 +108,16 @@ describe('Add {N} schematic', () => { expect(nativescript['id']).toEqual('org.nativescript.ngsample'); }); - it('should modify the tsconfig.app.json(web) to include files and path mappings', () => { - const webTsConfigPath = '/src/tsconfig.app.json'; + it('should modify the tsconfig.app.json (web) to include files and path mappings', () => { + const webTsConfigPath = '/tsconfig.app.json'; expect(appTree.files).toContain(webTsConfigPath); const webTsconfig = JSON.parse(getFileContent(appTree, webTsConfigPath)); const files = webTsconfig.files; expect(files).toBeDefined(); - expect(files.includes('main.ts')).toBeTruthy(); - expect(files.includes('polyfills.ts')).toBeTruthy(); + expect(files.includes('src/main.ts')).toBeTruthy(); + expect(files.includes('src/polyfills.ts')).toBeTruthy(); const paths = webTsconfig.compilerOptions.paths; expect(paths).toBeDefined(); @@ -148,7 +149,7 @@ describe('Add {N} schematic', () => { expect(maps).toContain("src/*.ts"); }); - it('should modify the base tsconfig.app.json to include path mappings', () => { + it('should modify the base tsconfig.json to include path mappings', () => { const baseTsConfigPath = '/tsconfig.json'; expect(appTree.files).toContain(baseTsConfigPath); @@ -186,13 +187,13 @@ describe('Add {N} schematic', () => { }); describe('when the skipAutoGeneratedComponent flag is raised', () => { - beforeEach(() => { + beforeEach(async () => { const options = { ...defaultOptions, skipAutoGeneratedComponent: true, }; - appTree = schematicRunner.runSchematic('add-ns', options, appTree); + appTree = await schematicRunner.runSchematicAsync('add-ns', options, appTree).toPromise(); }); it('should not add a sample shared component', () => { @@ -215,13 +216,13 @@ describe('Add {N} schematic', () => { }); describe('when the sample flag is raised', () => { - beforeEach(() => { + beforeEach(async () => { const options = { ...defaultOptions, sample: true, }; - appTree = schematicRunner.runSchematic('add-ns', options, appTree); + appTree = await schematicRunner.runSchematicAsync('add-ns', options, appTree).toPromise(); }); it('should generate sample files', () => { @@ -251,23 +252,23 @@ describe('Add {N} schematic', () => { }); }); -function setupProject( +async function setupProject( tree: UnitTestTree, schematicRunner: SchematicTestRunner, name: string, ) { - tree = schematicRunner.runExternalSchematic( + tree = await schematicRunner.runExternalSchematicAsync( '@schematics/angular', 'workspace', { name: 'workspace', - version: '7.0.0', + version: '8.0.0', newProjectRoot: '' } - ); + ).toPromise(); - tree = schematicRunner.runExternalSchematic( + tree = await schematicRunner.runExternalSchematicAsync( '@schematics/angular', 'application', { @@ -275,7 +276,7 @@ function setupProject( projectRoot: '' }, tree - ); + ).toPromise(); return tree; } diff --git a/src/angular-json/index_spec.ts b/src/angular-json/index_spec.ts index f5560df..04b15bd 100644 --- a/src/angular-json/index_spec.ts +++ b/src/angular-json/index_spec.ts @@ -18,8 +18,8 @@ describe('Angular JSON Config Schematic', () => { describe('with default options (name only)', () => { let tree: UnitTestTree; - beforeAll(() => { - tree = schematicRunner.runSchematic('angular-json', defaultOptions); + beforeAll(async () => { + tree = await schematicRunner.runSchematicAsync('angular-json', defaultOptions).toPromise(); }) it('should create angular.json files', () => { @@ -35,24 +35,24 @@ describe('Angular JSON Config Schematic', () => { }); }) - it('should insert the prefix option', () => { + it('should insert the prefix option', async () => { const prefix = 'custom-prefix'; - const tree = schematicRunner.runSchematic('angular-json', { ...defaultOptions, prefix }); + const tree = await schematicRunner.runSchematicAsync('angular-json', { ...defaultOptions, prefix }).toPromise(); expect(getFileContent(tree, configPath)).toContain(`"prefix": "${prefix}"`); }); - it('should insert the sourceRoot option', () => { + it('should insert the sourceRoot option', async () => { const sourceRoot = 'src'; - const tree = schematicRunner.runSchematic('angular-json', { ...defaultOptions, sourceRoot }); + const tree = await schematicRunner.runSchematicAsync('angular-json', { ...defaultOptions, sourceRoot }).toPromise(); expect(getFileContent(tree, configPath)).toContain(`"sourceRoot": "${sourceRoot}"`); }); - it('should create files inside path when specified', () => { + it('should create files inside path when specified', async () => { const path = '/path/to/my/app'; const appJsonPath = `${path}/angular.json`; const options = { ...defaultOptions, path }; - const tree = schematicRunner.runSchematic('angular-json', options); + const tree = await schematicRunner.runSchematicAsync('angular-json', options).toPromise(); expect(tree.files).toContain(appJsonPath); }); }); \ No newline at end of file diff --git a/src/convert-relative-imports/index_spec.ts b/src/convert-relative-imports/index_spec.ts index 962cfd3..60f7d2f 100644 --- a/src/convert-relative-imports/index_spec.ts +++ b/src/convert-relative-imports/index_spec.ts @@ -31,17 +31,17 @@ describe('Convert relative imports to mapped imports', () => { join(__dirname, '../collection.json') ); - it('should convert the relative imports in a newly generated file', () => { + it('should convert the relative imports in a newly generated file', async () => { let appTree = createTestProject(projSetup); appTree.create(aboutModulePath, relativeImportContent); - appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree); + appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise(); const actual = getFileContent(appTree, aboutModulePath); expect(actual).toEqual(fixedImportContent); }); - it('should convert the relative imports in a modified file', () => { + it('should convert the relative imports in a modified file', async () => { const existingContent = ` import { AboutComponent } from '${importPrefix}/about/about.component'; `; @@ -60,13 +60,13 @@ describe('Convert relative imports to mapped imports', () => { }]); appTree.overwrite(aboutModulePath, modifiedContent); - appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree); + appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise(); const actual = getFileContent(appTree, aboutModulePath); expect(actual).toEqual(expected); }); - it('should convert the relative imports in a created and then renamed file', () => { + it('should convert the relative imports in a created and then renamed file', async () => { let appTree = createTestProject(projSetup); const renamedFilePath = aboutModulePath.replace(".ts", ".tns.ts"); @@ -74,71 +74,71 @@ describe('Convert relative imports to mapped imports', () => { appTree.create(aboutModulePath, relativeImportContent); appTree.rename(aboutModulePath, renamedFilePath); - appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree); + appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise(); const actual = getFileContent(appTree, renamedFilePath); expect(actual).toEqual(fixedImportContent); }); - it('should not modify files that weren\'t modified', () => { + it('should not modify files that weren\'t modified', async () => { let appTree = createTestProject(projSetup, [{ path: aboutModulePath, content: relativeImportContent }]); - appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree); + appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise(); const actual = getFileContent(appTree, aboutModulePath); expect(actual).toEqual(relativeImportContent); }); - it('should not modify files with extension other than .ts', () => { + it('should not modify files with extension other than .ts', async () => { let appTree = createTestProject(projSetup); const generatedFilePath = `${sourceDirectory}/about/about.component.tsx`; appTree.create(generatedFilePath, relativeImportContent); - appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree); + appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise(); const actual = getFileContent(appTree, generatedFilePath); expect(actual).toEqual(relativeImportContent); }); - it('should not modify files specified as ignored in the invocation options', () => { + it('should not modify files specified as ignored in the invocation options', async () => { let appTree = createTestProject(projSetup); appTree.create(aboutModulePath, relativeImportContent); const options: ConvertRelativeImportsOptions = { ...defaultOptions, filesToIgnore: [aboutModulePath] }; - appTree = schematicRunner.runSchematic('convert-relative-imports', options, appTree); + appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', options, appTree).toPromise(); const actual = getFileContent(appTree, aboutModulePath); expect(actual).toEqual(relativeImportContent); }); - it('should not modify files that are deleted by previous rules', () => { + it('should not modify files that are deleted by previous rules', async () => { let appTree = createTestProject(projSetup, [{ path: aboutModulePath, content: relativeImportContent }]); appTree.delete(aboutModulePath); - appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree); + appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise(); expect(appTree.get(aboutModulePath)).toBeNull(); }); - it('should not modify files that were created and then deleted by previous rules', () => { + it('should not modify files that were created and then deleted by previous rules', async () => { let appTree = createTestProject(projSetup); appTree.create(aboutModulePath, relativeImportContent); appTree.delete(aboutModulePath); - appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree); + appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise(); expect(appTree.get(aboutModulePath)).toBeNull(); }); - it('should not modify files that were modified and then deleted by previous rules', () => { + it('should not modify files that were modified and then deleted by previous rules', async () => { let appTree = createTestProject(projSetup, [{ path: aboutModulePath, @@ -147,7 +147,7 @@ describe('Convert relative imports to mapped imports', () => { appTree.overwrite(aboutModulePath, relativeImportContent + '\nconsole.log(\'modified\');\n'); appTree.delete(aboutModulePath); - appTree = schematicRunner.runSchematic('convert-relative-imports', defaultOptions, appTree); + appTree = await schematicRunner.runSchematicAsync('convert-relative-imports', defaultOptions, appTree).toPromise(); expect(appTree.get(aboutModulePath)).toBeNull(); }); diff --git a/src/generate/component/index_spec.ts b/src/generate/component/index_spec.ts index ebb2045..0d5a954 100644 --- a/src/generate/component/index_spec.ts +++ b/src/generate/component/index_spec.ts @@ -60,12 +60,12 @@ describe('Component Schematic', () => { expect(content).toMatch(/Button/); }; - describe('when in ns-only project', () => { - beforeAll(() => { + describe('when in ns-only project', async () => { + beforeAll(async () => { appTree = createEmptyNsOnlyProject(project); const options = { ...defaultOptions, nativescript: true, web: false }; - appTree = schematicRunner.runSchematic('component', options, appTree); + appTree = await schematicRunner.runSchematicAsync('component', options, appTree).toPromise(); }); it('should create template without extension', () => @@ -93,11 +93,11 @@ describe('Component Schematic', () => { const componentPath = `src/app/${homeDir}/${name}/${name}.component.ts`; const templatePath = `src/app/${homeDir}/${name}/${name}.component.html`; - beforeAll(() => { + beforeAll(async () => { appTree = createEmptyNsOnlyProject(project); const options = { ...defaultOptions, name: componentName, nativescript: true, web: false }; - appTree = schematicRunner.runSchematic('component', options, appTree); + appTree = await schematicRunner.runSchematicAsync('component', options, appTree).toPromise(); }); it('should create component in the home folder', () => @@ -114,11 +114,11 @@ describe('Component Schematic', () => { describe('when in ns+web project', () => { describe('executing ns+web schematic', () => { - beforeAll(() => { + beforeAll(async () => { appTree = createEmptySharedProject(project); const options = { ...defaultOptions, web: true, nativescript: true }; - appTree = schematicRunner.runSchematic('component', options, appTree); + appTree = await schematicRunner.runSchematicAsync('component', options, appTree).toPromise(); }); it('should add web-specific markup file', () => ensureWebTemplate(appTree, webTemplatePath)); @@ -159,11 +159,11 @@ describe('Component Schematic', () => { }) describe('executing ns-only schematic', () => { - beforeAll(() => { + beforeAll(async () => { appTree = createEmptySharedProject(project); const options = { ...defaultOptions, web: false, nativescript: true }; - appTree = schematicRunner.runSchematic('component', options, appTree); + appTree = await schematicRunner.runSchematicAsync('component', options, appTree).toPromise(); }); it('should add {N}-specific markup file', () => ensureNsTemplate(appTree, nsTemplatePath)); @@ -183,11 +183,11 @@ describe('Component Schematic', () => { }) describe('executing web-only schematic', () => { - beforeAll(() => { + beforeAll(async () => { appTree = createEmptySharedProject(project); const options = { ...defaultOptions, web: true, nativescript: false }; - appTree = schematicRunner.runSchematic('component', options, appTree); + appTree = await schematicRunner.runSchematicAsync('component', options, appTree).toPromise(); }); it('should add web-specific markup file', () => ensureWebTemplate(appTree, webTemplatePath)); @@ -212,9 +212,9 @@ describe('Component Schematic', () => { appTree = createEmptyNsOnlyProject(project, customExtension); }); - it('should respect specified {N} extension', () => { + it('should respect specified {N} extension', async () => { const options = { ...defaultOptions, nsExtension: customExtension, nativescript: true }; - appTree = schematicRunner.runSchematic('component', options, appTree); + appTree = await schematicRunner.runSchematicAsync('component', options, appTree).toPromise(); const componentTemplatePath = getTemplatePath(customExtension); expect(appTree.exists(componentTemplatePath)).toBeTruthy(); @@ -223,10 +223,10 @@ describe('Component Schematic', () => { expect(appTree.exists(componentStylesheetPath)).toBeTruthy(); }); - it('should respect specified style extension', () => { + it('should respect specified style extension', async () => { const styleext = 'scss'; const options = { ...defaultOptions, nsExtension: customExtension, styleext, nativescript: true }; - appTree = schematicRunner.runSchematic('component', options, appTree); + appTree = await schematicRunner.runSchematicAsync('component', options, appTree).toPromise(); const componentStylesheetPath = getStylesheetPath(customExtension, styleext); expect(appTree.exists(componentStylesheetPath)).toBeTruthy(); @@ -242,17 +242,17 @@ describe('Component Schematic', () => { appTree = createEmptySharedProject(project, customExtension, '.tns'); }); - it('should create the files with this extension', () => { + it('should create the files with this extension', async () => { const options = { ...componentOptions }; - appTree = schematicRunner.runSchematic('component', options, appTree); + appTree = await schematicRunner.runSchematicAsync('component', options, appTree).toPromise(); const componentTemplatePath = getTemplatePath(customExtension); expect(appTree.exists(componentTemplatePath)).toBeTruthy(); }); - it('should declare in NgModule', () => { + it('should declare in NgModule', async () => { const options = { ...componentOptions }; - appTree = schematicRunner.runSchematic('component', options, appTree); + appTree = await schematicRunner.runSchematicAsync('component', options, appTree).toPromise(); const webModulePath = `src/app/app.module${customExtension}.ts`; const nsModulePath = `src/app/app.module.tns.ts`; @@ -265,18 +265,18 @@ describe('Component Schematic', () => { expect(nsModuleContent).toMatch(matcher); }); - it('should respect the module option', () => { + it('should respect the module option', async () => { const moduleName = 'random'; const webModulePath = `src/app/${moduleName}/${moduleName}.module${customExtension}.ts`; const nsModulePath = `src/app/${moduleName}/${moduleName}.module.tns.ts`; - appTree = schematicRunner.runSchematic('module', { + appTree = await schematicRunner.runSchematicAsync('module', { project, name: moduleName, webExtension: customExtension, - }, appTree); + }, appTree).toPromise(); const options = { ...componentOptions, module: moduleName }; - appTree = schematicRunner.runSchematic('component', options, appTree); + appTree = await schematicRunner.runSchematicAsync('component', options, appTree).toPromise(); const matcher = isInModuleMetadata('RandomModule', 'declarations', componentClassName, true); @@ -296,9 +296,9 @@ describe('Component Schematic', () => { appTree = createEmptySharedProject(project, '', customExtension); }); - it('should create the files with this extension', () => { + it('should create the files with this extension', async () => { const options = { ...componentOptions }; - appTree = schematicRunner.runSchematic('component', options, appTree); + appTree = await schematicRunner.runSchematicAsync('component', options, appTree).toPromise(); const componentTemplatePath = getTemplatePath(customExtension); expect(appTree.exists(componentTemplatePath)).toBeTruthy(); @@ -307,9 +307,9 @@ describe('Component Schematic', () => { expect(appTree.exists(componentStylesheetPath)).toBeTruthy(); }); - it('should declare in NgModule', () => { + it('should declare in NgModule', async () => { const options = { ...componentOptions }; - appTree = schematicRunner.runSchematic('component', options, appTree); + appTree = await schematicRunner.runSchematicAsync('component', options, appTree).toPromise(); const webModulePath = `src/app/app.module.ts`; const nsModulePath = `src/app/app.module${customExtension}.ts`; @@ -322,18 +322,18 @@ describe('Component Schematic', () => { expect(nsModuleContent).toMatch(matcher); }); - it('should respect the module option', () => { + it('should respect the module option', async () => { const moduleName = 'random'; const webModulePath = `src/app/${moduleName}/${moduleName}.module.ts`; const nsModulePath = `src/app/${moduleName}/${moduleName}.module${customExtension}.ts`; - appTree = schematicRunner.runSchematic('module', { + appTree = await schematicRunner.runSchematicAsync('module', { project, name: moduleName, nsExtension: customExtension, - }, appTree); + }, appTree).toPromise(); const options = { ...componentOptions, module: moduleName }; - appTree = schematicRunner.runSchematic('component', options, appTree); + appTree = await schematicRunner.runSchematicAsync('component', options, appTree).toPromise(); const matcher = isInModuleMetadata('RandomModule', 'declarations', componentClassName, true); @@ -354,9 +354,9 @@ describe('Component Schematic', () => { appTree = createEmptySharedProject(project, webExtension, nsExtension); }); - it('should create the files with these extensions', () => { + it('should create the files with these extensions', async () => { const options = { ...componentOptions }; - appTree = schematicRunner.runSchematic('component', options, appTree); + appTree = await schematicRunner.runSchematicAsync('component', options, appTree).toPromise(); const nsTemplate = getTemplatePath(nsExtension); const webTemplate = getTemplatePath(webExtension); @@ -369,9 +369,9 @@ describe('Component Schematic', () => { expect(appTree.exists(webStylesheet)).toBeTruthy(); }); - it('should declare in NgModule', () => { + it('should declare in NgModule', async () => { const options = { ...componentOptions }; - appTree = schematicRunner.runSchematic('component', options, appTree); + appTree = await schematicRunner.runSchematicAsync('component', options, appTree).toPromise(); const webModulePath = `src/app/app.module${webExtension}.ts`; const nsModulePath = `src/app/app.module${nsExtension}.ts`; @@ -384,19 +384,19 @@ describe('Component Schematic', () => { expect(nsModuleContent).toMatch(matcher); }); - it('should respect the module option', () => { + it('should respect the module option', async () => { const moduleName = 'random'; const webModulePath = `src/app/${moduleName}/${moduleName}.module${webExtension}.ts`; const nsModulePath = `src/app/${moduleName}/${moduleName}.module${nsExtension}.ts`; - appTree = schematicRunner.runSchematic('module', { + appTree = await schematicRunner.runSchematicAsync('module', { project, name: moduleName, webExtension, nsExtension, - }, appTree); + }, appTree).toPromise(); const options = { ...componentOptions, module: moduleName }; - appTree = schematicRunner.runSchematic('component', options, appTree); + appTree = await schematicRunner.runSchematicAsync('component', options, appTree).toPromise(); const matcher = isInModuleMetadata('RandomModule', 'declarations', componentClassName, true); diff --git a/src/generate/module/index_spec.ts b/src/generate/module/index_spec.ts index 2ebcfa8..a1474b5 100644 --- a/src/generate/module/index_spec.ts +++ b/src/generate/module/index_spec.ts @@ -41,8 +41,8 @@ describe('Module Schematic', () => { var tree: UnitTestTree; describe('with default options', () => { - beforeEach(() => { - tree = schematicRunner.runSchematic('module', defaultOptions, appTree); + beforeEach(async () => { + tree = await schematicRunner.runSchematicAsync('module', defaultOptions, appTree).toPromise(); }); it('should create tns module file with no extension', () => { @@ -82,10 +82,10 @@ describe('Module Schematic', () => { }); }) - it('should respect passed extension', () => { + it('should respect passed extension', async () => { const customExtension = '.mobile'; const options = { ...defaultOptions, routing: true, nsExtension: customExtension }; - tree = schematicRunner.runSchematic('module', options, appTree); + tree = await schematicRunner.runSchematicAsync('module', options, appTree).toPromise(); const modulePath = getModulePath(customExtension); expect(tree.exists(modulePath)).toBeTruthy(); @@ -94,17 +94,17 @@ describe('Module Schematic', () => { expect(tree.exists(routingModulePath)).toBeTruthy(); }); - it('should not have NativeScriptCommonModule imported if that is specified explicitly', () => { + it('should not have NativeScriptCommonModule imported if that is specified explicitly', async () => { const options = { ...defaultOptions, commonModule: false }; - const tree = schematicRunner.runSchematic('module', options, appTree); + const tree = await schematicRunner.runSchematicAsync('module', options, appTree).toPromise(); const content = getFileContent(tree, noExtensionModulePath); expect(content).not.toMatch(`import { NativeScriptCommonModule } from 'nativescript-angular/common'`); }); - it('should not have RouterModule imported in the routing module', () => { + it('should not have RouterModule imported in the routing module', async () => { const options = { ...defaultOptions, routing: true }; - const tree = schematicRunner.runSchematic('module', options, appTree); + const tree = await schematicRunner.runSchematicAsync('module', options, appTree).toPromise(); const content = getFileContent(tree, noExtensionModulePath); expect(content).not.toMatch(`import { RouterModule } from '@angular/router'`); @@ -116,9 +116,9 @@ describe('Module Schematic', () => { isInModuleMetadata(moduleClassName, 'exports', 'RouterModule', true)); }); - it('should have NativeScriptRouterModule imported', () => { + it('should have NativeScriptRouterModule imported', async () => { const options = { ...defaultOptions, routing: true }; - const tree = schematicRunner.runSchematic('module', options, appTree); + const tree = await schematicRunner.runSchematicAsync('module', options, appTree).toPromise(); const content = getFileContent(tree, noExtensionRoutingModulePath); expect(content).toMatch(`import { NativeScriptRouterModule } from 'nativescript-angular/router'`); @@ -134,33 +134,33 @@ describe('Module Schematic', () => { describe('executing ns-only schematic', () => { const nsOnlyOptions = { ...defaultOptions, nativescript: true, web: false }; - it('should create ns module file', () => { + it('should create ns module file', async () => { const options = { ...nsOnlyOptions }; - const tree = schematicRunner.runSchematic('module', options, appTree); + const tree = await schematicRunner.runSchematicAsync('module', options, appTree).toPromise(); expect(tree.files).toContain(nsModulePath); expect(getFileContent(tree, nsModulePath)).toContain('CommonModule'); expect(getFileContent(tree, nsModulePath)).toContain(`class ${moduleClassName}`); }); - it('should not create web module file', () => { + it('should not create web module file', async () => { const options = { ...nsOnlyOptions }; - const tree = schematicRunner.runSchematic('module', options, appTree); + const tree = await schematicRunner.runSchematicAsync('module', options, appTree).toPromise(); expect(tree.exists(webModulePath)).toBeFalsy(); }); - it('should not create a common file', () => { + it('should not create a common file', async () => { const options = { ...nsOnlyOptions }; - const tree = schematicRunner.runSchematic('module', options, appTree); + const tree = await schematicRunner.runSchematicAsync('module', options, appTree).toPromise(); expect(tree.exists(commonFilePath)).toBeFalsy(); }); - it('should respect passed extension', () => { + it('should respect passed extension', async () => { const customExtension = '.mobile'; const options = { ...nsOnlyOptions, nsExtension: customExtension, routing: true }; - const tree = schematicRunner.runSchematic('module', options, appTree); + const tree = await schematicRunner.runSchematicAsync('module', options, appTree).toPromise(); const modulePath = getModulePath(customExtension); expect(tree.exists(modulePath)).toBeTruthy(); @@ -173,33 +173,33 @@ describe('Module Schematic', () => { describe('executing web-only schematic', () => { const webOnlyOptions = { ...defaultOptions, nativescript: false, web: true }; - it('should create web module file', () => { + it('should create web module file', async () => { const options = { ...webOnlyOptions }; - const tree = schematicRunner.runSchematic('module', options, appTree); + const tree = await schematicRunner.runSchematicAsync('module', options, appTree).toPromise(); expect(tree.files).toContain(webModulePath); expect(getFileContent(tree, webModulePath)).toContain('CommonModule'); expect(getFileContent(tree, webModulePath)).toContain(`class ${moduleClassName}`); }); - it('should not create ns module file', () => { + it('should not create ns module file', async () => { const options = { ...webOnlyOptions }; - const tree = schematicRunner.runSchematic('module', options, appTree); + const tree = await schematicRunner.runSchematicAsync('module', options, appTree).toPromise(); expect(tree.exists(nsModulePath)).toBeFalsy(); }); - it('should not create a common file', () => { + it('should not create a common file', async () => { const options = { ...webOnlyOptions }; - const tree = schematicRunner.runSchematic('module', options, appTree); + const tree = await schematicRunner.runSchematicAsync('module', options, appTree).toPromise(); expect(tree.exists(commonFilePath)).toBeFalsy(); }); - it('should respect passed extension', () => { + it('should respect passed extension', async () => { const customExtension = '.web'; const options = { ...webOnlyOptions, webExtension: customExtension, routing: true }; - const tree = schematicRunner.runSchematic('module', options, appTree); + const tree = await schematicRunner.runSchematicAsync('module', options, appTree).toPromise(); const modulePath = getModulePath(customExtension); expect(tree.exists(modulePath)).toBeTruthy(); @@ -216,32 +216,32 @@ describe('Module Schematic', () => { web: true, }; - it('should generate both web and ns module files', () => { + it('should generate both web and ns module files', async () => { const options = { ...nsWebOptions }; - const tree = schematicRunner.runSchematic('module', options, appTree); + const tree = await schematicRunner.runSchematicAsync('module', options, appTree).toPromise(); expect(tree.exists(nsModulePath)).toBeTruthy(); expect(tree.exists(webModulePath)).toBeTruthy(); }); - it('should not create a common file', () => { + it('should not create a common file', async () => { const options = { ...nsWebOptions }; - const tree = schematicRunner.runSchematic('module', options, appTree); + const tree = await schematicRunner.runSchematicAsync('module', options, appTree).toPromise(); expect(tree.exists(commonFilePath)).toBeTruthy(); }); - it('should create both routing modules when routing flag is passed', () => { + it('should create both routing modules when routing flag is passed', async () => { const options = { ...nsWebOptions, routing: true }; - const tree = schematicRunner.runSchematic('module', options, appTree); + const tree = await schematicRunner.runSchematicAsync('module', options, appTree).toPromise(); expect(tree.exists(nsRoutingModulePath)).toBeTruthy(); expect(tree.exists(webRoutingModulePath)).toBeTruthy(); }); - it('should respect passed extension', () => { + it('should respect passed extension', async () => { const nsExtension = '.mobile'; const webExtension = '.web'; const options = { ...nsWebOptions, nsExtension, webExtension, routing: true }; - const tree = schematicRunner.runSchematic('module', options, appTree); + const tree = await schematicRunner.runSchematicAsync('module', options, appTree).toPromise(); const webModulePath = getModulePath(webExtension); const nsModulePath = getModulePath(nsExtension); diff --git a/src/migrate-component/index_spec.ts b/src/migrate-component/index_spec.ts index ffcc154..3eeae09 100644 --- a/src/migrate-component/index_spec.ts +++ b/src/migrate-component/index_spec.ts @@ -39,13 +39,14 @@ describe('Migrate component schematic', () => { const htmlComponentPath = `/src/app/${componentName}/${componentName}.component.html`; const xmlComponentPath = `/src/app/${componentName}/${componentName}.component.tns.html`; - beforeEach(() => { - appTree = schematicRunner.runSchematic('component', { + beforeEach(async () => { + appTree = await schematicRunner.runSchematicAsync('component', { name: componentName, nativescript: false, web: true, project, - }, appTree); + }, appTree) + .toPromise(); appTree = schematicRunner.runSchematic('migrate-component', options, appTree); }); @@ -89,19 +90,21 @@ describe('Migrate component schematic', () => { const htmlComponentPath = `/src/app/${componentName}/${componentName}.component.html`; const xmlComponentPath = `/src/app/${componentName}/${componentName}.component.tns.html`; - beforeEach(() => { - appTree = schematicRunner.runSchematic('module', { + beforeEach(async () => { + appTree = await schematicRunner.runSchematicAsync('module', { project, name: moduleName, - }, appTree); + }, appTree) + .toPromise(); - appTree = schematicRunner.runSchematic('component', { + appTree = await schematicRunner.runSchematicAsync('component', { project, nativescript: false, web: true, name: componentName, module: moduleName, - }, appTree); + }, appTree) + .toPromise(); appTree = schematicRunner.runSchematic('migrate-component', { ...options }, appTree); diff --git a/src/migrate-module/index_spec.ts b/src/migrate-module/index_spec.ts index 897ae63..5100a85 100644 --- a/src/migrate-module/index_spec.ts +++ b/src/migrate-module/index_spec.ts @@ -30,15 +30,16 @@ describe('Migrate module Schematic', () => { ); let appTree: UnitTestTree; - beforeEach(() => { + beforeEach(async () => { appTree = new UnitTestTree(new HostTree); - appTree = setupProject(appTree, schematicRunner, project, moduleName); + appTree = await setupProject(appTree, schematicRunner, project, moduleName); }); describe('When the name of existing module is provided', () => { - beforeEach(() => { + beforeEach(async () => { const options = { ...defaultOptions }; - appTree = schematicRunner.runSchematic('migrate-module', options, appTree); + appTree = await schematicRunner.runSchematicAsync('migrate-module', options, appTree) + .toPromise(); }); it('should create a mobile module file', () => { @@ -51,9 +52,10 @@ describe('Migrate module Schematic', () => { }); describe('When a custom mobile extension is provided', () => { - beforeEach(() => { + beforeEach(async () => { const options: MigrateModuleOptions = { ...defaultOptions, nsext: 'mobile' }; - appTree = schematicRunner.runSchematic('migrate-module', options, appTree); + appTree = await schematicRunner.runSchematicAsync('migrate-module', options, appTree) + .toPromise(); }); it('should create the module file with that extension', () => { @@ -67,18 +69,20 @@ describe('Migrate module Schematic', () => { describe('When the module has a component', () => { let originalWebModuleContent: string; - beforeEach(() => { - appTree = schematicRunner.runSchematic('component', { + beforeEach(async () => { + appTree = await schematicRunner.runSchematicAsync('component', { name: 'a', module: moduleName, project, nativescript: false, - }, appTree); + }, appTree) + .toPromise(); originalWebModuleContent = getFileContent(appTree, webModulePath); const options: MigrateModuleOptions = { ...defaultOptions }; - appTree = schematicRunner.runSchematic('migrate-module', options, appTree); + appTree = await schematicRunner.runSchematicAsync('migrate-module', options, appTree) + .toPromise(); }); it('should keep the web module untouched', () => { @@ -106,11 +110,12 @@ describe('Migrate module Schematic', () => { describe('When the module has a provider', () => { const provider = 'SomeProvider'; let originalWebModuleContent: string; - beforeEach(() => { + beforeEach(async () => { appTree = insertProviderInMetadata(appTree, webModulePath, provider); originalWebModuleContent = getFileContent(appTree, webModulePath); const options: MigrateModuleOptions = { ...defaultOptions }; - appTree = schematicRunner.runSchematic('migrate-module', options, appTree); + appTree = await schematicRunner.runSchematicAsync('migrate-module', options, appTree) + .toPromise(); }); it('should keep the web module untouched', () => { @@ -128,28 +133,30 @@ describe('Migrate module Schematic', () => { }); }); -const setupProject = ( +const setupProject = async ( appTree: UnitTestTree, schematicRunner: SchematicTestRunner, project: string, moduleName: string, ) => { - appTree = schematicRunner.runSchematic('shared', { + appTree = await schematicRunner.runSchematicAsync('shared', { name: project, prefix: '', sourceDir: 'src', style: 'css', theme: true, sample: false, - }, appTree); + }, appTree) + .toPromise(); appTree = moveToRoot(schematicRunner, appTree, project); - appTree = schematicRunner.runSchematic('module', { + appTree = await schematicRunner.runSchematicAsync('module', { name: moduleName, nativescript: false, web: true, project, - }, appTree); + }, appTree) + .toPromise(); return appTree; }; diff --git a/src/ng-new/application/_files/package.json b/src/ng-new/application/_files/package.json index 018d9a6..59c9583 100644 --- a/src/ng-new/application/_files/package.json +++ b/src/ng-new/application/_files/package.json @@ -6,30 +6,29 @@ "id": "org.nativescript.<%= utils.sanitize(name) %>" }, "dependencies": { - "@angular/animations": "~7.2.0", - "@angular/common": "~7.2.0", - "@angular/compiler": "~7.2.0", - "@angular/core": "~7.2.0", - "@angular/forms": "~7.2.0", - "@angular/http": "~7.2.0", - "@angular/platform-browser": "~7.2.0", - "@angular/platform-browser-dynamic": "~7.2.0", - "@angular/router": "~7.2.0", - "nativescript-angular": "~7.2.0",<% if(theme) { %> + "@angular/animations": "~8.0.1", + "@angular/common": "~8.0.1", + "@angular/compiler": "~8.0.1", + "@angular/core": "~8.0.1", + "@angular/forms": "~8.0.1", + "@angular/http": "~8.0.0-beta.10", + "@angular/platform-browser": "~8.0.1", + "@angular/platform-browser-dynamic": "~8.0.1", + "@angular/router": "~8.0.1", + "nativescript-angular": "~8.0.1",<% if(theme) { %> "nativescript-theme-core": "~1.0.4", <% } %>"reflect-metadata": "~0.1.12", - "rxjs": "~6.3.3", - "tns-core-modules": "~5.2.0", - "zone.js": "^0.8.26" + "rxjs": "~6.4.0", + "tns-core-modules": "~5.4.0", + "zone.js": "~0.9.1" }, "devDependencies": { - "@angular/cli": "^7.2.0", - "@angular/compiler-cli": "~7.2.0", - "@angular-devkit/core": "~7.2.0", - "@nativescript/schematics": "~0.4.0", - "nativescript-dev-typescript": "~0.8.0",<% if(webpack) { %> - "nativescript-dev-webpack": "^0.20.0", - "@ngtools/webpack": "~7.2.0", - <% } %>"typescript": "~3.1.1" + "@angular/cli": "^8.0.3", + "@angular/compiler-cli": "~8.0.1", + "@angular-devkit/core": "~8.0.1", + "@nativescript/schematics": "~0.6.0",<% if(webpack) { %> + "nativescript-dev-webpack": "~0.24.0", + "@ngtools/webpack": "~8.0.3", + <% } %>"typescript": "~3.4.3" } } diff --git a/src/ng-new/application/index_spec.ts b/src/ng-new/application/index_spec.ts index 578e686..7351ee5 100644 --- a/src/ng-new/application/index_spec.ts +++ b/src/ng-new/application/index_spec.ts @@ -19,10 +19,10 @@ describe('Application Schematic', () => { webpack: true, }; - it('should create all files of an application', () => { + it('should create all files of an application', async () => { const options = { ...defaultOptions }; - const tree = schematicRunner.runSchematic('application', options); + const tree = await schematicRunner.runSchematicAsync('application', options).toPromise(); const files = tree.files; expect(files).toContain('/foo/angular.json'); expect(files).toContain('/foo/nsconfig.json'); @@ -41,9 +41,9 @@ describe('Application Schematic', () => { expect(files).toContain('/foo/app/home/home.component.css'); }); - it('should create root NgModule with bootstrap information', () => { + it('should create root NgModule with bootstrap information', async () => { const options = { ...defaultOptions }; - const tree = schematicRunner.runSchematic('application', options); + const tree = await schematicRunner.runSchematicAsync('application', options).toPromise(); const content = getFileContent(tree, '/foo/app/app.module.ts'); expect(content).toMatch(isInModuleMetadata('AppModule', 'bootstrap', 'AppComponent', true)); diff --git a/src/ng-new/shared/_files/angular.json b/src/ng-new/shared/_files/angular.json index a6ff159..8b974ee 100644 --- a/src/ng-new/shared/_files/angular.json +++ b/src/ng-new/shared/_files/angular.json @@ -24,7 +24,7 @@ "index": "<%= sourcedir %>/index.html", "main": "<%= sourcedir %>/main.ts", "polyfills": "<%= sourcedir %>/polyfills.ts", - "tsConfig": "<%= sourcedir %>/tsconfig.app.json", + "tsConfig": "tsconfig.app.json", "assets": [ "<%= sourcedir %>/favicon.ico", "<%= sourcedir %>/assets" @@ -76,8 +76,8 @@ "options": { "main": "<%= sourcedir %>/test.ts", "polyfills": "<%= sourcedir %>/polyfills.ts", - "tsConfig": "<%= sourcedir %>/tsconfig.spec.json", - "karmaConfig": "<%= sourcedir %>/karma.conf.js", + "tsConfig": "tsconfig.spec.json", + "karmaConfig": "karma.conf.js", "styles": [ "<%= sourcedir %>/styles.<%= style %>" ], @@ -92,8 +92,8 @@ "builder": "@angular-devkit/build-angular:tslint", "options": { "tsConfig": [ - "<%= sourcedir %>/tsconfig.app.json", - "<%= sourcedir %>/tsconfig.spec.json" + "tsconfig.app.json", + "tsconfig.spec.json" ], "exclude": [ "**/node_modules/**" diff --git a/src/ng-new/shared/_files/__sourcedir__/karma.conf.js b/src/ng-new/shared/_files/karma.conf.js similarity index 100% rename from src/ng-new/shared/_files/__sourcedir__/karma.conf.js rename to src/ng-new/shared/_files/karma.conf.js diff --git a/src/ng-new/shared/_files/package.json b/src/ng-new/shared/_files/package.json index 0d03569..35e44b2 100644 --- a/src/ng-new/shared/_files/package.json +++ b/src/ng-new/shared/_files/package.json @@ -18,43 +18,43 @@ }, "private": true, "dependencies": { - "@angular/animations": "~7.2.0", - "@angular/common": "~7.2.0", - "@angular/compiler": "~7.2.0", - "@angular/core": "~7.2.0", - "@angular/forms": "~7.2.0", - "@angular/http": "~7.2.0", - "@angular/platform-browser": "~7.2.0", - "@angular/platform-browser-dynamic": "~7.2.0", - "@angular/router": "~7.2.0", + "@angular/animations": "~8.0.1", + "@angular/common": "~8.0.1", + "@angular/compiler": "~8.0.1", + "@angular/core": "~8.0.1", + "@angular/forms": "~8.0.1", + "@angular/http": "~8.0.0-beta.10", + "@angular/platform-browser": "~8.0.1", + "@angular/platform-browser-dynamic": "~8.0.1", + "@angular/router": "~8.0.1", "core-js": "^2.5.4", - "nativescript-angular": "~7.2.0",<% if(theme) { %> + "nativescript-angular": "~8.0.1",<% if(theme) { %> "nativescript-theme-core": "~1.0.4", <% } %>"reflect-metadata": "~0.1.12", - "rxjs": "~6.3.3", - "tns-core-modules": "~5.2.0", - "zone.js": "^0.8.26" + "rxjs": "~6.4.0", + "tns-core-modules": "~5.4.0", + "zone.js": "~0.9.1" }, "devDependencies": { - "@angular/cli": "^7.2.0", - "@angular/compiler-cli": "~7.2.0", - "@angular-devkit/build-angular": "~0.11.4", - "@nativescript/schematics": "~0.4.0", - "@types/jasmine": "2.8.6", + "@angular/cli": "~8.0.3", + "@angular/compiler-cli": "~8.0.1", + "@angular-devkit/build-angular": "~0.800.0", + "@nativescript/schematics": "~0.6.0", + "@types/jasmine": "~3.3.8", "@types/jasminewd2": "~2.0.3", "@types/node": "~8.9.4", - "codelyzer": "~4.2.1", - "jasmine-core": "~2.99.1", + "codelyzer": "^5.0.0", + "jasmine-core": "~3.4.0", "jasmine-spec-reporter": "~4.2.1", - "karma": "~1.7.1", + "karma": "~4.1.0", "karma-chrome-launcher": "~2.2.0", - "karma-coverage-istanbul-reporter": "~2.0.0", - "karma-jasmine": "~1.1.1", - "karma-jasmine-html-reporter": "^0.2.2", - "nativescript-dev-webpack": "^0.20.0", - "protractor": "~5.3.0", - "ts-node": "~5.0.1", - "tslint": "~5.9.1", - "typescript": "~3.1.1" + "karma-coverage-istanbul-reporter": "~2.0.1", + "karma-jasmine": "~2.0.1", + "karma-jasmine-html-reporter": "^1.4.0", + "nativescript-dev-webpack": "~0.24.0", + "protractor": "~5.4.0", + "ts-node": "~7.0.0", + "tslint": "~5.15.0", + "typescript": "~3.4.3" } -} \ No newline at end of file +} diff --git a/src/ng-new/shared/_files/__sourcedir__/tsconfig.app.json b/src/ng-new/shared/_files/tsconfig.app.json similarity index 69% rename from src/ng-new/shared/_files/__sourcedir__/tsconfig.app.json rename to src/ng-new/shared/_files/tsconfig.app.json index 7d7f000..a1cbea2 100644 --- a/src/ng-new/shared/_files/__sourcedir__/tsconfig.app.json +++ b/src/ng-new/shared/_files/tsconfig.app.json @@ -1,5 +1,5 @@ { - "extends": "../tsconfig.json", + "extends": "./tsconfig.json", "compilerOptions": { "outDir": "./out-tsc/app", "module": "es2015", @@ -12,7 +12,7 @@ } }, "files": [ - "main.ts", - "polyfills.ts" + "<%= sourcedir %>/main.ts", + "<%= sourcedir %>/polyfills.ts" ] } diff --git a/src/ng-new/shared/_files/__sourcedir__/tsconfig.spec.json b/src/ng-new/shared/_files/tsconfig.spec.json similarity index 100% rename from src/ng-new/shared/_files/__sourcedir__/tsconfig.spec.json rename to src/ng-new/shared/_files/tsconfig.spec.json diff --git a/src/ng-new/shared/index_spec.ts b/src/ng-new/shared/index_spec.ts index e9c74f6..76f8748 100644 --- a/src/ng-new/shared/index_spec.ts +++ b/src/ng-new/shared/index_spec.ts @@ -17,10 +17,10 @@ describe('Shared Application Schematic', () => { sample: false, }; - it('should create all files of an application', () => { + it('should create all files of an application', async () => { const options = { ...defaultOptions }; - const tree = schematicRunner.runSchematic('shared', options); + const tree = await schematicRunner.runSchematicAsync('shared', options).toPromise(); const files = tree.files; expect(files).toContain('/foo/angular.json'); expect(files).toContain('/foo/nsconfig.json'); @@ -41,10 +41,10 @@ describe('Shared Application Schematic', () => { expect(files).toContain('/foo/src/app/home/home.component.css'); }); - it('should create all sample files when the sample flag is provided', () => { + it('should create all sample files when the sample flag is provided', async () => { const options = { ...defaultOptions, sample: true }; - const tree = schematicRunner.runSchematic('shared', options); + const tree = await schematicRunner.runSchematicAsync('shared', options).toPromise(); const files = tree.files; expect(files).toContain('/foo/src/app/barcelona/barcelona.common.ts'); expect(files).toContain('/foo/src/app/barcelona/barcelona.module.ts'); @@ -61,9 +61,9 @@ describe('Shared Application Schematic', () => { expect(files).toContain('/foo/src/app/barcelona/player-detail/player-detail.component.ts'); }); - it('should generate correct files when different style extension is specified', () => { + it('should generate correct files when different style extension is specified', async () => { const options = { ...defaultOptions, style: 'scss' }; - const tree = schematicRunner.runSchematic('application', options); + const tree = await schematicRunner.runSchematicAsync('application', options).toPromise(); const files = tree! .files; diff --git a/src/refactor-nsng-modules/index_spec.ts b/src/refactor-nsng-modules/index_spec.ts index 2bf0797..9925e19 100644 --- a/src/refactor-nsng-modules/index_spec.ts +++ b/src/refactor-nsng-modules/index_spec.ts @@ -1,9 +1,8 @@ -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; +import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; import { getFileContent } from '@schematics/angular/utility/test'; -import { VirtualTree } from '@angular-devkit/schematics'; import * as path from 'path'; -import { isInModuleMetadata } from '../test-utils'; +import { isInModuleMetadata, createEmptyNsOnlyProject, VirtualFile } from '../test-utils'; import { Schema } from './schema'; describe('Refactor NsNg Modules Schematic', () => { @@ -15,44 +14,29 @@ describe('Refactor NsNg Modules Schematic', () => { const sourceDir = 'src'; const defaultOptions: Schema = { sourceDir }; - const rootModulePath = `${sourceDir}/app.module.ts`; - const rootModuleContent = ` - import { NgModule } from "@angular/core"; - import { NativeScriptModule } from "nativescript-angular/nativescript.module"; - - @NgModule({ - imports: [ - NativeScriptModule, - ], - }) - export class AppModule { } - `; + const rootModulePath = `${sourceDir}/app/app.module.ts`; + const getRootModuleContent = (tree: UnitTestTree) => { + const buffer = tree.read(rootModulePath) || ''; + return buffer.toString(); + }; const initAppTree = () => { - const appTree = new VirtualTree(); - appTree.create(`${sourceDir}/package.json`, `{ "main": "main.js" }`); - appTree.create(`${sourceDir}/main.ts`, ` - import { platformNativeScriptDynamic } from 'nativescript-angular/platform'; - import { AppModule } from './app.module'; - - platformNativeScriptDynamic().bootstrapModule(AppModule); - `); - - appTree.create(rootModulePath, rootModuleContent); + const appTree = createEmptyNsOnlyProject('project'); return appTree; }; - describe('when no changes are required', () => { - let tree; + let appTree; + let rootModuleContent; beforeEach(() => { - const appTree = initAppTree(); - tree = schematicRunner.runSchematic('refactor-nsng-modules', defaultOptions, appTree); + appTree = initAppTree(); + rootModuleContent = getRootModuleContent(appTree); }); - it('should not change the tree', () => { - expect(tree.files.length).toEqual(3); + it('should not change the tree', async () => { + const tree = await schematicRunner.runSchematicAsync('refactor-nsng-modules', defaultOptions, appTree) + .toPromise(); expect(tree.exists(rootModulePath)).toEqual(true); expect(getFileContent(tree, rootModulePath)).toEqual(rootModuleContent); }); @@ -64,6 +48,7 @@ describe('Refactor NsNg Modules Schematic', () => { let tree; let featureModuleContent; + let rootModuleContent; beforeEach(() => { const appTree = initAppTree(); @@ -90,6 +75,7 @@ describe('Refactor NsNg Modules Schematic', () => { export class ${featureModuleName} { } `); + rootModuleContent = getRootModuleContent(appTree); tree = schematicRunner.runSchematic('refactor-nsng-modules', defaultOptions, appTree); featureModuleContent = getFileContent(tree, featureModulePath); }); diff --git a/src/styling/index_spec.ts b/src/styling/index_spec.ts index 1e904ef..ca8786b 100644 --- a/src/styling/index_spec.ts +++ b/src/styling/index_spec.ts @@ -1,9 +1,10 @@ +import * as path from 'path'; import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; import { getFileContent } from '@schematics/angular/utility/test'; -import * as path from 'path'; +import { Tree } from '@angular-devkit/schematics'; +import { createEmptyNsOnlyProject } from '../test-utils'; import { Schema as StylingOptions } from './schema'; -import { VirtualTree, Tree } from '@angular-devkit/schematics'; describe('Styling Schematic', () => { const schematicRunner = new SchematicTestRunner( @@ -11,7 +12,7 @@ describe('Styling Schematic', () => { path.join(__dirname, '../collection.json'), ); - const appPath = 'foo'; + const appPath = ''; const sourceDir = 'app'; const defaultOptions: StylingOptions = { appPath, @@ -22,8 +23,7 @@ describe('Styling Schematic', () => { let appTree: Tree; beforeEach(() => { - appTree = new VirtualTree(); - appTree.create(`${appPath}/package.json`, '{}'); + appTree = createEmptyNsOnlyProject(sourceDir); }); describe('when css is used', () => { diff --git a/src/test-utils.ts b/src/test-utils.ts index 2290502..847d126 100644 --- a/src/test-utils.ts +++ b/src/test-utils.ts @@ -25,8 +25,7 @@ const defaultProjectSettings: TestProjectSetup = { webExtension: '', nsExtension: '.tns', shared: true, -} - +}; export const isInModuleMetadata = ( moduleName: string, @@ -110,11 +109,23 @@ function setupTestTree(files: VirtualFile[]): UnitTestTree { } export function createEmptyNsOnlyProject(projectName: string, nsExtension: string = ''): UnitTestTree { - return createTestProject({ projectName, nsExtension, shared: false }); + const setup = { ...defaultProjectSettings, projectName, nsExtension }; + const additionalFiles = [ + getNsPackageJson(setup), + getNsEntryPoint(setup) + ]; + + return createTestProject(setup, additionalFiles); } export function createEmptySharedProject(projectName: string, webExtension: string = '', nsExtension: string = '.tns'): UnitTestTree { - return createTestProject({ projectName, webExtension, nsExtension, shared: true }); + const setup = { ...defaultProjectSettings, projectName, webExtension, nsExtension }; + const additionalFiles = [ + getNsConfig(setup), + getAppModule(setup.webExtension), + ]; + + return createTestProject(setup, additionalFiles); } export function createTestProject(setup: TestProjectSetup, additionalFiles: VirtualFile[] = []): UnitTestTree { @@ -129,11 +140,6 @@ export function createTestProject(setup: TestProjectSetup, additionalFiles: Virt files.push(getAppModule(setup.nsExtension)); - if (setup.shared) { - files.push(getNsConfig(setup)); - files.push(getAppModule(setup.webExtension)); - } - files.push(...additionalFiles); const virtualTree = setupTestTree(files); @@ -213,14 +219,14 @@ function getBaseTypescriptConfig({ sourceDirectory, importPrefix }: TestProjectS } function getWebTypescriptConfig({ sourceDirectory, importPrefix }: TestProjectSetup): VirtualFile { - const webConfigPath = `${sourceDirectory}/tsconfig.app.json`; + const webConfigPath = 'tsconfig.app.json'; const webImportRemapKey = `${importPrefix}/*`; const webImportMap = [ `${sourceDirectory}/*.web`, `${sourceDirectory}/` ]; const webConfigObject = { - 'extends': '../tsconfig.json', + 'extends': './tsconfig.json', compilerOptions: { outDir: './out-tsc/app', 'module': 'es2015', @@ -276,4 +282,28 @@ function getAppModule(extension?: string): VirtualFile { path, content: file.content.toString() }; -} \ No newline at end of file +} + +function getNsEntryPoint(setup: TestProjectSetup): VirtualFile { + return { + path: `${setup.sourceDirectory}/main.ts`, + content: ` + import { platformNativeScriptDynamic } from 'nativescript-angular/platform'; + import { AppModule } from './app/app.module'; + + platformNativeScriptDynamic().bootstrapModule(AppModule); + ` + }; +} + +function getNsPackageJson(setup: TestProjectSetup): VirtualFile { + return { + path: `${setup.sourceDirectory}/package.json`, + content: JSON.stringify({ + android: { + v8Flags: '--expose_gc' + }, + main: 'main.js' + }) + }; +}