Skip to content

Commit

Permalink
fix(react): remove unit test runner prompt when generating library (#…
Browse files Browse the repository at this point in the history
…14457)

(cherry picked from commit 99b4918)
  • Loading branch information
jaysoo authored and FrozenPandaz committed Jan 20, 2023
1 parent 22d6519 commit 3fa9d43
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 33 deletions.
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

0 comments on commit 3fa9d43

Please sign in to comment.