How to use the @schematics/angular/utility/test.getFileContent function in @schematics/angular

To help you get started, we’ve selected a few @schematics/angular examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github maciejtreder / ng-toolkit / schematics / utils / index.ts View on Github external
export function getServerDistFolder(tree: Tree, options: any): string {
    const cliConfig: any = JSON.parse(getFileContent(tree, `${options.directory}/angular.json`));
    // console.log(getFileContent(tree, `${options.directory}/angular.json`));
    const project: any = cliConfig.projects[options.project].architect;
    for (let property in project) {
        if (project.hasOwnProperty(property) && project[property].builder === '@angular-devkit/build-angular:server') {
            return project[property].options.outputPath;
        }
    }
    return '';
}
github nstudio / xplat / src / xplat-helper / index_spec.ts View on Github external
const files = tree.files;
    // console.log(files);

    // xplat helpers
    expect(files.indexOf('/xplat/nativescript/utils/@nativescript/core.ts')).toBeGreaterThanOrEqual(0);
    expect(files.indexOf('/xplat/nativescript/utils/@nativescript/ui.ts')).toBeGreaterThanOrEqual(0);
    expect(files.indexOf('/xplat/nativescript/utils/@nativescript/angular/core.ts')).toBeGreaterThanOrEqual(0);

    // should update tsconfig files
    let filePath = '/tsconfig.json';
    let fileContent = JSON.parse(getFileContent(tree, filePath));
    // console.log(fileContent);
    expect(fileContent.compilerOptions.paths['@nativescript/*'][0]).toBe('xplat/nativescript/utils/@nativescript/*');

    filePath = '/apps/nativescript-foo/tsconfig.json';
    fileContent = JSON.parse(getFileContent(tree, filePath));
    // console.log(fileContent);
    expect(fileContent.compilerOptions.paths['@nativescript/*'][0]).toBe('../../xplat/nativescript/utils/@nativescript/*');
  });
github nstudio / xplat / src / xplat-helper / index_spec.ts View on Github external
npmScope: 'testing',
      prefix: 'tt',
      platforms: 'web,nativescript'
    };

    appTree = schematicRunner.runSchematic('xplat', optionsXplat, appTree);
    const appOptions: AppWebOptions = {
      name: 'foo',
      prefix: 'tt',
      e2eTestRunner: 'cypress'
    };
    // console.log('appTree:', appTree);
    appTree = await schematicRunner.runSchematicAsync('app', appOptions, appTree).toPromise();
    
    const cypressJsonPath = '/apps/web-foo-e2e/cypress.json';
    let fileContent = getFileContent(appTree, cypressJsonPath);
    let cypressJson = JSON.parse(fileContent);
    expect(cypressJson.supportFile).toBe(false);

    const options: HelperOptions = { 
      name: 'applitools',
      platforms: 'web'
     };
    // console.log('appTree:', appTree);
    let tree;

    expect(
      () => (tree = schematicRunner.runSchematic('xplat-helper', options, appTree))
    ).toThrowError(
      `The xplat-helper "applitools" requires the --target flag.`
    );
  });
github CanopyTax / single-spa-angular / src / schematics / ng-add / index.spec.ts View on Github external
test('should not add router dependencies', () => {
    const tree = testRunner.runSchematic('ng-add', { routing: false }, defaultAppTree);
    const mainModuleContent = getFileContent(tree, '/projects/ss-angular-cli-app/src/main.single-spa.ts')
    expect(mainModuleContent.indexOf('@angular/router')).toBe(-1);
  });
github NativeScript / nativescript-schematics / src / ng-new / application / index_spec.ts View on Github external
it('should handle the webpack flag', () => {
    const options = { ...defaultOptions, webpack: false };
    const tree = schematicRunner.runSchematic('application', options);

    const packageJson = '/foo/package.json';
    expect(getFileContent(tree, packageJson))
      .not
      .toMatch(new RegExp('nativescript-dev-webpack'));

    const files = tree!.files;
    expect(files).not.toContain('/foo/webpack.config.js');
  });
