How to use the @nrwl/workspace/testing.getFileContent function in @nrwl/workspace

To help you get started, weโ€™ve selected a few @nrwl/workspace 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 nstudio / xplat / packages / xplat / src / schematics / application / index.spec.ts View on Github external
fit('should create Nx node', async () => {
      appTree = Tree.empty();
      appTree = createEmptyWorkspace(appTree);
      const options: XplatHelpers.Schema = { ...defaultOptions };
      options.platforms = 'node';

      const tree = await runSchematic('app', options, appTree);
      const files = tree.files;
      // console.log('files:', files);

      expect(tree.exists('/apps/node-sample/src/main.ts')).toBeTruthy();

      let fileContent = getFileContent(tree, '/apps/node-sample/src/main.ts');
      // console.log(fileContent);
      expect(
        fileContent.indexOf(`console.log('Hello World!')`)
      ).toBeGreaterThanOrEqual(0);
    });
github nrwl / nx / packages / angular / src / schematics / ngrx / ngrx.spec.ts View on Github external
it('should add feature', async () => {
    const tree = await runSchematic(
      'ngrx',
      {
        name: 'state',
        module: 'apps/myapp/src/app/app.module.ts'
      },
      appTree
    );

    const appModule = getFileContent(tree, '/apps/myapp/src/app/app.module.ts');
    expect(appModule).toContain('StoreModule.forFeature');
    expect(appModule).toContain('EffectsModule.forFeature');
    expect(appModule).not.toContain('!environment.production ? [] : []');

    expect(
      tree.exists(`/apps/myapp/src/app/+state/state.actions.ts`)
    ).toBeTruthy();
  });
github nrwl / nx / packages / angular / src / schematics / downgrade-module / downgrade-module.spec.ts View on Github external
it('should update main.ts', async () => {
    const tree = await runSchematic(
      'downgrade-module',
      {
        name: 'legacy',
        project: 'myapp'
      },
      appTree
    );

    const main = getFileContent(tree, '/apps/myapp/src/main.ts');
    expect(main).toContain('downgradeModule(bootstrapAngular)');
    expect(main).toContain(`import 'legacy';`);
    expect(main).toContain(
      `angular.bootstrap(document, ['legacy', downgraded.name]);`
    );
  });
github nrwl / nx / packages / angular / src / schematics / application / application.spec.ts View on Github external
const tsconfigApp = JSON.parse(
        stripJsonComments(getFileContent(tree, 'apps/my-app/tsconfig.app.json'))
      );
      expect(tsconfigApp.compilerOptions.outDir).toEqual('../../dist/out-tsc');
      expect(tsconfigApp.extends).toEqual('./tsconfig.json');

      const tslintJson = JSON.parse(
        stripJsonComments(getFileContent(tree, 'apps/my-app/tslint.json'))
      );
      expect(tslintJson.extends).toEqual('../../tslint.json');

      expect(tree.exists('apps/my-app-e2e/cypress.json')).toBeTruthy();
      const tsconfigE2E = JSON.parse(
        stripJsonComments(
          getFileContent(tree, 'apps/my-app-e2e/tsconfig.e2e.json')
        )
      );
      expect(tsconfigE2E.extends).toEqual('./tsconfig.json');
    });
github nrwl / nx / packages / angular / src / schematics / library / library.spec.ts View on Github external
path: 'my-dir-my-lib2',
        loadChildren: () =>
          import('@proj/my-dir/my-lib2').then(
            module => module.MyDirMyLib2Module
          )
      }`);
        expect(moduleContents3).toContain(`
      {
        path: 'my-lib3',
        loadChildren: () =>
          import('@proj/my-dir/my-lib3').then(module => module.MyLib3Module)
      }`);

        const tsConfigAppJson3 = JSON.parse(
          stripJsonComments(
            getFileContent(tree3, 'apps/myapp/tsconfig.app.json')
          )
        );
        expect(tsConfigAppJson3.include).toEqual([
          '**/*.ts',
          '../../libs/my-dir/my-lib/src/index.ts',
          '../../libs/my-dir/my-lib2/src/index.ts',
          '../../libs/my-dir/my-lib3/src/index.ts'
        ]);
      });
    });
github bennymeg / nx-electron / src / schematics / application / application.spec.ts View on Github external
const tsconfig = readJsonInTree(tree, 'apps/my-electron-app/tsconfig.json');
      expect(tsconfig.extends).toEqual('../../tsconfig.json');
      expect(tsconfig.compilerOptions.types).toContain('node');
      expect(tsconfig.compilerOptions.types).toContain('jest');

      const tsconfigApp = JSON.parse(
        stripJsonComments(
          getFileContent(tree, 'apps/my-electron-app/tsconfig.app.json')
        )
      );
      expect(tsconfigApp.compilerOptions.outDir).toEqual('../../dist/out-tsc');
      expect(tsconfigApp.extends).toEqual('./tsconfig.json');

      const tslintJson = JSON.parse(
        stripJsonComments(getFileContent(tree, 'apps/my-electron-app/tslint.json'))
      );
      expect(tslintJson.extends).toEqual('../../tslint.json');
    });
  });
github nrwl / nx / packages / angular / src / schematics / library / library.spec.ts View on Github external
);
        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: () =>
          import('@proj/my-dir/my-lib').then(module => module.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'
        ]);

        const tree2 = await runSchematic(
          'lib',
          {
            name: 'myLib2',
            directory: 'myDir',
            routing: true,
            framework: 'angular',
            lazy: true,
            parentModule: 'apps/myapp/src/app/app.module.ts'
github nrwl / nx / packages / node / src / schematics / application / application.spec.ts View on Github external
const tsconfig = readJsonInTree(tree, 'apps/my-node-app/tsconfig.json');
      expect(tsconfig.extends).toEqual('../../tsconfig.json');
      expect(tsconfig.compilerOptions.types).toContain('node');
      expect(tsconfig.compilerOptions.types).toContain('jest');

      const tsconfigApp = JSON.parse(
        stripJsonComments(
          getFileContent(tree, 'apps/my-node-app/tsconfig.app.json')
        )
      );
      expect(tsconfigApp.compilerOptions.outDir).toEqual('../../dist/out-tsc');
      expect(tsconfigApp.extends).toEqual('./tsconfig.json');

      const tslintJson = JSON.parse(
        stripJsonComments(getFileContent(tree, 'apps/my-node-app/tslint.json'))
      );
      expect(tslintJson.extends).toEqual('../../tslint.json');
    });
  });
github bennymeg / nx-electron / src / schematics / application / application.spec.ts View on Github external
const hasJsonValue = ({ path, expectedValue, lookupFn }) => {
        const content = getFileContent(tree, path);
        const config = JSON.parse(stripJsonComments(content));

        expect(lookupFn(config)).toEqual(expectedValue);
      };
      const tree = await runSchematic(
github nrwl / nx / packages / node / src / schematics / application / application.spec.ts View on Github external
const hasJsonValue = ({ path, expectedValue, lookupFn }) => {
        const content = getFileContent(tree, path);
        const config = JSON.parse(stripJsonComments(content));

        expect(lookupFn(config)).toEqual(expectedValue);
      };
      const tree = await runSchematic(