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

This commit is contained in:
Jack Hsu 2023-01-18 09:38:52 -05:00 committed by GitHub
parent bd2b5ca8d3
commit 99b49189eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 4 additions and 33 deletions

View File

@ -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",

View File

@ -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"
},

View File

@ -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();

View File

@ -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 () => {

View File

@ -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',

View File

@ -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(

View File

@ -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",

View File

@ -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

View File

@ -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(() => {