github nrwl / nx / packages / schematics / src / collection / library / library.spec.ts View on Github external
it('should update the parent module', async () => {
        appTree = createApp(appTree, 'myapp');
        const tree = await runSchematic(
          'lib',
          {
            name: 'myLib',
            directory: 'myDir',
            routing: true,
            lazy: true,
            framework: 'angular',
            parentModule: 'apps/myapp/src/app/app.module.ts'
          },
          appTree
        );
        const moduleContents = getFileContent(
          tree,
          'apps/myapp/src/app/app.module.ts'
        );
        expect(moduleContents).toContain('RouterModule.forRoot([');
        expect(moduleContents).toContain(
          `{path: 'my-dir-my-lib', loadChildren: '@proj/my-dir/my-lib#MyDirMyLibModule'}`
        );

        const tsConfigAppJson = JSON.parse(
          stripJsonComments(
            getFileContent(tree, 'apps/myapp/tsconfig.app.json')
          )
        );
        expect(tsConfigAppJson.include).toEqual([
          '**/*.ts',
          '../../libs/my-dir/my-lib/src/index.ts'
github maciejtreder / ng-toolkit / schematics / universal / src / schematics.ts View on Github external
tree => {
            const packageJsonSource = JSON.parse(getFileContent(tree, `${options.directory}/package.json`));
            if (packageJsonSource.dependencies['@ng-toolkit/serverless']) {
                tree.delete(`${options.directory}/local.js`);
                tree.delete(`${options.directory}/server.ts`);
                tree.delete(`${options.directory}/webpack.server.config.js`);
            } 
        },
github maciejtreder / ng-toolkit / schematics / universal / src / schematics.ts View on Github external
function addOrReplaceScriptInPackageJson(tree: Tree, options: any, name: string, script: string) {
    const packageJsonSource = JSON.parse(getFileContent(tree, `${options.directory}/package.json`));
    packageJsonSource.scripts[name] = script;
    tree.overwrite(`${options.directory}/package.json`, JSON.stringify(packageJsonSource, null, "  "));
}
github nrwl / nx / packages / schematics / src / collection / library / library.spec.ts View on Github external
expect(moduleContents).toContain(
          "{path: 'my-dir-my-lib', children: myDirMyLibRoutes}"
        );

        const tree2 = await runSchematic(
          'lib',
          {
            name: 'myLib2',
            directory: 'myDir',
            routing: true,
            framework: 'angular',
            parentModule: 'apps/myapp/src/app/app.module.ts'
          },
          tree
        );
        const moduleContents2 = getFileContent(
          tree2,
          'apps/myapp/src/app/app.module.ts'
        );
        expect(moduleContents2).toContain('MyDirMyLib2Module');
        expect(moduleContents2).toContain('RouterModule.forRoot([');
        expect(moduleContents2).toContain(
          "{path: 'my-dir-my-lib', children: myDirMyLibRoutes}"
        );
        expect(moduleContents2).toContain(
          "{path: 'my-dir-my-lib2', children: myDirMyLib2Routes}"
        );

        const tree3 = await runSchematic(
          'lib',
          {
            name: 'myLib3',
github nrwl / nx / packages / schematics / src / collection / library / library.spec.ts View on Github external
framework: 'angular',
            routing: true
          },
          appTree
        );
        expect(
          tree.exists('libs/my-dir/my-lib/src/lib/my-dir-my-lib.module.ts')
        ).toBeTruthy();
        expect(
          getFileContent(
            tree,
            'libs/my-dir/my-lib/src/lib/my-dir-my-lib.module.ts'
          )
        ).toContain('RouterModule');
        expect(
          getFileContent(
            tree,
            'libs/my-dir/my-lib/src/lib/my-dir-my-lib.module.ts'
          )
        ).toContain('const myDirMyLibRoutes: Route[] = ');

        const tree2 = await runSchematic(
          'lib',
          {
            name: 'myLib2',
            directory: 'myDir',
            routing: true,
            framework: 'angular',
            simpleModuleName: true
          },
          tree
        );