Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react): remove unit test runner prompt when generating library #14457

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/generated/packages/react/generators/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
"unitTestRunner": {
"type": "string",
"enum": ["jest", "vitest", "none"],
"description": "Test runner to use for unit tests."
"description": "Test runner to use for unit tests.",
"x-prompt": "What unit test runner should be used?"
},
"inSourceTests": {
"type": "boolean",
Expand Down
1 change: 0 additions & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"@nrwl/workspace": "file:../workspace",
"@phenomnomnominal/tsquery": "4.1.1",
"chalk": "^4.1.0",
"enquirer": "~2.3.6",
"minimatch": "3.0.5",
"semver": "7.3.4"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ describe(componentTestGenerator.name, () => {
> = assertMinimumCypressVersion as never;
beforeEach(() => {
tree = createTreeWithEmptyV1Workspace();
jest
.spyOn(enquirer, 'prompt')
.mockReturnValue(new Promise((res) => res({ runner: 'jest' })));
});
it('should create component test for tsx files', async () => {
mockedAssertMinimumCypressVersion.mockReturnValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ describe('React:CypressComponentTestConfiguration', () => {
> = assertMinimumCypressVersion as never;
beforeEach(() => {
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
jest
.spyOn(enquirer, 'prompt')
.mockReturnValue(new Promise((res) => res({ runner: 'jest' })));
});

it('should generate cypress config with vite', async () => {
Expand Down
3 changes: 0 additions & 3 deletions packages/react/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,6 @@ describe('lib', () => {

describe('--unit-test-runner none', () => {
it('should not generate test configuration', async () => {
jest
.spyOn(enquirer, 'prompt')
.mockReturnValue(new Promise((res) => res({ runner: 'none' })));
await libraryGenerator(tree, {
...defaultSchema,
unitTestRunner: 'none',
Expand Down
15 changes: 0 additions & 15 deletions packages/react/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,11 @@ import { createFiles } from './lib/create-files';
import { updateBaseTsConfig } from './lib/update-base-tsconfig';
import { extractTsConfigBase } from '../../utils/create-ts-config';
import { installCommonDependencies } from './lib/install-common-dependencies';
import { prompt } from 'enquirer';
import { setDefaults } from './lib/set-defaults';

export async function libraryGenerator(host: Tree, schema: Schema) {
const tasks: GeneratorCallback[] = [];

// Check if unit test runner was provided or if we have a default
if (!schema.unitTestRunner) {
schema.unitTestRunner = (
await prompt<{ runner: 'vitest' | 'jest' | 'none' }>([
{
message: 'What unit test runner should be used?',
type: 'select',
name: 'runner',
choices: ['vitest', 'jest', 'none'],
},
])
).runner;
}

const options = normalizeOptions(host, schema);
if (options.publishable === true && !schema.importPath) {
throw new Error(
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/generators/library/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"unitTestRunner": {
"type": "string",
"enum": ["jest", "vitest", "none"],
"description": "Test runner to use for unit tests."
"description": "Test runner to use for unit tests.",
"x-prompt": "What unit test runner should be used?"
},
"inSourceTests": {
"type": "boolean",
Expand Down
3 changes: 0 additions & 3 deletions packages/react/src/generators/stories/stories.lib.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ describe('react:stories for libraries', () => {
let appTree: Tree;

beforeEach(async () => {
jest
.spyOn(enquirer, 'prompt')
.mockReturnValue(new Promise((res) => res({ runner: 'jest' })));
appTree = await createTestUILib('test-ui-lib');

// create another component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ describe('react:storybook-configuration', () => {
mockedInstalledCypressVersion.mockReturnValue(10);
jest.spyOn(logger, 'warn').mockImplementation(() => {});
jest.spyOn(logger, 'debug').mockImplementation(() => {});
jest
.spyOn(enquirer, 'prompt')
.mockReturnValue(new Promise((res) => res({ runner: 'jest' })));
});

afterEach(() => {
Expand Down