How to use the @nrwl/workspace.readJsonInTree 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 nrwl / nx / packages / storybook / src / schematics / init / init.spec.ts View on Github external
it('should add dependencies into `package.json` file', async () => {
    const tree = await runSchematic('init', {}, appTree);
    const packageJson = readJsonInTree(tree, 'package.json');
    expect(packageJson.devDependencies['@storybook/angular']).toBeDefined();
    expect(packageJson.devDependencies['@storybook/addon-knobs']).toBeDefined();
    expect(packageJson.devDependencies['babel-loader']).toBeDefined();
    expect(packageJson.devDependencies['@babel/core']).toBeDefined();
  });
});
github nrwl / nx / packages / react / src / schematics / application / application.spec.ts View on Github external
it('should update nx.json', async () => {
      const tree = await runSchematic(
        'app',
        { name: 'myApp', tags: 'one,two' },
        appTree
      );
      const nxJson = readJsonInTree(tree, '/nx.json');
      expect(nxJson).toEqual({
        npmScope: 'proj',
        projects: {
          'my-app': {
            tags: ['one', 'two']
          },
          'my-app-e2e': {
            tags: []
          }
        }
      });
    });
github nrwl / nx / packages / workspace / src / schematics / library / library.spec.ts View on Github external
it('should extend the local tsconfig.json with tsconfig.lib.json', async () => {
      const tree = await runSchematic('lib', { name: 'myLib' }, appTree);
      const tsconfigJson = readJsonInTree(
        tree,
        'libs/my-lib/tsconfig.lib.json'
      );
      expect(tsconfigJson.extends).toEqual('./tsconfig.json');
    });
github nrwl / nx / packages / workspace / src / schematics / library / library.spec.ts View on Github external
it('should create a local tsconfig.json', async () => {
      const tree = await runSchematic(
        'lib',
        { name: 'myLib', directory: 'myDir' },
        appTree
      );

      const tsconfigJson = readJsonInTree(
        tree,
        'libs/my-dir/my-lib/tsconfig.json'
      );
      expect(tsconfigJson).toEqual({
        extends: '../../../tsconfig.json',
        compilerOptions: {
          types: ['node', 'jest']
        },
        include: ['**/*.ts']
      });
    });
github nrwl / nx / packages / react / src / schematics / application / application.spec.ts View on Github external
it('should not generate test configuration', async () => {
      const tree = await runSchematic(
        'app',
        { name: 'myApp', unitTestRunner: 'none' },
        appTree
      );
      expect(tree.exists('apps/my-app/src/app/app.spec.tsx')).toBeFalsy();
      expect(tree.exists('apps/my-app/tsconfig.spec.json')).toBeFalsy();
      expect(tree.exists('apps/my-app/jest.config.js')).toBeFalsy();
      const workspaceJson = readJsonInTree(tree, 'workspace.json');
      expect(workspaceJson.projects['my-app'].architect.test).toBeUndefined();
      expect(
        workspaceJson.projects['my-app'].architect.lint.options.tsConfig
      ).toEqual(['apps/my-app/tsconfig.app.json']);
    });
  });
github nrwl / nx / packages / angular / src / schematics / ngrx / ngrx.spec.ts View on Github external
it('should update package.json', async () => {
    const tree = await runSchematic(
      'ngrx',
      {
        name: 'state',
        module: 'apps/myapp/src/app/app.module.ts'
      },
      appTree
    );
    const packageJson = readJsonInTree(tree, 'package.json');

    expect(packageJson.dependencies['@ngrx/store']).toBeDefined();
    expect(packageJson.dependencies['@ngrx/router-store']).toBeDefined();
    expect(packageJson.dependencies['@ngrx/effects']).toBeDefined();
    expect(packageJson.devDependencies['@ngrx/store-devtools']).toBeDefined();
  });
github nrwl / nx / packages / schematics / migrations / update-7-6-0 / update-7-6-0.spec.ts View on Github external
it('should be added to existing recommendations', async () => {
      initialTree = await schematicRunner
        .callRule(
          updateJsonInTree('.vscode/extensions.json', () => ({
            recommendations: ['eamodio.gitlens', 'angular.ng-template']
          })),
          initialTree
        )
        .toPromise();

      const result = await schematicRunner
        .runSchematicAsync('update-7.6.0', {}, initialTree)
        .toPromise();

      expect(readJsonInTree(result, '.vscode/extensions.json')).toEqual({
        recommendations: [
          'eamodio.gitlens',
          'angular.ng-template',
          'nrwl.angular-console',
          'esbenp.prettier-vscode'
        ]
      });
    });
  });
github nrwl / nx / packages / cypress / src / schematics / init / init.ts View on Github external
return (host: Tree): Rule => {
    const packageJson = readJsonInTree(host, 'package.json');
    const dependencyList: { name: string; version: string }[] = [];
    if (!packageJson.devDependencies.cypress) {
      dependencyList.push({ name: 'cypress', version: cypressVersion });
    }
    if (!packageJson.devDependencies['@nrwl/cypress']) {
      dependencyList.push({ name: '@nrwl/cypress', version: nxVersion });
    }

    if (!dependencyList.length) {
      return noop();
    }

    return addDepsToPackageJson(
      {},
      dependencyList.reduce((dictionary, value) => {
        dictionary[value.name] = value.version;
github nrwl / nx / packages / schematics / migrations / update-7-2-0 / update-7-2-0.spec.ts View on Github external
function getTypes(path: string) {
      return readJsonInTree(result, path).compilerOptions.types;
    }
github nrwl / nx / packages / workspace / src / migrations / update-8-5-0 / update-8-5-0.spec.ts View on Github external
tree = await createLibWithTests(
        tree,
        lib,
        jestBuilder,
        'test-modified.ts.ts'
      );
      tree.create(
        `/libs/${lib}/tsconfig.lib.json`,
        JSON.stringify({ exclude })
      );

      const result = await schematicRunner
        .runSchematicAsync(schematicName, {}, tree)
        .toPromise();

      const tsconfigJson = readJsonInTree(
        result,
        `libs/${lib}/tsconfig.lib.json`
      );
      expect(tsconfigJson.exclude).toEqual(exclude);
    });
  });