From 05bd6be00b91bf375a97e3f96a14e2cfa1610510 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Fri, 27 Sep 2024 11:59:11 -0300 Subject: [PATCH] testing: add helpers and migrate to JHipster helpers (#27426) --- cli/cli.spec.mts | 2 +- cli/environment-builder.mjs | 2 +- cli/utils.mjs | 2 +- generators/angular/generator.spec.ts | 5 +- generators/base-application/generator.spec.ts | 46 ++-- generators/base-core/generator.ts | 10 +- generators/base/blueprints.spec.ts | 10 +- generators/base/generator.spec.ts | 9 +- generators/client/generator.spec.ts | 13 +- generators/common/generator.spec.ts | 7 +- .../docker-compose/docker-compose.spec.ts | 239 +++++++---------- generators/docker/generator.spec.ts | 7 +- .../generator/generator.spec.mjs.ejs | 2 +- generators/git/generator.spec.ts | 7 +- generators/gradle/generator.spec.ts | 9 +- generators/init/generator.spec.ts | 7 +- .../kubernetes-helm/kubernetes.helm.spec.ts | 72 +++--- generators/kubernetes-knative/knative.spec.ts | 114 ++++---- generators/kubernetes/kubernetes.spec.ts | 100 +++---- generators/languages/languages.spec.ts | 29 +-- .../liquibase/incremental-liquibase.spec.ts | 2 +- generators/maven/generator.spec.ts | 7 +- generators/react/generator.spec.ts | 5 +- .../generator-pulsar.spec.ts | 5 +- generators/upgrade/upgrade.spec.ts | 35 +-- generators/vue/generator.spec.ts | 5 +- lib/index.ts | 11 +- .../__snapshots__/helpers.spec.ts.snap | 244 ++++++++++++++++++ lib/testing/get-generator.ts | 9 +- lib/testing/helpers.spec.ts | 57 ++++ lib/testing/helpers.ts | 111 ++++++-- .../needle-client-angular-generator.spec.ts | 4 +- .../needle-client-react-generator.spec.ts | 6 +- test/support/tests.js | 67 ++--- 34 files changed, 760 insertions(+), 500 deletions(-) create mode 100644 lib/testing/__snapshots__/helpers.spec.ts.snap create mode 100644 lib/testing/helpers.spec.ts diff --git a/cli/cli.spec.mts b/cli/cli.spec.mts index 293ff7d0a57a..be8959e38cfc 100644 --- a/cli/cli.spec.mts +++ b/cli/cli.spec.mts @@ -90,7 +90,7 @@ const cliSharedBlueprintFiles = { describe('cli', () => { const __filename = fileURLToPath(import.meta.url); const jhipsterCli = join(dirname(__filename), '..', 'bin', 'jhipster.cjs'); - const logger = { verboseInfo: esmocha.fn(), fatal: esmocha.fn(), debug: esmocha.fn() }; + const logger = { verboseInfo: esmocha.fn(), warn: esmocha.fn(), fatal: esmocha.fn(), debug: esmocha.fn() }; const getCommand = esmocha.fn(); let mockCli; let argv; diff --git a/cli/environment-builder.mjs b/cli/environment-builder.mjs index 9ca383ec78ce..dc561cb80131 100644 --- a/cli/environment-builder.mjs +++ b/cli/environment-builder.mjs @@ -75,7 +75,7 @@ export default class EnvironmentBuilder { * const promise = require('yeoman-test').create('jhipster:app', {}, {createEnv: EnvironmentBuilder.createEnv}).run(); * * @param {...any} args - Arguments passed to Environment.createEnv(). - * @return {EnvironmentBuilder} envBuilder + * @return {Promise} envBuilder */ static async createEnv(...args) { const builder = await EnvironmentBuilder.createDefaultBuilder(...args); diff --git a/cli/utils.mjs b/cli/utils.mjs index 1094f6fe16d3..feea1d91d146 100644 --- a/cli/utils.mjs +++ b/cli/utils.mjs @@ -19,7 +19,7 @@ import chalk from 'chalk'; -import { CLI_LOGGER, createJHipsterLogger } from '../generators/base/support/index.js'; +import { CLI_LOGGER, createJHipsterLogger } from '../lib/utils/logger.js'; export const CLI_NAME = 'jhipster'; export const GENERATOR_NAME = 'generator-jhipster'; diff --git a/generators/angular/generator.spec.ts b/generators/angular/generator.spec.ts index 6103f39635a1..fbbd9b06fcef 100644 --- a/generators/angular/generator.spec.ts +++ b/generators/angular/generator.spec.ts @@ -1,4 +1,4 @@ -import { basename, dirname, join } from 'path'; +import { basename, dirname } from 'path'; import { fileURLToPath } from 'url'; import { before, describe, expect, it } from 'esmocha'; import { snakeCase } from 'lodash-es'; @@ -14,7 +14,6 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const generator = basename(__dirname); -const generatorFile = join(__dirname, 'index.ts'); const { ANGULAR: clientFramework } = clientFrameworkTypes; const commonConfig = { clientFramework, nativeLanguage: 'en', languages: ['fr', 'en'] }; @@ -88,7 +87,7 @@ describe(`generator - ${clientFramework}`, () => { describe(name, () => { before(async () => { await helpers - .run(generatorFile) + .runJHipster(generator) .withJHipsterConfig(sampleConfig, entities) .withSharedApplication({ gatewayServicesApiAvailable: sampleConfig.applicationType === 'gateway' }) .withControl({ getWebappTranslation: () => 'translations' }) diff --git a/generators/base-application/generator.spec.ts b/generators/base-application/generator.spec.ts index 0903d3e5181f..2cb958003cef 100644 --- a/generators/base-application/generator.spec.ts +++ b/generators/base-application/generator.spec.ts @@ -157,27 +157,30 @@ describe(`generator - ${generator}`, () => { } before(async () => { - await helpers.run(CustomGenerator as any).withJHipsterConfig({}, [ - { - name: 'One', - fields: [{ fieldName: 'id', fieldType: 'Long' }], - relationships: [{ relationshipName: 'two', otherEntityName: 'Two', relationshipType: 'many-to-one' }], - }, - { - name: 'Two', - fields: [ - { fieldName: 'id', fieldType: 'Long' }, - { fieldName: 'name', fieldType: 'String' }, - ], - relationships: [ - { relationshipName: 'one', otherEntityName: 'One', relationshipType: 'many-to-one' }, - { relationshipName: 'three', otherEntityName: 'Three', relationshipType: 'many-to-one' }, - ], - }, - { - name: 'Three', - }, - ]); + await helpers + .run(CustomGenerator as any) + .withJHipsterGenerators({ useDefaultMocks: true }) + .withJHipsterConfig({}, [ + { + name: 'One', + fields: [{ fieldName: 'id', fieldType: 'Long' }], + relationships: [{ relationshipName: 'two', otherEntityName: 'Two', relationshipType: 'many-to-one' }], + }, + { + name: 'Two', + fields: [ + { fieldName: 'id', fieldType: 'Long' }, + { fieldName: 'name', fieldType: 'String' }, + ], + relationships: [ + { relationshipName: 'one', otherEntityName: 'One', relationshipType: 'many-to-one' }, + { relationshipName: 'three', otherEntityName: 'Three', relationshipType: 'many-to-one' }, + ], + }, + { + name: 'Three', + }, + ]); }); it('should call priorities with correct arguments', async () => { @@ -397,6 +400,7 @@ describe(`generator - ${generator}`, () => { before(async () => { await helpers .run(CustomGenerator as any) + .withJHipsterGenerators({ useDefaultMocks: true }) .withJHipsterConfig({}, [ { name: 'One', diff --git a/generators/base-core/generator.ts b/generators/base-core/generator.ts index 4d80c30e92b3..609616392a9f 100644 --- a/generators/base-core/generator.ts +++ b/generators/base-core/generator.ts @@ -721,15 +721,7 @@ You can ignore this error by passing '--skip-checks' to jhipster command.`); if (await this.env.get(namespace)) { generator = namespace; } else { - // Keep test compatibility were jhipster lookup does not run. - const found = ['/index.js', '/index.cjs', '/index.mjs', '/index.ts', '/index.cts', '/index.mts'].find(extension => { - const pathToLook = join(__dirname, `../${generator}${extension}`); - return existsSync(pathToLook) ? pathToLook : undefined; - }); - if (!found) { - throw new Error(`Generator ${generator} was not found`); - } - generator = join(__dirname, `../${generator}${found}`); + throw new Error(`Generator ${generator} was not found`); } } diff --git a/generators/base/blueprints.spec.ts b/generators/base/blueprints.spec.ts index 429245ff0497..102cc81fc1a7 100644 --- a/generators/base/blueprints.spec.ts +++ b/generators/base/blueprints.spec.ts @@ -291,7 +291,11 @@ describe('generator - base - local blueprint', () => { describe('generates application', () => { before(async () => { - await helpers.run(BLUEPRINT_NS).withFiles({ '.blueprint/app/index.mjs': BLUEPRINT_CONTENTS }).commitFiles().withJHipsterConfig(); + await helpers + .runJHipster(BLUEPRINT_NS, { useEnvironmentBuilder: true }) + .withFiles({ '.blueprint/app/index.mjs': BLUEPRINT_CONTENTS }) + .commitFiles() + .withJHipsterConfig(); }); it('creates expected default files', () => { @@ -486,7 +490,7 @@ describe('generator - base-blueprint', () => { before(() => { mockedPriorities = createPrioritiesFakes(); mockBlueprintSubGen = createAllBlueprint(mockedPriorities); - return helpers.run(mockBlueprintSubGen); + return helpers.run(mockBlueprintSubGen).withJHipsterGenerators({ useDefaultMocks: true }); }); priorities.forEach((priority, idx) => { @@ -541,7 +545,7 @@ describe('generator - base-blueprint', () => { return super.end; } }; - return helpers.create(mockBlueprintSubGen).run(); + return helpers.run(mockBlueprintSubGen).withJHipsterGenerators({ useDefaultMocks: true }); }); priorities.forEach(priority => { diff --git a/generators/base/generator.spec.ts b/generators/base/generator.spec.ts index 2fb0608affee..7000e5416695 100644 --- a/generators/base/generator.spec.ts +++ b/generators/base/generator.spec.ts @@ -81,9 +81,12 @@ describe(`generator - ${generator}`, () => { } before(async () => { - await helpers.run(CustomGenerator as any).withOptions({ - skipPriorities: ['prompting', 'writing', 'postWriting'], - }); + await helpers + .run(CustomGenerator as any) + .withJHipsterGenerators({ useDefaultMocks: true }) + .withOptions({ + skipPriorities: ['prompting', 'writing', 'postWriting'], + }); }); it('should skip priorities', async () => { diff --git a/generators/client/generator.spec.ts b/generators/client/generator.spec.ts index 37e5299af367..a6ae9c0ad8f7 100644 --- a/generators/client/generator.spec.ts +++ b/generators/client/generator.spec.ts @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { basename, dirname, join } from 'path'; +import { basename, dirname } from 'path'; import { fileURLToPath } from 'url'; import { snakeCase } from 'lodash-es'; import { before, describe, expect, it } from 'esmocha'; @@ -32,7 +32,6 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const generator = basename(__dirname); -const generatorFile = join(__dirname, 'index.js'); describe(`generator - ${generator}`, () => { it('generator-list constant matches folder name', async () => { @@ -49,7 +48,7 @@ describe(`generator - ${generator}`, () => { const options = { enableTranslation: false }; before(async () => { await helpers - .run(generatorFile) + .runJHipster(generator) .withControl({ getWebappTranslation: () => 'translations' }) .withJHipsterConfig(options) .withSkipWritingPriorities() @@ -68,7 +67,7 @@ describe(`generator - ${generator}`, () => { const options = { enableTranslation: true }; before(async () => { await helpers - .run(generatorFile) + .runJHipster(generator) .withControl({ getWebappTranslation: () => 'translations' }) .withJHipsterConfig(options) .withSkipWritingPriorities() @@ -87,7 +86,7 @@ describe(`generator - ${generator}`, () => { const options = { testFrameworks: [] }; before(async () => { await helpers - .run(generatorFile) + .runJHipster(generator) .withControl({ getWebappTranslation: () => 'translations' }) .withJHipsterConfig(options) .withSkipWritingPriorities() @@ -109,7 +108,7 @@ describe(`generator - ${generator}`, () => { const options = { testFrameworks: [CYPRESS] }; before(async () => { await helpers - .run(generatorFile) + .runJHipster(generator) .withControl({ getWebappTranslation: () => 'translations' }) .withJHipsterConfig(options) .withSkipWritingPriorities() @@ -139,7 +138,7 @@ describe(`generator - ${generator}`, () => { ]; before(async () => { await helpers - .run(generatorFile) + .runJHipster(generator) .withControl({ getWebappTranslation: () => 'translations' }) .withJHipsterConfig({ applicationType: 'microservice' }) .withSkipWritingPriorities() diff --git a/generators/common/generator.spec.ts b/generators/common/generator.spec.ts index 1422cea6d17e..703951531ee9 100644 --- a/generators/common/generator.spec.ts +++ b/generators/common/generator.spec.ts @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { basename, dirname, join } from 'path'; +import { basename, dirname } from 'path'; import { fileURLToPath } from 'url'; import { before, describe, expect, it } from 'esmocha'; import { snakeCase } from 'lodash-es'; @@ -30,7 +30,6 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const generator = basename(__dirname); -const generatorFile = join(__dirname, 'index.js'); const mockedGenerators = ['jhipster:git']; @@ -45,7 +44,7 @@ describe(`generator - ${generator}`, () => { describe('with', () => { describe('default config', () => { before(async () => { - await helpers.run(generatorFile).withJHipsterConfig().withMockedGenerators(mockedGenerators); + await helpers.runJHipster(generator).withJHipsterConfig().withMockedGenerators(mockedGenerators); }); it('should succeed', () => { @@ -59,7 +58,7 @@ describe(`generator - ${generator}`, () => { describe('Custom prettier', () => { before(async () => { await basicHelpers - .run(generatorFile) + .runJHipster(generator) .withJHipsterConfig({ prettierTabWidth: 10, }) diff --git a/generators/docker-compose/docker-compose.spec.ts b/generators/docker-compose/docker-compose.spec.ts index 0231885f8314..30cab6b592df 100644 --- a/generators/docker-compose/docker-compose.spec.ts +++ b/generators/docker-compose/docker-compose.spec.ts @@ -2,7 +2,7 @@ import { before, describe, expect, it } from 'esmocha'; import monitoringTypes from '../../lib/jhipster/monitoring-types.js'; import applicationTypes from '../../lib/jhipster/application-types.js'; import { GENERATOR_DOCKER_COMPOSE } from '../generator-list.js'; -import { getGenerator, defaultHelpers as helpers, runResult } from '../../lib/testing/index.js'; +import { defaultHelpers as helpers, runResult } from '../../lib/testing/index.js'; const { PROMETHEUS } = monitoringTypes; const { MICROSERVICE, MONOLITH } = applicationTypes; @@ -24,16 +24,13 @@ describe('generator - Docker Compose', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) - .withAnswers({ - deploymentApplicationType: MICROSERVICE, - directoryPath: './', - appsFolders: chosenApps, - clusteredDbApps: [], - monitoring: NO_MONITORING, - }) - .run(); + await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({ + deploymentApplicationType: MICROSERVICE, + directoryPath: './', + appsFolders: chosenApps, + clusteredDbApps: [], + monitoring: NO_MONITORING, + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -59,16 +56,13 @@ describe('generator - Docker Compose', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) - .withAnswers({ - deploymentApplicationType: MICROSERVICE, - directoryPath: './', - appsFolders: chosenApps, - clusteredDbApps: [], - monitoring: NO_MONITORING, - }) - .run(); + await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({ + deploymentApplicationType: MICROSERVICE, + directoryPath: './', + appsFolders: chosenApps, + clusteredDbApps: [], + monitoring: NO_MONITORING, + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -94,16 +88,13 @@ describe('generator - Docker Compose', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) - .withAnswers({ - deploymentApplicationType: MICROSERVICE, - directoryPath: '.', - appsFolders: chosenApps, - clusteredDbApps: [], - monitoring: NO_MONITORING, - }) - .run(); + await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({ + deploymentApplicationType: MICROSERVICE, + directoryPath: '.', + appsFolders: chosenApps, + clusteredDbApps: [], + monitoring: NO_MONITORING, + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -124,16 +115,13 @@ describe('generator - Docker Compose', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) - .withAnswers({ - deploymentApplicationType: MICROSERVICE, - directoryPath: './', - appsFolders: chosenApps, - clusteredDbApps: [], - monitoring: NO_MONITORING, - }) - .run(); + await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({ + deploymentApplicationType: MICROSERVICE, + directoryPath: './', + appsFolders: chosenApps, + clusteredDbApps: [], + monitoring: NO_MONITORING, + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -159,15 +147,12 @@ describe('generator - Docker Compose', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) - .withAnswers({ - deploymentApplicationType: MICROSERVICE, - directoryPath: './', - appsFolders: chosenApps, - clusteredDbApps: [], - }) - .run(); + await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({ + deploymentApplicationType: MICROSERVICE, + directoryPath: './', + appsFolders: chosenApps, + clusteredDbApps: [], + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -196,15 +181,12 @@ describe('generator - Docker Compose', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) - .withAnswers({ - deploymentApplicationType: MICROSERVICE, - directoryPath: './', - appsFolders: chosenApps, - clusteredDbApps: [], - }) - .run(); + await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({ + deploymentApplicationType: MICROSERVICE, + directoryPath: './', + appsFolders: chosenApps, + clusteredDbApps: [], + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -233,16 +215,13 @@ describe('generator - Docker Compose', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) - .withAnswers({ - deploymentApplicationType: MICROSERVICE, - directoryPath: './', - appsFolders: chosenApps, - clusteredDbApps: [], - monitoring: PROMETHEUS, - }) - .run(); + await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({ + deploymentApplicationType: MICROSERVICE, + directoryPath: './', + appsFolders: chosenApps, + clusteredDbApps: [], + monitoring: PROMETHEUS, + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -271,15 +250,12 @@ describe('generator - Docker Compose', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) - .withAnswers({ - deploymentApplicationType: MICROSERVICE, - directoryPath: './', - appsFolders: chosenApps, - clusteredDbApps: [], - }) - .run(); + await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({ + deploymentApplicationType: MICROSERVICE, + directoryPath: './', + appsFolders: chosenApps, + clusteredDbApps: [], + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -305,15 +281,12 @@ describe('generator - Docker Compose', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) - .withAnswers({ - deploymentApplicationType: MICROSERVICE, - directoryPath: './', - appsFolders: chosenApps, - clusteredDbApps: ['04-mongo'], - }) - .run(); + await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({ + deploymentApplicationType: MICROSERVICE, + directoryPath: './', + appsFolders: chosenApps, + clusteredDbApps: ['04-mongo'], + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -339,15 +312,12 @@ describe('generator - Docker Compose', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) - .withAnswers({ - deploymentApplicationType: MICROSERVICE, - directoryPath: './', - appsFolders: chosenApps, - clusteredDbApps: [], - }) - .run(); + await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({ + deploymentApplicationType: MICROSERVICE, + directoryPath: './', + appsFolders: chosenApps, + clusteredDbApps: [], + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -373,15 +343,12 @@ describe('generator - Docker Compose', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) - .withAnswers({ - deploymentApplicationType: MONOLITH, - directoryPath: './', - appsFolders: chosenApps, - clusteredDbApps: [], - }) - .run(); + await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({ + deploymentApplicationType: MONOLITH, + directoryPath: './', + appsFolders: chosenApps, + clusteredDbApps: [], + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -404,15 +371,12 @@ describe('generator - Docker Compose', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) - .withAnswers({ - deploymentApplicationType: MICROSERVICE, - directoryPath: './', - appsFolders: chosenApps, - clusteredDbApps: [], - }) - .run(); + await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({ + deploymentApplicationType: MICROSERVICE, + directoryPath: './', + appsFolders: chosenApps, + clusteredDbApps: [], + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot({ @@ -443,15 +407,12 @@ describe('generator - Docker Compose', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) - .withAnswers({ - deploymentApplicationType: MICROSERVICE, - directoryPath: './', - appsFolders: chosenApps, - clusteredDbApps: [], - }) - .run(); + await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({ + deploymentApplicationType: MICROSERVICE, + directoryPath: './', + appsFolders: chosenApps, + clusteredDbApps: [], + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -477,15 +438,12 @@ describe('generator - Docker Compose', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) - .withAnswers({ - deploymentApplicationType: MICROSERVICE, - directoryPath: './', - appsFolders: chosenApps, - clusteredDbApps: ['10-couchbase'], - }) - .run(); + await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({ + deploymentApplicationType: MICROSERVICE, + directoryPath: './', + appsFolders: chosenApps, + clusteredDbApps: ['10-couchbase'], + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -511,16 +469,13 @@ describe('generator - Docker Compose', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) - .withAnswers({ - deploymentApplicationType: MONOLITH, - directoryPath: './', - appsFolders: chosenApps, - clusteredDbApps: [], - monitoring: NO_MONITORING, - }) - .run(); + await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({ + deploymentApplicationType: MONOLITH, + directoryPath: './', + appsFolders: chosenApps, + clusteredDbApps: [], + monitoring: NO_MONITORING, + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); diff --git a/generators/docker/generator.spec.ts b/generators/docker/generator.spec.ts index cbf359ae1cd7..356c2a197312 100644 --- a/generators/docker/generator.spec.ts +++ b/generators/docker/generator.spec.ts @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { basename, dirname, join } from 'path'; +import { basename, dirname } from 'path'; import { fileURLToPath } from 'url'; import { before, describe, expect, it } from 'esmocha'; import { snakeCase } from 'lodash-es'; @@ -45,7 +45,6 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const generator = basename(__dirname); -const generatorFile = join(__dirname, 'index.ts'); const NO_SQL = [CASSANDRA, COUCHBASE, MONGODB, NEO4J]; @@ -86,7 +85,7 @@ describe(`generator - ${generator}`, () => { describe(name, () => { before(async () => { - await helpers.run(generatorFile).withJHipsterConfig(sampleConfig); + await helpers.runJHipster(generator).withJHipsterConfig(sampleConfig); }); it('should match generated files snapshot', () => { @@ -108,7 +107,7 @@ describe(`generator - ${generator}`, () => { describe(`custom path for ${name}`, () => { before(async () => { await helpers - .run(generatorFile) + .runJHipster(generator) .withSharedApplication({ dockerServicesDir: 'foo/', }) diff --git a/generators/generate-blueprint/templates/generators/generator/generator.spec.mjs.ejs b/generators/generate-blueprint/templates/generators/generator/generator.spec.mjs.ejs index 3f66bcb0f357..9fd887094e3d 100644 --- a/generators/generate-blueprint/templates/generators/generator/generator.spec.mjs.ejs +++ b/generators/generate-blueprint/templates/generators/generator/generator.spec.mjs.ejs @@ -42,7 +42,7 @@ describe('SubGenerator <%= subGenerator %> of <%= application.baseName %> JHipst inline: 'application { }', <%_ } _%> }) - .withJHipsterLookup() + .withJHipsterGenerators() .withParentBlueprintLookup(); }); diff --git a/generators/git/generator.spec.ts b/generators/git/generator.spec.ts index 4e71eebb23d6..b26480b10a0e 100644 --- a/generators/git/generator.spec.ts +++ b/generators/git/generator.spec.ts @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { basename, dirname, join, resolve } from 'path'; +import { basename, dirname, resolve } from 'path'; import { fileURLToPath } from 'url'; import { access } from 'fs/promises'; import { before, describe, expect, it } from 'esmocha'; @@ -28,7 +28,6 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const generator = basename(__dirname); -const generatorPath = join(__dirname, 'index.ts'); describe(`generator - ${generator}`, () => { it('generator-list constant matches folder name', () => { @@ -72,7 +71,7 @@ describe(`generator - ${generator}`, () => { describe('regenerating', () => { before(async () => { await helpers.runJHipster(generator).withOptions({ skipGit: false }); - await runResult.create(generatorPath).withOptions({ skipGit: false, baseName: 'changed' }).run(); + await helpers.runJHipsterInApplication(generator).withOptions({ skipGit: false, baseName: 'changed' }); }); it('should create a single commit', async () => { const git = runResult.generator.createGit(); @@ -82,7 +81,7 @@ describe(`generator - ${generator}`, () => { describe('regenerating with --force-git', () => { before(async () => { await helpers.runJHipster(generator).withOptions({ skipGit: false }); - await runResult.create(generatorPath).withOptions({ skipGit: false, forceGit: true, baseName: 'changed' }).run(); + await helpers.runJHipsterInApplication(generator).withOptions({ skipGit: false, forceGit: true, baseName: 'changed' }); }); it('should create 2 commits', async () => { const git = runResult.generator.createGit(); diff --git a/generators/gradle/generator.spec.ts b/generators/gradle/generator.spec.ts index 86ea4bba54c7..e76fe7cc7d05 100644 --- a/generators/gradle/generator.spec.ts +++ b/generators/gradle/generator.spec.ts @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { basename, dirname, join } from 'path'; +import { basename, dirname } from 'path'; import { fileURLToPath } from 'url'; import { before, describe, expect, it } from 'esmocha'; import { testBlueprintSupport } from '../../test/support/tests.js'; @@ -27,7 +27,6 @@ import { GENERATOR_GRADLE } from '../generator-list.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const generator = basename(__dirname); -const generatorFile = join(__dirname, 'index.js'); describe(`generator - ${generator}`, () => { it('generator-list constant matches folder name', () => { @@ -36,7 +35,7 @@ describe(`generator - ${generator}`, () => { describe('blueprint support', () => testBlueprintSupport(generator)); describe('with valid configuration', () => { before(async () => { - await helpers.run(generatorFile).withJHipsterConfig({ + await helpers.runJHipster(generator).withJHipsterConfig({ baseName: 'existing', packageName: 'tech.jhipster', }); @@ -50,7 +49,7 @@ describe(`generator - ${generator}`, () => { }); describe('with empty configuration', () => { before(async () => { - await helpers.run(generatorFile).withJHipsterConfig(); + await helpers.runJHipster(generator).withJHipsterConfig(); }); it('should generate only gradle files', () => { expect(runResult.getStateSnapshot()).toMatchSnapshot(); @@ -63,7 +62,7 @@ describe(`generator - ${generator}`, () => { describe('with custom gradleVersion', () => { const gradleVersion = 'fooVersion'; before(async () => { - await helpers.run(generatorFile).withSharedApplication({ gradleVersion }).withJHipsterConfig(); + await helpers.runJHipster(generator).withSharedApplication({ gradleVersion }).withJHipsterConfig(); }); it('should set gradleVersion at gradle-wrapper.properties', () => { runResult.assertFileContent('gradle/wrapper/gradle-wrapper.properties', `-${gradleVersion}-`); diff --git a/generators/init/generator.spec.ts b/generators/init/generator.spec.ts index c937d2c58df5..df267c5d6a13 100644 --- a/generators/init/generator.spec.ts +++ b/generators/init/generator.spec.ts @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { basename, dirname, join } from 'path'; +import { basename, dirname } from 'path'; import { fileURLToPath } from 'url'; import { before, describe, expect, it } from 'esmocha'; import { basicTests, getCommandHelpOutput, testBlueprintSupport } from '../../test/support/tests.js'; @@ -28,19 +28,16 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const generator = basename(__dirname); -const generatorPath = join(__dirname, 'index.js'); - -const contextBuilder = () => helpers.create(generatorPath); describe(`generator - ${generator}`, () => { it('generator-list constant matches folder name', () => { expect(GENERATOR_INIT).toBe(generator); }); basicTests({ + generatorNamespace: generator, requiredConfig, defaultConfig, customPrompts: {}, - contextBuilder, }); describe('blueprint support', () => testBlueprintSupport(generator)); describe('help', () => { diff --git a/generators/kubernetes-helm/kubernetes.helm.spec.ts b/generators/kubernetes-helm/kubernetes.helm.spec.ts index 6a00319f89aa..f53d1f7cc228 100644 --- a/generators/kubernetes-helm/kubernetes.helm.spec.ts +++ b/generators/kubernetes-helm/kubernetes.helm.spec.ts @@ -1,5 +1,5 @@ import { before, describe, expect, it } from 'esmocha'; -import { getGenerator, defaultHelpers as helpers, runResult } from '../../lib/testing/index.js'; +import { defaultHelpers as helpers, runResult } from '../../lib/testing/index.js'; import { GENERATOR_KUBERNETES_HELM } from '../generator-list.js'; const expectedFiles = { @@ -80,8 +80,8 @@ describe('generator - Kubernetes Helm', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_HELM)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_HELM) .withOptions({ askAnswered: true, }) @@ -96,8 +96,7 @@ describe('generator - Kubernetes Helm', () => { jhipsterConsole: false, kubernetesServiceType: 'LoadBalancer', clusteredDbApps: [], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -124,8 +123,8 @@ describe('generator - Kubernetes Helm', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_HELM)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_HELM) .withOptions({ askAnswered: true, }) @@ -139,8 +138,7 @@ describe('generator - Kubernetes Helm', () => { jhipsterConsole: false, kubernetesServiceType: 'LoadBalancer', clusteredDbApps: [], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -170,8 +168,8 @@ describe('generator - Kubernetes Helm', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_HELM)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_HELM) .withOptions({ askAnswered: true, }) @@ -185,8 +183,7 @@ describe('generator - Kubernetes Helm', () => { jhipsterConsole: true, kubernetesServiceType: 'LoadBalancer', clusteredDbApps: [], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -216,8 +213,8 @@ describe('generator - Kubernetes Helm', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_HELM)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_HELM) .withOptions({ askAnswered: true, }) @@ -233,8 +230,7 @@ describe('generator - Kubernetes Helm', () => { ingressType: 'gke', ingressDomain: 'example.com', clusteredDbApps: [], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -267,8 +263,8 @@ describe('generator - Kubernetes Helm', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_HELM)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_HELM) .withOptions({ askAnswered: true, }) @@ -282,8 +278,7 @@ describe('generator - Kubernetes Helm', () => { jhipsterConsole: false, kubernetesServiceType: 'LoadBalancer', clusteredDbApps: [], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -318,8 +313,8 @@ describe('generator - Kubernetes Helm', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_HELM)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_HELM) .withOptions({ askAnswered: true, }) @@ -334,8 +329,7 @@ describe('generator - Kubernetes Helm', () => { kubernetesServiceType: 'LoadBalancer', clusteredDbApps: [], istio: false, - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -378,8 +372,8 @@ describe('generator - Kubernetes Helm', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_HELM)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_HELM) .withOptions({ askAnswered: true, }) @@ -393,8 +387,7 @@ describe('generator - Kubernetes Helm', () => { jhipsterConsole: false, kubernetesServiceType: 'LoadBalancer', clusteredDbApps: [], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -420,8 +413,8 @@ describe('generator - Kubernetes Helm', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_HELM)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_HELM) .withOptions({ askAnswered: true, }) @@ -435,8 +428,7 @@ describe('generator - Kubernetes Helm', () => { jhipsterConsole: false, kubernetesServiceType: 'LoadBalancer', clusteredDbApps: [], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -461,8 +453,8 @@ describe('generator - Kubernetes Helm', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_HELM)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_HELM) .withOptions({ askAnswered: true, }) @@ -475,8 +467,7 @@ describe('generator - Kubernetes Helm', () => { kubernetesNamespace: 'mynamespace', monitoring: 'prometheus', kubernetesServiceType: 'LoadBalancer', - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -510,8 +501,8 @@ describe('generator - Kubernetes Helm', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_HELM)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_HELM) .withOptions({ askAnswered: true, }) @@ -525,8 +516,7 @@ describe('generator - Kubernetes Helm', () => { ingressDomain: 'example.com', clusteredDbApps: [], istio: true, - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); diff --git a/generators/kubernetes-knative/knative.spec.ts b/generators/kubernetes-knative/knative.spec.ts index bacfcbacfb78..9f9965c7a181 100644 --- a/generators/kubernetes-knative/knative.spec.ts +++ b/generators/kubernetes-knative/knative.spec.ts @@ -1,5 +1,5 @@ import { before, describe, expect, it } from 'esmocha'; -import { getGenerator, defaultHelpers as helpers, runResult } from '../../lib/testing/index.js'; +import { defaultHelpers as helpers, runResult } from '../../lib/testing/index.js'; import { GENERATOR_KUBERNETES_KNATIVE } from '../generator-list.js'; const expectedFiles = { @@ -106,8 +106,8 @@ describe('generator - Knative', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_KNATIVE) .withOptions({ askAnswered: true, }) @@ -123,8 +123,7 @@ describe('generator - Knative', () => { clusteredDbApps: [], generatorType: 'k8s', istio: true, - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -151,8 +150,8 @@ describe('generator - Knative', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_KNATIVE) .withOptions({ askAnswered: true, }) @@ -167,8 +166,7 @@ describe('generator - Knative', () => { clusteredDbApps: [], generatorType: 'k8s', istio: true, - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -196,8 +194,8 @@ describe('generator - Knative', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_KNATIVE) .withOptions({ askAnswered: true, }) @@ -212,8 +210,7 @@ describe('generator - Knative', () => { clusteredDbApps: [], generatorType: 'k8s', istio: true, - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -241,8 +238,8 @@ describe('generator - Knative', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_KNATIVE) .withOptions({ askAnswered: true, }) @@ -258,8 +255,7 @@ describe('generator - Knative', () => { clusteredDbApps: [], generatorType: 'k8s', istio: true, - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -284,8 +280,8 @@ describe('generator - Knative', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_KNATIVE) .withOptions({ askAnswered: true, }) @@ -300,8 +296,7 @@ describe('generator - Knative', () => { clusteredDbApps: [], generatorType: 'k8s', istio: true, - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -332,8 +327,8 @@ describe('generator - Knative', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_KNATIVE) .withOptions({ askAnswered: true, }) @@ -348,8 +343,7 @@ describe('generator - Knative', () => { clusteredDbApps: [], generatorType: 'k8s', istio: true, - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -389,8 +383,8 @@ describe('generator - Knative', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_KNATIVE) .withOptions({ askAnswered: true, }) @@ -404,8 +398,7 @@ describe('generator - Knative', () => { monitoring: 'prometheus', generatorType: 'k8s', istio: true, - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -436,8 +429,8 @@ describe('generator - Knative', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_KNATIVE) .withOptions({ askAnswered: true, }) @@ -452,8 +445,7 @@ describe('generator - Knative', () => { clusteredDbApps: [], generatorType: 'k8s', istio: true, - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -483,8 +475,8 @@ describe('generator - Knative', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_KNATIVE) .withOptions({ askAnswered: true, }) @@ -500,8 +492,7 @@ describe('generator - Knative', () => { clusteredDbApps: [], generatorType: 'helm', istio: true, - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -528,8 +519,8 @@ describe('generator - Knative', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_KNATIVE) .withOptions({ askAnswered: true, }) @@ -544,8 +535,7 @@ describe('generator - Knative', () => { clusteredDbApps: [], generatorType: 'helm', istio: true, - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -575,8 +565,8 @@ describe('generator - Knative', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_KNATIVE) .withOptions({ askAnswered: true, }) @@ -591,8 +581,7 @@ describe('generator - Knative', () => { clusteredDbApps: [], generatorType: 'helm', istio: true, - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -622,8 +611,8 @@ describe('generator - Knative', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_KNATIVE) .withOptions({ askAnswered: true, }) @@ -639,8 +628,7 @@ describe('generator - Knative', () => { clusteredDbApps: [], generatorType: 'helm', istio: true, - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -672,8 +660,8 @@ describe('generator - Knative', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_KNATIVE) .withOptions({ askAnswered: true, }) @@ -688,8 +676,7 @@ describe('generator - Knative', () => { clusteredDbApps: [], generatorType: 'helm', istio: true, - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -724,8 +711,8 @@ describe('generator - Knative', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_KNATIVE) .withOptions({ askAnswered: true, }) @@ -741,8 +728,7 @@ describe('generator - Knative', () => { clusteredDbApps: [], generatorType: 'helm', istio: true, - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -785,8 +771,8 @@ describe('generator - Knative', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_KNATIVE) .withOptions({ askAnswered: true, }) @@ -800,8 +786,7 @@ describe('generator - Knative', () => { monitoring: 'prometheus', generatorType: 'helm', istio: true, - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -835,8 +820,8 @@ describe('generator - Knative', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES_KNATIVE) .withOptions({ askAnswered: true, }) @@ -851,8 +836,7 @@ describe('generator - Knative', () => { clusteredDbApps: [], generatorType: 'helm', istio: true, - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); diff --git a/generators/kubernetes/kubernetes.spec.ts b/generators/kubernetes/kubernetes.spec.ts index 061e052ea254..698e02374d38 100644 --- a/generators/kubernetes/kubernetes.spec.ts +++ b/generators/kubernetes/kubernetes.spec.ts @@ -1,5 +1,5 @@ import { before, describe, expect, it } from 'esmocha'; -import { getGenerator, defaultHelpers as helpers, runResult } from '../../lib/testing/index.js'; +import { defaultHelpers as helpers, runResult } from '../../lib/testing/index.js'; import { GENERATOR_KUBERNETES } from '../generator-list.js'; const expectedFiles = { @@ -52,8 +52,8 @@ describe('generator - Kubernetes', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES) .withSpawnMock() .withOptions({ askAnswered: true, @@ -71,8 +71,7 @@ describe('generator - Kubernetes', () => { clusteredDbApps: [], kubernetesUseDynamicStorage: true, kubernetesStorageClassName: '', - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -103,8 +102,8 @@ describe('generator - Kubernetes', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES) .withSpawnMock() .withOptions({ askAnswered: true, @@ -121,8 +120,7 @@ describe('generator - Kubernetes', () => { clusteredDbApps: [], kubernetesUseDynamicStorage: true, kubernetesStorageClassName: '', - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -153,8 +151,8 @@ describe('generator - Kubernetes', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES) .withSpawnMock() .withOptions({ askAnswered: true, @@ -171,8 +169,7 @@ describe('generator - Kubernetes', () => { clusteredDbApps: [], kubernetesUseDynamicStorage: true, kubernetesStorageClassName: '', - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -203,8 +200,8 @@ describe('generator - Kubernetes', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES) .withSpawnMock() .withOptions({ askAnswered: true, @@ -221,8 +218,7 @@ describe('generator - Kubernetes', () => { clusteredDbApps: [], kubernetesUseDynamicStorage: true, kubernetesStorageClassName: '', - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -253,8 +249,8 @@ describe('generator - Kubernetes', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES) .withSpawnMock() .withOptions({ askAnswered: true, @@ -271,8 +267,7 @@ describe('generator - Kubernetes', () => { clusteredDbApps: [], kubernetesUseDynamicStorage: true, kubernetesStorageClassName: '', - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -303,8 +298,8 @@ describe('generator - Kubernetes', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES) .withSpawnMock() .withOptions({ askAnswered: true, @@ -322,8 +317,7 @@ describe('generator - Kubernetes', () => { clusteredDbApps: [], kubernetesUseDynamicStorage: true, kubernetesStorageClassName: '', - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -360,8 +354,8 @@ describe('generator - Kubernetes', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES) .withSpawnMock() .withOptions({ askAnswered: true, @@ -378,8 +372,7 @@ describe('generator - Kubernetes', () => { clusteredDbApps: [], kubernetesUseDynamicStorage: true, kubernetesStorageClassName: '', - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -416,8 +409,8 @@ describe('generator - Kubernetes', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES) .withSpawnMock() .withOptions({ askAnswered: true, @@ -434,8 +427,7 @@ describe('generator - Kubernetes', () => { clusteredDbApps: [], kubernetesUseDynamicStorage: true, kubernetesStorageClassName: '', - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -469,8 +461,8 @@ describe('generator - Kubernetes', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES) .withSpawnMock() .withOptions({ askAnswered: true, @@ -487,8 +479,7 @@ describe('generator - Kubernetes', () => { clusteredDbApps: [], kubernetesUseDynamicStorage: true, kubernetesStorageClassName: '', - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -531,8 +522,8 @@ describe('generator - Kubernetes', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES) .withSpawnMock() .withOptions({ askAnswered: true, @@ -549,8 +540,7 @@ describe('generator - Kubernetes', () => { clusteredDbApps: [], kubernetesUseDynamicStorage: true, kubernetesStorageClassName: '', - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -579,8 +569,8 @@ describe('generator - Kubernetes', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES) .withSpawnMock() .withOptions({ askAnswered: true, @@ -597,8 +587,7 @@ describe('generator - Kubernetes', () => { clusteredDbApps: [], kubernetesUseDynamicStorage: true, kubernetesStorageClassName: '', - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -627,8 +616,8 @@ describe('generator - Kubernetes', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES) .withSpawnMock() .withOptions({ askAnswered: true, @@ -644,8 +633,7 @@ describe('generator - Kubernetes', () => { kubernetesServiceType: 'LoadBalancer', kubernetesUseDynamicStorage: true, kubernetesStorageClassName: '', - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -679,8 +667,8 @@ describe('generator - Kubernetes', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES) .withSpawnMock() .withOptions({ askAnswered: true, @@ -697,8 +685,7 @@ describe('generator - Kubernetes', () => { istio: true, kubernetesUseDynamicStorage: true, kubernetesStorageClassName: '', - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -729,8 +716,8 @@ describe('generator - Kubernetes', () => { .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - await runResult - .create(getGenerator(GENERATOR_KUBERNETES)) + await helpers + .runJHipsterInApplication(GENERATOR_KUBERNETES) .withSpawnMock() .withOptions({ askAnswered: true, @@ -747,8 +734,7 @@ describe('generator - Kubernetes', () => { clusteredDbApps: [], kubernetesUseDynamicStorage: true, kubernetesStorageClassName: '', - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); diff --git a/generators/languages/languages.spec.ts b/generators/languages/languages.spec.ts index 80e6f8acaf78..dc501d17b357 100644 --- a/generators/languages/languages.spec.ts +++ b/generators/languages/languages.spec.ts @@ -1,5 +1,5 @@ import { fileURLToPath } from 'url'; -import { basename, dirname, join } from 'path'; +import { basename, dirname } from 'path'; import { before, describe, it } from 'esmocha'; import { basicHelpers, defaultHelpers as helpers, result as runResult } from '../../lib/testing/index.js'; @@ -10,7 +10,6 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const generator = basename(__dirname); -const generatorPath = join(__dirname, 'index.js'); const createClientProject = (options?) => basicHelpers @@ -99,14 +98,13 @@ describe('generator - languages', () => { describe(`with prompts for ${language.name}`, () => { before(() => helpers - .create(generatorPath) + .runJHipster(generator) .withOptions({ ignoreNeedlesError: true }) .withAnswers({ enableTranslation: true, nativeLanguage: language.languageTag, languages: [language.languageTag], - }) - .run(), + }), ); containsLanguageFiles(language.languageTag); }); @@ -277,20 +275,19 @@ describe('generator - languages', () => { describe('Creates default i18n files for Vue applications', () => { describe('using prompts', () => { before(async () => { - const result = await createClientProject().withJHipsterConfig({ + await createClientProject().withJHipsterConfig({ clientFramework: 'vue', enableTranslation: true, nativeLanguage: 'en', }); - await result - .create('jhipster:languages') + await helpers + .runJHipsterInApplication('jhipster:languages') .withAnswers({ languages: ['fr', 'de'], }) .withOptions({ commandName: 'languages', - }) - .run(); + }); }); it('creates expected configuration values', () => { runResult.assertJsonFileContent('.yo-rc.json', { @@ -315,18 +312,14 @@ describe('generator - languages', () => { describe('using arguments', () => { before(async () => { - const result = await createClientProject().withJHipsterConfig({ + await createClientProject().withJHipsterConfig({ clientFramework: 'vue', enableTranslation: true, nativeLanguage: 'en', }); - await result - .create('jhipster:languages') - .withArguments(['fr', 'de']) - .withOptions({ - baseName: 'jhipster', - }) - .run(); + await helpers.runJHipsterInApplication('jhipster:languages').withArguments(['fr', 'de']).withOptions({ + baseName: 'jhipster', + }); }); it('creates expected configuration values', () => { runResult.assertJsonFileContent('.yo-rc.json', { diff --git a/generators/liquibase/incremental-liquibase.spec.ts b/generators/liquibase/incremental-liquibase.spec.ts index 3baed9a5b803..7b3cd00aed2a 100644 --- a/generators/liquibase/incremental-liquibase.spec.ts +++ b/generators/liquibase/incremental-liquibase.spec.ts @@ -274,7 +274,7 @@ describe('generator - app - --incremental-changelog', function () { .runJDL(jdlApplicationWithRelationshipToUser) .withMockedSource({ except: exceptSourceMethods }) .withMockedJHipsterGenerators({ except: exceptMockedGenerators }); - await runResult.create('jhipster:jdl').withOptions({ + await helpers.runJHipsterInApplication('jhipster:jdl').withOptions({ inline: jdlApplicationWithRelationshipToUser, creationTimestamp: '2020-01-02', }); diff --git a/generators/maven/generator.spec.ts b/generators/maven/generator.spec.ts index 748ff3c8cec5..32263bf98372 100644 --- a/generators/maven/generator.spec.ts +++ b/generators/maven/generator.spec.ts @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { basename, dirname, join } from 'path'; +import { basename, dirname } from 'path'; import { fileURLToPath } from 'url'; import { before, describe, expect, it } from 'esmocha'; import { testBlueprintSupport } from '../../test/support/tests.js'; @@ -27,7 +27,6 @@ import MavenGenerator from './generator.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const generator = basename(__dirname); -const generatorFile = join(__dirname, 'index.js'); describe(`generator - ${generator}`, () => { it('generator-list constant matches folder name', () => { @@ -36,7 +35,7 @@ describe(`generator - ${generator}`, () => { describe('blueprint support', () => testBlueprintSupport(generator)); describe('with valid configuration', () => { before(async () => { - await helpers.run(generatorFile).withJHipsterConfig({ + await helpers.runJHipster(generator).withJHipsterConfig({ baseName: 'existing', packageName: 'tech.jhipster', }); @@ -47,7 +46,7 @@ describe(`generator - ${generator}`, () => { }); describe('with empty configuration', () => { before(async () => { - await helpers.run(generatorFile).withJHipsterConfig(); + await helpers.runJHipster(generator).withJHipsterConfig(); }); it('should generate only maven files', () => { expect(runResult.getStateSnapshot()).toMatchSnapshot(); diff --git a/generators/react/generator.spec.ts b/generators/react/generator.spec.ts index d40b281b692c..33ceee03817d 100644 --- a/generators/react/generator.spec.ts +++ b/generators/react/generator.spec.ts @@ -1,4 +1,4 @@ -import { basename, dirname, join } from 'path'; +import { basename, dirname } from 'path'; import { fileURLToPath } from 'url'; import { before, describe, expect, it } from 'esmocha'; import { snakeCase } from 'lodash-es'; @@ -16,7 +16,6 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const generator = basename(__dirname); -const generatorFile = join(__dirname, 'index.ts'); const { REACT: clientFramework } = clientFrameworkTypes; const commonConfig = { clientFramework, nativeLanguage: 'en', languages: ['fr', 'en'] }; @@ -59,7 +58,7 @@ describe(`generator - ${clientFramework}`, () => { describe(name, () => { before(async () => { await helpers - .run(generatorFile) + .runJHipster(generator) .withJHipsterConfig(sampleConfig, entities) .withSharedApplication({ gatewayServicesApiAvailable: sampleConfig.applicationType === 'gateway' }) .withGenerators([[MockedLanguagesGenerator, { namespace: 'jhipster:languages' }]]) diff --git a/generators/spring-cloud-stream/generator-pulsar.spec.ts b/generators/spring-cloud-stream/generator-pulsar.spec.ts index 9ebd5b5921bb..a28402731397 100644 --- a/generators/spring-cloud-stream/generator-pulsar.spec.ts +++ b/generators/spring-cloud-stream/generator-pulsar.spec.ts @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { basename, dirname, join } from 'path'; +import { basename, dirname } from 'path'; import { fileURLToPath } from 'url'; import { before, describe, expect, it } from 'esmocha'; import { snakeCase } from 'lodash-es'; @@ -32,7 +32,6 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const generator = basename(__dirname); -const generatorFile = join(__dirname, 'index.ts'); const commonConfig = { messageBroker: PULSAR }; @@ -48,7 +47,7 @@ describe(`generator - ${generator}`, () => { Object.entries(testSamples).forEach(([name, config]) => { describe(name, () => { before(async () => { - await helpers.run(generatorFile).withJHipsterConfig(config); + await helpers.runJHipster(generator).withJHipsterConfig(config); }); it('should match generated files snapshot', () => { diff --git a/generators/upgrade/upgrade.spec.ts b/generators/upgrade/upgrade.spec.ts index 65d96600295b..3a2234985270 100644 --- a/generators/upgrade/upgrade.spec.ts +++ b/generators/upgrade/upgrade.spec.ts @@ -1,18 +1,14 @@ -import path, { dirname } from 'path'; -import { fileURLToPath } from 'url'; +import path from 'path'; import { mkdirSync, writeFileSync } from 'fs'; import { escapeRegExp } from 'lodash-es'; import { before, describe, expect, it } from 'esmocha'; import { execaCommandSync } from 'execa'; import { packageJson } from '../../lib/index.js'; import { GENERATOR_APP, GENERATOR_UPGRADE } from '../generator-list.js'; -import { getGenerator, basicHelpers as helpers, result as runResult } from '../../lib/testing/index.js'; +import { basicHelpers as helpers, result as runResult } from '../../lib/testing/index.js'; const writeJsonSync = (file, content) => writeFileSync(file, JSON.stringify(content, null, 2)); -const __filename = fileURLToPath(import.meta.url); -const __dirname = dirname(__filename); - describe('generator - upgrade', function () { describe('default application', () => { before(async () => { @@ -24,11 +20,10 @@ describe('generator - upgrade', function () { baseName: 'upgradeTest', }) .withOptions({ skipGit: false, useVersionPlaceholders: false }); - await runResult - .create(getGenerator(GENERATOR_UPGRADE)) + await helpers + .runJHipsterInApplication(GENERATOR_UPGRADE) .withSpawnMock() - .withOptions({ useVersionPlaceholders: false } as any) - .run(); + .withOptions({ useVersionPlaceholders: false } as any); }); it('generated git commits to match snapshot', () => { @@ -72,8 +67,8 @@ Initial version of upgradeTest generated by generator-jhipster@undefined" writeJsonSync(path.join(fakeBlueprintModuleDir, 'package.json'), packagejs); // Create an fake generator, otherwise env.lookup doesn't find it. writeFileSync(path.join(fakeBlueprintModuleDir, 'generators', 'fake', 'index.js'), ''); - return helpers - .create(path.join(__dirname, '../generators/app/index.js'), { tmpdir: false }) + await helpers + .runJHipster('app', { tmpdir: false }) .withJHipsterConfig({ skipClient: true, skipServer: true, @@ -82,18 +77,12 @@ Initial version of upgradeTest generated by generator-jhipster@undefined" .withOptions({ skipGit: false, blueprints: blueprintName, - }) - .run() - .then(() => { - return helpers - .create(path.join(__dirname, '../generators/upgrade/index.js'), { tmpdir: false }) - .withOptions({ - force: true, - silent: false, - targetVersion: packageJson.version, - }) - .run(); }); + await helpers.runJHipsterInApplication('upgrade').withOptions({ + force: true, + silent: false, + targetVersion: packageJson.version, + }); }); it('generated git commits to match snapshot', () => { diff --git a/generators/vue/generator.spec.ts b/generators/vue/generator.spec.ts index a6c515e0a301..77ef9c93d759 100644 --- a/generators/vue/generator.spec.ts +++ b/generators/vue/generator.spec.ts @@ -1,4 +1,4 @@ -import { basename, dirname, join } from 'path'; +import { basename, dirname } from 'path'; import { fileURLToPath } from 'url'; import { before, describe, expect, it } from 'esmocha'; import { snakeCase } from 'lodash-es'; @@ -15,7 +15,6 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const generator = basename(__dirname); -const generatorFile = join(__dirname, 'index.ts'); const { VUE: clientFramework } = clientFrameworkTypes; const commonConfig = { clientFramework, nativeLanguage: 'en', languages: ['fr', 'en'] }; @@ -68,7 +67,7 @@ describe(`generator - ${clientFramework}`, () => { describe(name, () => { before(async () => { await helpers - .run(generatorFile) + .runJHipster(generator) .withJHipsterConfig(sampleConfig, entities) .withControl({ getWebappTranslation: () => 'translations' }) .withSharedApplication({ gatewayServicesApiAvailable: sampleConfig.applicationType === 'gateway' }) diff --git a/lib/index.ts b/lib/index.ts index 9815d74355c2..3aa6f9620427 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -6,13 +6,18 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); export const isDistFolder = () => { - return basename(join(__dirname, '..')) === 'dist'; + return basename(dirname(__dirname)) === 'dist'; }; export const getPackageRoot = (relativePath?: string) => { - const sourceRoot = join(__dirname, '..'); - const packageDirectory = isDistFolder() ? join(sourceRoot, '..') : sourceRoot; + const sourceRoot = dirname(__dirname); + const packageDirectory = isDistFolder() ? dirname(sourceRoot) : sourceRoot; return relativePath ? join(packageDirectory, relativePath) : packageDirectory; }; +export const getSourceRoot = (relativePath?: string) => { + const sourceRoot = dirname(__dirname); + return relativePath ? join(sourceRoot, relativePath) : sourceRoot; +}; + export const packageJson = JSON.parse(readFileSync(getPackageRoot('package.json')).toString()); diff --git a/lib/testing/__snapshots__/helpers.spec.ts.snap b/lib/testing/__snapshots__/helpers.spec.ts.snap new file mode 100644 index 000000000000..eb662d922656 --- /dev/null +++ b/lib/testing/__snapshots__/helpers.spec.ts.snap @@ -0,0 +1,244 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`helpers run using withJHipsterGenerators should register jhipster generators namespaces 1`] = ` +[ + "jhipster:angular", + "jhipster:app", + "jhipster:base", + "jhipster:base-application", + "jhipster:base-core", + "jhipster:base-entity-changes", + "jhipster:base-workspaces", + "jhipster:bootstrap", + "jhipster:bootstrap-application", + "jhipster:bootstrap-application-base", + "jhipster:bootstrap-application-client", + "jhipster:bootstrap-application-server", + "jhipster:bootstrap-workspaces", + "jhipster:ci-cd", + "jhipster:client", + "jhipster:client:common", + "jhipster:common", + "jhipster:cucumber", + "jhipster:cypress", + "jhipster:docker", + "jhipster:docker-compose", + "jhipster:entities", + "jhipster:entity", + "jhipster:export-jdl", + "jhipster:feign-client", + "jhipster:gatling", + "jhipster:generate-blueprint", + "jhipster:git", + "jhipster:gradle", + "jhipster:gradle:code-quality", + "jhipster:gradle:jib", + "jhipster:gradle:node-gradle", + "jhipster:heroku", + "jhipster:info", + "jhipster:init", + "jhipster:java", + "jhipster:java:bootstrap", + "jhipster:java:build-tool", + "jhipster:java:code-quality", + "jhipster:java:domain", + "jhipster:java:jib", + "jhipster:java:node", + "jhipster:java:openapi-generator", + "jhipster:javascript:bootstrap", + "jhipster:javascript:eslint", + "jhipster:javascript:husky", + "jhipster:javascript:prettier", + "jhipster:jdl", + "jhipster:kubernetes", + "jhipster:kubernetes-helm", + "jhipster:kubernetes-knative", + "jhipster:languages", + "jhipster:liquibase", + "jhipster:maven", + "jhipster:maven:code-quality", + "jhipster:maven:frontend-plugin", + "jhipster:maven:jib", + "jhipster:project-name", + "jhipster:react", + "jhipster:server", + "jhipster:spring-boot", + "jhipster:spring-cache", + "jhipster:spring-cloud-stream", + "jhipster:spring-cloud-stream:kafka", + "jhipster:spring-cloud-stream:pulsar", + "jhipster:spring-cloud:gateway", + "jhipster:spring-data-cassandra", + "jhipster:spring-data-couchbase", + "jhipster:spring-data-elasticsearch", + "jhipster:spring-data-mongodb", + "jhipster:spring-data-neo4j", + "jhipster:spring-data-relational", + "jhipster:spring-websocket", + "jhipster:upgrade", + "jhipster:vue", + "jhipster:workspaces", +] +`; + +exports[`helpers runJHipster defaults should register jhipster generators namespaces 1`] = ` +[ + "jhipster:angular", + "jhipster:app", + "jhipster:base", + "jhipster:base-application", + "jhipster:base-core", + "jhipster:base-entity-changes", + "jhipster:base-workspaces", + "jhipster:bootstrap", + "jhipster:bootstrap-application", + "jhipster:bootstrap-application-base", + "jhipster:bootstrap-application-client", + "jhipster:bootstrap-application-server", + "jhipster:bootstrap-workspaces", + "jhipster:ci-cd", + "jhipster:client", + "jhipster:client:common", + "jhipster:common", + "jhipster:cucumber", + "jhipster:cypress", + "jhipster:docker", + "jhipster:docker-compose", + "jhipster:entities", + "jhipster:entity", + "jhipster:export-jdl", + "jhipster:feign-client", + "jhipster:gatling", + "jhipster:generate-blueprint", + "jhipster:git", + "jhipster:gradle", + "jhipster:gradle:code-quality", + "jhipster:gradle:jib", + "jhipster:gradle:node-gradle", + "jhipster:heroku", + "jhipster:info", + "jhipster:init", + "jhipster:java", + "jhipster:java:bootstrap", + "jhipster:java:build-tool", + "jhipster:java:code-quality", + "jhipster:java:domain", + "jhipster:java:jib", + "jhipster:java:node", + "jhipster:java:openapi-generator", + "jhipster:javascript:bootstrap", + "jhipster:javascript:eslint", + "jhipster:javascript:husky", + "jhipster:javascript:prettier", + "jhipster:jdl", + "jhipster:kubernetes", + "jhipster:kubernetes-helm", + "jhipster:kubernetes-knative", + "jhipster:languages", + "jhipster:liquibase", + "jhipster:maven", + "jhipster:maven:code-quality", + "jhipster:maven:frontend-plugin", + "jhipster:maven:jib", + "jhipster:project-name", + "jhipster:react", + "jhipster:server", + "jhipster:spring-boot", + "jhipster:spring-cache", + "jhipster:spring-cloud-stream", + "jhipster:spring-cloud-stream:kafka", + "jhipster:spring-cloud-stream:pulsar", + "jhipster:spring-cloud:gateway", + "jhipster:spring-data-cassandra", + "jhipster:spring-data-couchbase", + "jhipster:spring-data-elasticsearch", + "jhipster:spring-data-mongodb", + "jhipster:spring-data-neo4j", + "jhipster:spring-data-relational", + "jhipster:spring-websocket", + "jhipster:upgrade", + "jhipster:vue", + "jhipster:workspaces", +] +`; + +exports[`helpers runJHipster with useDefaultMocks should register jhipster generators namespaces 1`] = ` +[ + "jhipster:angular", + "jhipster:app", + "jhipster:base", + "jhipster:base-application", + "jhipster:base-core", + "jhipster:base-entity-changes", + "jhipster:base-workspaces", + "jhipster:bootstrap", + "jhipster:bootstrap-application", + "jhipster:bootstrap-application-base", + "jhipster:bootstrap-application-client", + "jhipster:bootstrap-application-server", + "jhipster:bootstrap-workspaces", + "jhipster:ci-cd", + "jhipster:client", + "jhipster:client:common", + "jhipster:common", + "jhipster:cucumber", + "jhipster:cypress", + "jhipster:docker", + "jhipster:docker-compose", + "jhipster:entities", + "jhipster:entity", + "jhipster:export-jdl", + "jhipster:feign-client", + "jhipster:gatling", + "jhipster:generate-blueprint", + "jhipster:git", + "jhipster:gradle", + "jhipster:gradle:code-quality", + "jhipster:gradle:jib", + "jhipster:gradle:node-gradle", + "jhipster:heroku", + "jhipster:info", + "jhipster:init", + "jhipster:java", + "jhipster:java:bootstrap", + "jhipster:java:build-tool", + "jhipster:java:code-quality", + "jhipster:java:domain", + "jhipster:java:jib", + "jhipster:java:node", + "jhipster:java:openapi-generator", + "jhipster:javascript:bootstrap", + "jhipster:javascript:eslint", + "jhipster:javascript:husky", + "jhipster:javascript:prettier", + "jhipster:jdl", + "jhipster:kubernetes", + "jhipster:kubernetes-helm", + "jhipster:kubernetes-knative", + "jhipster:languages", + "jhipster:liquibase", + "jhipster:maven", + "jhipster:maven:code-quality", + "jhipster:maven:frontend-plugin", + "jhipster:maven:jib", + "jhipster:project-name", + "jhipster:react", + "jhipster:server", + "jhipster:spring-boot", + "jhipster:spring-cache", + "jhipster:spring-cloud-stream", + "jhipster:spring-cloud-stream:kafka", + "jhipster:spring-cloud-stream:pulsar", + "jhipster:spring-cloud:gateway", + "jhipster:spring-data-cassandra", + "jhipster:spring-data-couchbase", + "jhipster:spring-data-elasticsearch", + "jhipster:spring-data-mongodb", + "jhipster:spring-data-neo4j", + "jhipster:spring-data-relational", + "jhipster:spring-websocket", + "jhipster:upgrade", + "jhipster:vue", + "jhipster:workspaces", +] +`; diff --git a/lib/testing/get-generator.ts b/lib/testing/get-generator.ts index c1587fedb43a..1f979840af4a 100644 --- a/lib/testing/get-generator.ts +++ b/lib/testing/get-generator.ts @@ -1,12 +1,17 @@ -import { dirname, resolve } from 'path'; +import { dirname, join, resolve } from 'path'; import { existsSync } from 'fs'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); +export const getGeneratorRelativeFolder = (generatorName: string) => { + generatorName = generatorName.replace('jhipster:', ''); + return join('generators', generatorName.split(':').join('/generators/')); +}; + export const getGeneratorFolder = (generatorName: string) => { - return resolve(__dirname, '../../generators', generatorName.split(':').join('/generators/')); + return resolve(__dirname, '../..', getGeneratorRelativeFolder(generatorName)); }; const getGenerator = (generatorName: string) => { diff --git a/lib/testing/helpers.spec.ts b/lib/testing/helpers.spec.ts new file mode 100644 index 000000000000..d51c8a086a6f --- /dev/null +++ b/lib/testing/helpers.spec.ts @@ -0,0 +1,57 @@ +import { before, describe, expect, it } from 'esmocha'; +import { defaultHelpers as helpers, runResult } from './helpers.js'; + +const DUMMY_NAMESPACE = 'jhipster:dummy'; + +describe('helpers', () => { + describe('run defaults', () => { + before(async () => { + await helpers.run(helpers.createDummyGenerator(), { namespace: DUMMY_NAMESPACE }); + }); + it('should register not jhipster generators namespaces', () => { + expect( + Object.keys(runResult.env.store._meta) + .filter(ns => ns !== DUMMY_NAMESPACE) + .sort(), + ).toHaveLength(0); + }); + }); + describe('runJHipster defaults', () => { + before(async () => { + await helpers.runJHipster('dummy').withGenerators([[helpers.createDummyGenerator(), { namespace: DUMMY_NAMESPACE }]]); + }); + it('should register jhipster generators namespaces', () => { + expect( + Object.keys(runResult.env.store._meta) + .filter(ns => ns !== DUMMY_NAMESPACE) + .sort(), + ).toMatchSnapshot(); + }); + }); + describe('run using withJHipsterGenerators', () => { + before(async () => { + await helpers.run(helpers.createDummyGenerator(), { namespace: DUMMY_NAMESPACE }).withJHipsterGenerators(); + }); + it('should register jhipster generators namespaces', () => { + expect( + Object.keys(runResult.env.store._meta) + .filter(ns => ns !== DUMMY_NAMESPACE) + .sort(), + ).toMatchSnapshot(); + }); + }); + describe('runJHipster with useDefaultMocks', () => { + before(async () => { + await helpers + .runJHipster('dummy', { useDefaultMocks: true }) + .withGenerators([[helpers.createDummyGenerator(), { namespace: DUMMY_NAMESPACE }]]); + }); + it('should register jhipster generators namespaces', () => { + expect( + Object.keys(runResult.env.store._meta) + .filter(ns => ns !== DUMMY_NAMESPACE) + .sort(), + ).toMatchSnapshot(); + }); + }); +}); diff --git a/lib/testing/helpers.ts b/lib/testing/helpers.ts index a3d28e39c097..9185eff065e8 100644 --- a/lib/testing/helpers.ts +++ b/lib/testing/helpers.ts @@ -1,4 +1,4 @@ -import { basename, dirname, join } from 'path'; +import { basename, dirname, isAbsolute, join } from 'path'; import { mock } from 'node:test'; import { merge, set, snakeCase } from 'lodash-es'; import type { RunContextSettings, RunResult } from 'yeoman-test'; @@ -13,16 +13,35 @@ import { GENERATOR_WORKSPACES } from '../../generators/generator-list.js'; import { createJHipsterLogger, normalizePathEnd, parseCreationTimestamp } from '../../generators/base/support/index.js'; import BaseGenerator from '../../generators/base/index.js'; import type { JHipsterGeneratorOptions } from '../../generators/base/api.js'; -import { getPackageRoot, isDistFolder } from '../index.js'; +import { getPackageRoot, getSourceRoot, isDistFolder } from '../index.js'; import type CoreGenerator from '../../generators/base-core/generator.js'; import type { ApplicationConfiguration } from '../types/application/yo-rc.js'; import { getDefaultJDLApplicationConfig } from '../command/jdl.js'; import type { Entity } from '../types/base/entity.js'; import { buildJHipster, createProgram } from '../../cli/program.mjs'; -import getGenerator from './get-generator.js'; +import getGenerator, { getGeneratorRelativeFolder } from './get-generator.js'; type GeneratorTestType = YeomanGenerator; type GeneratorTestOptions = JHipsterGeneratorOptions; +type WithJHipsterGenerators = { + /** + * Apply default mocks. + */ + useDefaultMocks?: boolean; + /** + * List of generators to don't mock. + */ + actualGeneratorsList?: string[]; + /** + * Filter to mock a generator. + */ + useMock?: (ns: string) => boolean; + /** + * Use the EnviromentBuilder default preparation to create the environment. + * Includes local and dev blueprints. + */ + useEnvironmentBuilder?: boolean; +}; type JHipsterRunResult = RunResult & { /** @@ -34,6 +53,9 @@ type JHipsterRunResult = Ru * Composed generators that were mocked. */ composedMockedGenerators: string[]; + + // eslint-disable-next-line no-use-before-define + createJHipster: (ns: string, options?: WithJHipsterGenerators) => JHipsterRunContext; }; const runResult = result as JHipsterRunResult; @@ -44,7 +66,8 @@ const DEFAULT_TEST_SETTINGS = { forwardCwd: true }; const DEFAULT_TEST_OPTIONS = { skipInstall: true }; const DEFAULT_TEST_ENV_OPTIONS = { skipInstall: true, dryRun: false }; -const generatorsDir = join(getPackageRoot(), 'generators'); +const toJHipsterNamespace = (ns: string) => (/^jhipster[:-]/.test(ns) ? ns : `jhipster:${ns}`); +const generatorsDir = getSourceRoot('generators'); const allGenerators = [ ...globSync('*/index.{j,t}s', { cwd: generatorsDir, posix: true }).map(file => dirname(file)), ...globSync('*/generators/*/index.{j,t}s', { cwd: generatorsDir, posix: true }).map(file => dirname(file).replace('/generators/', ':')), @@ -61,6 +84,8 @@ const defaultSharedApplication = Object.fromEntries(['CLIENT_WEBPACK_DIR'].map(k let defaultMockFactory: (original?: any) => any; let defaultAccumulateMockArgs: (mocks: Record) => Record; +const createEnvBuilderEnvironment = (...args) => EnvironmentBuilder.createEnv(...args); + export const defineDefaults = async ( defaults: { /** @deprecated mock from `node:test` is used internally */ @@ -216,14 +241,9 @@ class JHipsterRunContext extends RunContext { }); } + /** @deprecated use withJHipsterGenerators */ withJHipsterLookup(): this { - return this.withLookups([ - { - packagePaths: [getPackageRoot()], - // @ts-expect-error lookups is not exported - lookups: [`${isDistFolder() ? 'dist/' : ''}generators`, `${isDistFolder() ? 'dist/' : ''}generators/*/generators`], - }, - ]); + return this.withJHipsterGenerators(); } /** @@ -306,12 +326,30 @@ class JHipsterRunContext extends RunContext { withMockedJHipsterGenerators(options: string[] | { except?: string[]; filter?: (string) => boolean } = {}): this { const optionsObj = Array.isArray(options) ? { except: options } : options; const { except = [], filter = filterBootstrapGenerators } = optionsObj; - const jhipsterExceptList = except.map(gen => (gen.startsWith('jhipster:') ? gen : `jhipster:${gen}`)); + const jhipsterExceptList = except.map(toJHipsterNamespace); return this.withMockedGenerators( allGenerators.filter(filter).filter(gen => !jhipsterExceptList.includes(gen) && (this as any).Generator !== gen), ); } + withJHipsterGenerators(options: WithJHipsterGenerators = {}): this { + const { useDefaultMocks, actualGeneratorsList = [], useMock = useDefaultMocks ? filterBootstrapGenerators : () => false } = options; + const jhipsterExceptList = actualGeneratorsList.map(toJHipsterNamespace); + const mockedGenerators = allGenerators + .filter(useMock) + .filter(gen => !jhipsterExceptList.includes(gen) && (this as any).Generator !== gen); + const actualGenerators = allGenerators.filter(gen => !mockedGenerators.includes(gen)); + const prefix = isDistFolder() ? 'dist/' : ''; + const filePatterns = actualGenerators.map(ns => getGeneratorRelativeFolder(ns)).map(path => `${prefix}${path}/index.{j,t}s`); + return this.withMockedGenerators(mockedGenerators).withLookups({ + packagePaths: [getPackageRoot()], + // @ts-expect-error lookups is not exported + lookups: [`${prefix}generators`, `${prefix}generators/*/generators`], + filePatterns, + customizeNamespace: ns => ns?.replaceAll(':generators:', ':'), + }); + } + withGradleBuildTool(): this { return this.withFiles({ 'build.gradle': ` @@ -372,6 +410,12 @@ plugins { runResult.composedMockedGenerators = composedGeneratorsToCheck.filter(gen => runResult.mockedGenerators[gen]?.mock.callCount() > 0); + runResult.createJHipster = (ns: string, options?: WithJHipsterGenerators) => { + ns = toJHipsterNamespace(ns); + const context = runResult.create(ns) as JHipsterRunContext; + return context.withJHipsterGenerators(options); + }; + return runResult as any; } } @@ -387,7 +431,7 @@ class JHipsterTest extends YeomanTest { run = YeomanGenerator>( GeneratorOrNamespace: string | GetGeneratorConstructor, settings?: RunContextSettings | undefined, - envOptions?: BaseEnvironmentOptions | undefined, + envOptions?: (BaseEnvironmentOptions & { createEnv?: any }) | undefined, ): JHipsterRunContext { return super .run(GeneratorOrNamespace, settings, envOptions) @@ -401,20 +445,37 @@ class JHipsterTest extends YeomanTest { jhipsterGenerator: string, settings?: RunContextSettings | undefined, envOptions?: BaseEnvironmentOptions | undefined, + ): JHipsterRunContext; + runJHipster(jhipsterGenerator: string, options?: WithJHipsterGenerators): JHipsterRunContext; + runJHipster( + jhipsterGenerator: string, + settings?: RunContextSettings | WithJHipsterGenerators | undefined, + envOptions?: BaseEnvironmentOptions | undefined, ): JHipsterRunContext { - return this.run(getGenerator(jhipsterGenerator), settings, envOptions); + if (!isAbsolute(jhipsterGenerator)) { + jhipsterGenerator = toJHipsterNamespace(jhipsterGenerator); + } + const isWithJHipsterGenerators = (opt: any): opt is WithJHipsterGenerators | undefined => + opt === undefined || 'actualGeneratorsList' in opt || 'useMock' in opt || 'useDefaultMocks' in opt || 'useEnvironmentBuilder' in opt; + if (isWithJHipsterGenerators(settings)) { + const createEnv = settings?.useEnvironmentBuilder ? createEnvBuilderEnvironment : undefined; + return this.run(jhipsterGenerator, undefined, { createEnv }).withJHipsterGenerators(settings); + } + return this.run(getGenerator(jhipsterGenerator), settings, envOptions).withJHipsterGenerators(); } runCli(command: string | string[]): JHipsterRunContext { // Use a dummy generator which will not be used to match yeoman-test requirement. - return this.run(this.createDummyGenerator(), { namespace: 'non-used-dummy:generator' }).withEnvironmentRun(async function (this, env) { - // Customize program to throw an error instead of exiting the process on cli parse error. - const program = createProgram().exitOverride(); - await buildJHipster({ program, env: env as any, silent: true }); - await program.parseAsync(['jhipster', 'jhipster', ...(Array.isArray(command) ? command : command.split(' '))]); - // Put the rootGenerator in context to be used in result assertions. - this.generator = env.rootGenerator(); - }); + return this.run(this.createDummyGenerator(), { namespace: 'non-used-dummy:generator' }) + .withJHipsterGenerators({ useEnvironmentBuilder: true }) + .withEnvironmentRun(async function (this, env) { + // Customize program to throw an error instead of exiting the process on cli parse error. + const program = createProgram().exitOverride(); + await buildJHipster({ program, env: env as any, silent: true }); + await program.parseAsync(['jhipster', 'jhipster', ...(Array.isArray(command) ? command : command.split(' '))]); + // Put the rootGenerator in context to be used in result assertions. + this.generator = env.rootGenerator(); + }); } /** @@ -425,7 +486,8 @@ class JHipsterTest extends YeomanTest { settings?: RunContextSettings | undefined, envOptions?: BaseEnvironmentOptions | undefined, ): JHipsterRunContext { - return runResult.create(getGenerator(jhipsterGenerator), settings, envOptions) as JHipsterRunContext; + const context = runResult.create(getGenerator(jhipsterGenerator), settings, envOptions) as JHipsterRunContext; + return context.withJHipsterGenerators(); } runJDL(jdl: string, settings?: RunContextSettings | undefined, envOptions?: BaseEnvironmentOptions | undefined): JHipsterRunContext { @@ -461,7 +523,7 @@ class JHipsterTest extends YeomanTest { return {}; } } - return this.run(blueprintNS).withGenerators([[BlueprintedGenerator, { namespace: blueprintNS }]]); + return this.runJHipster(blueprintNS).withGenerators([[BlueprintedGenerator, { namespace: blueprintNS }]]); } // @ts-expect-error testing types should be improved @@ -503,7 +565,6 @@ export function createTestHelpers(options: any = {}) { helper.settings = { ...DEFAULT_TEST_SETTINGS, ...options.settings }; helper.environmentOptions = { ...DEFAULT_TEST_ENV_OPTIONS, ...environmentOptions, sharedOptions }; helper.generatorOptions = { ...DEFAULT_TEST_OPTIONS, ...options.generatorOptions }; - helper.createEnv = (...args) => EnvironmentBuilder.createEnv(...args) as any; // @ts-expect-error testing types should be improved helper.getRunContextType = () => JHipsterRunContext; return helper; diff --git a/test/needle-api/needle-client-angular-generator.spec.ts b/test/needle-api/needle-client-angular-generator.spec.ts index 932e45973cb7..2a1769bc5d79 100644 --- a/test/needle-api/needle-client-angular-generator.spec.ts +++ b/test/needle-api/needle-client-angular-generator.spec.ts @@ -95,8 +95,8 @@ describe('needle API Angular angular generator : JHipster with blueprint', () => ); }); it('should bail on any file change adding same needles again', async () => { - await runResult - .create('jhipster:angular') + await helpers + .runJHipsterInApplication('jhipster:angular') .withGenerators([[mockAngularBlueprintSubGen, { namespace: 'jhipster-myblueprint2:angular' }]]) .withOptions({ blueprint: ['myblueprint2'], diff --git a/test/needle-api/needle-client-react-generator.spec.ts b/test/needle-api/needle-client-react-generator.spec.ts index 059e0477dd1a..2720bfb88b6a 100644 --- a/test/needle-api/needle-client-react-generator.spec.ts +++ b/test/needle-api/needle-client-react-generator.spec.ts @@ -35,10 +35,8 @@ const mockReactBlueprintSubGen: any = class extends ReactGenerator { }; describe('needle API React: JHipster client generator with blueprint', () => { - let result; - before(async () => { - result = await helpers + await helpers .runJHipster('react') .withOptions({ build: 'maven', @@ -69,7 +67,7 @@ describe('needle API React: JHipster client generator with blueprint', () => { }); it('Assert entity is added to menu', () => { - result.assertFileContent( + runResult.assertFileContent( `${CLIENT_MAIN_SRC_DIR}app/entities/menu.tsx`, '\n Router Name\n ', ); diff --git a/test/support/tests.js b/test/support/tests.js index f674b14bb6ac..f00f0a147766 100644 --- a/test/support/tests.js +++ b/test/support/tests.js @@ -34,11 +34,9 @@ export const getCommandHelpOutput = async command => { }; export const testOptions = data => { - const { generatorPath, customOptions, contextBuilder = () => helpers.create(generatorPath) } = data; + const { generatorPath, customOptions } = data; before(async () => { - await contextBuilder() - .withOptions({ ...customOptions }) - .run(); + await helpers.runJHipster(generatorPath).withOptions({ ...customOptions }); }); it('should write options to .yo-rc.json', () => { @@ -50,22 +48,20 @@ const skipWritingPriorities = ['writing', 'writingEntities', 'postWriting', 'pos export const basicTests = data => { const { - generatorPath, + generatorNamespace, + generatorPath = generatorNamespace, customPrompts, requiredConfig, defaultConfig, getTemplateData = generator => generator.sharedData.getApplication(), - contextBuilder = () => helpers.create(generatorPath), } = data; describe('with default options', () => { before(async () => { - await contextBuilder() - .withOptions({ - skipPrompts: true, - configure: true, - skipPriorities: skipWritingPriorities, - }) - .run(); + await helpers.runJHipster(generatorPath).withOptions({ + skipPrompts: true, + configure: true, + skipPriorities: skipWritingPriorities, + }); }); it('should write default config to .yo-rc.json', () => { runResult.assertJsonFileContent('.yo-rc.json', { [GENERATOR_JHIPSTER]: requiredConfig }); @@ -76,7 +72,7 @@ export const basicTests = data => { }); describe('with defaults option', () => { before(async () => { - await contextBuilder().withOptions({ defaults: true, skipPriorities: skipWritingPriorities }).run(); + await helpers.runJHipster(generatorPath).withOptions({ defaults: true, skipPriorities: skipWritingPriorities }); }); it('should write default config to .yo-rc.json', () => { runResult.assertJsonFileContent('.yo-rc.json', { [GENERATOR_JHIPSTER]: requiredConfig }); @@ -88,7 +84,10 @@ export const basicTests = data => { describe('with custom prompt values', () => { describe('and default options', () => { before(async () => { - await contextBuilder().withOptions({ configure: true, skipPriorities: skipWritingPriorities }).withAnswers(customPrompts).run(); + await helpers + .runJHipster(generatorPath) + .withOptions({ configure: true, skipPriorities: skipWritingPriorities }) + .withAnswers(customPrompts); }); it('should show prompts and write prompt values to .yo-rc.json', () => { runResult.assertJsonFileContent('.yo-rc.json', { [GENERATOR_JHIPSTER]: customPrompts }); @@ -99,7 +98,10 @@ export const basicTests = data => { }); describe('and defaults option', () => { before(async () => { - await contextBuilder().withOptions({ defaults: true, skipPriorities: skipWritingPriorities }).withAnswers(customPrompts).run(); + await helpers + .runJHipster(generatorPath) + .withOptions({ defaults: true, skipPriorities: skipWritingPriorities }) + .withAnswers(customPrompts); }); it('should not show prompts and write default config to .yo-rc.json', () => { runResult.assertJsonFileContent('.yo-rc.json', { [GENERATOR_JHIPSTER]: requiredConfig }); @@ -110,7 +112,10 @@ export const basicTests = data => { }); describe('and skipPrompts option', () => { before(async () => { - await contextBuilder().withOptions({ skipPrompts: true, skipPriorities: skipWritingPriorities }).withAnswers(customPrompts).run(); + await helpers + .runJHipster(generatorPath) + .withOptions({ skipPrompts: true, skipPriorities: skipWritingPriorities }) + .withAnswers(customPrompts); }); it('should not show prompts and write required config to .yo-rc.json', () => { runResult.assertJsonFileContent('.yo-rc.json', { [GENERATOR_JHIPSTER]: requiredConfig }); @@ -122,11 +127,11 @@ export const basicTests = data => { describe('and existing config', () => { const existing = { baseName: 'existing' }; before(async () => { - await contextBuilder() + await helpers + .runJHipster(generatorPath) .withJHipsterConfig(existing) .withOptions({ skipPriorities: skipWritingPriorities }) - .withAnswers(customPrompts) - .run(); + .withAnswers(customPrompts); }); it('should not show prompts and write required config to .yo-rc.json', () => { runResult.assertJsonFileContent('.yo-rc.json', { [GENERATOR_JHIPSTER]: { ...requiredConfig, ...existing } }); @@ -137,14 +142,14 @@ export const basicTests = data => { }); describe('and askAnswered option on an existing project', () => { before(async () => { - await contextBuilder() + await helpers + .runJHipster(generatorPath) .withJHipsterConfig({ baseName: 'existing' }) .withOptions({ askAnswered: true, skipPriorities: ['writing', 'writingEntities', 'postWriting', 'postWritingEntities'], }) - .withAnswers(customPrompts) - .run(); + .withAnswers(customPrompts); }); it('should show prompts and write prompt values to .yo-rc.json', () => { runResult.assertJsonFileContent('.yo-rc.json', { [GENERATOR_JHIPSTER]: customPrompts }); @@ -156,14 +161,14 @@ export const basicTests = data => { describe('and add option on an existing project', () => { const existingConfig = { baseName: 'existing' }; before(async () => { - await contextBuilder() + await helpers + .runJHipster(generatorPath) .withJHipsterConfig(existingConfig) .withOptions({ add: true, skipPriorities: ['writing', 'writingEntities', 'postWriting', 'postWritingEntities'], }) - .withAnswers(customPrompts) - .run(); + .withAnswers(customPrompts); }); it('should show prompts and write prompt values to .yo-rc.json', () => { runResult.assertJsonFileContent('.yo-rc.json', { [GENERATOR_JHIPSTER]: { ...customPrompts, ...existingConfig } }); @@ -227,10 +232,9 @@ export const testBlueprintSupport = (generatorName, options = {}) => { return { prioritiesSpy, prioritiesCount, prioritiesTasks }; }; describe('with blueprint', () => { - let result; let spy; before(async () => { - result = await helpers + await helpers .runJHipster(generatorName) .withMockedJHipsterGenerators({ filter: () => true }) .withMockedGenerators([`jhipster-foo:${generatorName}`]) @@ -241,14 +245,13 @@ export const testBlueprintSupport = (generatorName, options = {}) => { }); }); it(`should compose with jhipster-foo:${generatorName} blueprint once`, () => { - expect(result.getGeneratorComposeCount(`jhipster-foo:${generatorName}`)).toBe(1); + expect(runResult.getGeneratorComposeCount(`jhipster-foo:${generatorName}`)).toBe(1); }); it('should not call any priority', () => { expect(spy.prioritiesSpy.callCount).toBe(0); }); }); describe('with sbs blueprint', () => { - let result; let spy; before(async function () { if (skipSbsBlueprint) { @@ -296,10 +299,10 @@ export const testBlueprintSupport = (generatorName, options = {}) => { configurable: true, }); - result = await context; + await context; }); it(`should compose with jhipster-foo:${generatorName} blueprint once`, () => { - expect(result.assertGeneratorComposedOnce(`jhipster-foo-sbs:${generatorName}`)); + expect(runResult.assertGeneratorComposedOnce(`jhipster-foo-sbs:${generatorName}`)); }); it('should call every priority', () => { expect(spy.prioritiesSpy.callCount).toBe(spy.prioritiesCount);