Repository: angular/angular-cli
File: packages/schematics/angular/migrations/use-application-builder/migration_spec.ts (TypeScript)

Code before:
      app: {
        root: '/project/app',
        sourceRoot: 'src',
        projectType: ProjectType.Application,
        prefix: 'app',
        architect: {
          build: {
            builder: Builders.Browser,
            options: {
              tsConfig: 'src/tsconfig.app.json',
              main: 'src/main.ts',
              polyfills: 'src/polyfills.ts',
              outputPath: 'dist/project',
              resourcesOutputPath: '/resources',
            },
          },
        },
      },
    },
  };

  tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2));
  tree.create(
    '/tsconfig.json',
    JSON.stringify({ compilerOptions: { module: 'preserve' } }, undefined, 2),
  );
  tree.create('/package.json', JSON.stringify({}, undefined, 2));
}

function addWorkspaceTarget(tree: UnitTestTree, targetName: string, targetEntry: unknown): void {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  const workspaceContent = tree.readJson('/angular.json') as Record<string, any>;

  workspaceContent['projects']['app']['architect'][targetName] = targetEntry;

  tree.overwrite('/angular.json', JSON.stringify(workspaceContent));
}

function getCompilerOptionsValue(tree: UnitTestTree, filePath: string): Record<string, unknown> {
  const json = tree.readJson(filePath);
  if (isJsonObject(json) && isJsonObject(json.compilerOptions)) {
    return json.compilerOptions;
  }

  throw new Error(`Cannot retrieve 'compilerOptions'.`);
}

function createJsonFile(tree: UnitTestTree, filePath: string, content: {}): void {
  const stringifiedContent = JSON.stringify(content, undefined, 2);
  if (tree.exists(filePath)) {
    tree.overwrite(filePath, stringifiedContent);

Review comment (suggestion):
This can be reverted as it's not needed.
```suggestion
  tree.create('/tsconfig.json', JSON.stringify({}, undefined, 2));
```

Code after:
      app: {
        root: '/project/app',
        sourceRoot: 'src',
        projectType: ProjectType.Application,
        prefix: 'app',
        architect: {
          build: {
            builder: Builders.Browser,
            options: {
              tsConfig: 'src/tsconfig.app.json',
              main: 'src/main.ts',
              polyfills: 'src/polyfills.ts',
              outputPath: 'dist/project',
              resourcesOutputPath: '/resources',
            },
          },
        },
      },
    },
  };

  tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2));
  tree.create('/tsconfig.json', JSON.stringify({}, undefined, 2));
  tree.create('/package.json', JSON.stringify({}, undefined, 2));
}

function addWorkspaceTarget(tree: UnitTestTree, targetName: string, targetEntry: unknown): void {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  const workspaceContent = tree.readJson('/angular.json') as Record<string, any>;

  workspaceContent['projects']['app']['architect'][targetName] = targetEntry;

  tree.overwrite('/angular.json', JSON.stringify(workspaceContent));
}

describe(`Migration to use the application builder`, () => {
  const schematicName = 'use-application-builder';
  const schematicRunner = new SchematicTestRunner(
    'migrations',
    require.resolve('../migration-collection.json'),
  );

  let tree: UnitTestTree;
  beforeEach(() => {
    tree = new UnitTestTree(new EmptyTree());
    createWorkSpaceConfig(tree);
  });

  it(`should replace 'outputPath' to string if 'resourcesOutputPath' is set to 'media'`, async () => {
    // Replace resourcesOutputPath
    tree.overwrite('angular.json', tree.readContent('angular.json').replace('/resources', 'media'));