inquirer#Answers TypeScript Examples

The following examples show how to use inquirer#Answers. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: generator.spec.ts    From nx-dotnet with MIT License 6 votes vote down vote up
describe('restore generator', () => {
  let appTree: Tree;

  beforeEach(() => {
    appTree = createTreeWithEmptyWorkspace();
    updateConfig(appTree, { nugetPackages: {} });

    (prompt as jest.MockedFunction<typeof prompt>)
      .mockReset()
      .mockImplementation((async () => {
        return {};
      }) as () => Promise<Answers> & { ui: PromptUI });

    (getNxDotnetProjects as jest.MockedFunction<typeof getNxDotnetProjects>)
      .mockReset()
      .mockImplementation(() => Promise.resolve(new Map()));
  });

  it('should run successfully', async () => {
    await generator(appTree, null);
    expect(true).toBeTruthy();
  });
});
Example #2
Source File: generator.spec.ts    From nx-dotnet with MIT License 6 votes vote down vote up
describe('sync generator', () => {
  let appTree: Tree;

  beforeEach(() => {
    appTree = createTreeWithEmptyWorkspace();
    updateConfig(appTree, { nugetPackages: {} });

    (prompt as jest.MockedFunction<typeof prompt>)
      .mockReset()
      .mockImplementation((async () => {
        return {};
      }) as () => Promise<Answers> & { ui: PromptUI });

    (getNxDotnetProjects as jest.MockedFunction<typeof getNxDotnetProjects>)
      .mockReset()
      .mockImplementation(() => Promise.resolve(new Map()));
  });

  it('should run successfully', async () => {
    await generator(appTree);
    expect(true).toBeTruthy();
  });
});
Example #3
Source File: generator.spec.ts    From nx-dotnet with MIT License 5 votes vote down vote up
describe('nuget-reference generator', () => {
  let appTree: Tree;

  const options: NugetReferenceGeneratorSchema = {
    packageName: 'test',
    project: 'test',
    allowVersionMismatch: false,
  };

  let dotnetClient: DotNetClient;

  beforeEach(() => {
    appTree = createTreeWithEmptyWorkspace();
    appTree.write(
      'workspace.json',
      JSON.stringify({
        projects: {
          test: {},
        },
      }),
    );
    appTree.write(
      'nx.json',
      JSON.stringify({
        projects: {
          test: {
            tags: [],
          },
        },
      }),
    );

    updateConfig(appTree, { nugetPackages: {} });
    (prompt as jest.MockedFunction<typeof prompt>)
      .mockReset()
      .mockImplementation((async () => {
        return {};
      }) as () => Promise<Answers> & { ui: PromptUI });

    dotnetClient = new DotNetClient(mockDotnetFactory());
  });

  it('runs calls dotnet add package reference', async () => {
    await generator(appTree, options, dotnetClient);
    const mock = dotnetClient as jest.Mocked<DotNetClient>;
    expect(mock.addPackageReference).toHaveBeenCalledTimes(1);
  });

  it('only prompts user once on version mismatch / miss', async () => {
    await generator(appTree, options, dotnetClient);
    expect(prompt).toHaveBeenCalledTimes(1);
  });

  it('provides resolved version to dotnet add package reference', async () => {
    const { getProjectFileForNxProject } = await import('@nx-dotnet/utils');

    const projectFilePath = 'libs/test/Test.csproj';

    (getProjectFileForNxProject as jest.MockedFunction<() => Promise<string>>)
      .mockReset()
      .mockResolvedValue(projectFilePath);

    updateConfig(appTree, {
      nugetPackages: { [options.packageName]: '1.2.3' },
    });
    await generator(appTree, options, dotnetClient);
    const mock = dotnetClient as jest.Mocked<DotNetClient>;
    expect(mock.addPackageReference).toHaveBeenCalledWith(
      projectFilePath,
      options.packageName,
      { version: '1.2.3' },
    );
  });
});