diff --git a/generators/app/composing.spec.ts b/generators/app/composing.spec.ts index 4bb868b79335..058a6e68bd47 100644 --- a/generators/app/composing.spec.ts +++ b/generators/app/composing.spec.ts @@ -1,6 +1,6 @@ import { before, describe, it } from 'esmocha'; -import { defaultHelpers as helpers } from '../../lib/testing/index.js'; +import { defaultHelpers as helpers, runResult } from '../../lib/testing/index.js'; import { GENERATOR_APP } from '../generator-list.js'; const allMockedComposedGenerators = [ @@ -18,9 +18,8 @@ const allMockedComposedGenerators = [ describe('generator - app - composing', () => { describe('when mocking all generators', () => { describe('with default options', () => { - let runResult; before(async () => { - runResult = await helpers.runJHipster(GENERATOR_APP).withJHipsterConfig().withMockedGenerators(allMockedComposedGenerators); + await helpers.runJHipster(GENERATOR_APP).withJHipsterConfig().withMockedGenerators(allMockedComposedGenerators); }); it('should compose with bootstrap generator', () => { @@ -50,9 +49,8 @@ describe('generator - app - composing', () => { }); describe('with --skip-client', () => { - let runResult; before(async () => { - runResult = await helpers + await helpers .runJHipster(GENERATOR_APP) .withJHipsterConfig({ skipClient: true, @@ -87,9 +85,8 @@ describe('generator - app - composing', () => { }); describe('with --skip-server', () => { - let runResult; before(async () => { - runResult = await helpers + await helpers .runJHipster(GENERATOR_APP) .withJHipsterConfig({ skipServer: true, diff --git a/generators/app/generator.spec.ts b/generators/app/generator.spec.ts index d0288ce07ee0..083edd107d44 100644 --- a/generators/app/generator.spec.ts +++ b/generators/app/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'; @@ -29,7 +29,6 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const generator = basename(__dirname); -const generatorPath = join(__dirname, 'index.js'); describe(`generator - ${generator}`, () => { it('generator-list constant matches folder name', async () => { @@ -44,9 +43,8 @@ describe(`generator - ${generator}`, () => { describe('blueprint support', () => testBlueprintSupport(generator)); describe('with', () => { describe('default config', () => { - let runResult; before(async () => { - runResult = await helpers.run(generatorPath).withJHipsterConfig().withSkipWritingPriorities().withMockedSource(); + await helpers.runJHipster(generator).withJHipsterConfig().withSkipWritingPriorities().withMockedSource(); }); it('should match snapshot', () => { @@ -61,10 +59,9 @@ describe(`generator - ${generator}`, () => { }); describe('gateway', () => { - let runResult; before(async () => { - runResult = await helpers - .run(generatorPath) + await helpers + .runJHipster(generator) .withJHipsterConfig({ applicationType: 'gateway', }) @@ -84,10 +81,9 @@ describe(`generator - ${generator}`, () => { }); describe('microservice', () => { - let runResult; before(async () => { - runResult = await helpers - .run(generatorPath) + await helpers + .runJHipster(generator) .withJHipsterConfig({ applicationType: 'microservice', }) @@ -108,7 +104,7 @@ describe(`generator - ${generator}`, () => { describe('with application', () => { before(async () => { await helpers - .run(generatorPath) + .runJHipster(generator) .withJHipsterConfig({ jdlStore: 'app.jdl', skipServer: true, @@ -125,7 +121,7 @@ describe(`generator - ${generator}`, () => { describe('with application and entities', () => { before(async () => { await helpers - .run(generatorPath) + .runJHipster(generator) .withJHipsterConfig( { jdlStore: 'app.jdl', @@ -146,7 +142,7 @@ describe(`generator - ${generator}`, () => { describe('with incremental changelog application and entities', () => { before(async () => { await helpers - .run(generatorPath) + .runJHipster(generator) .withJHipsterConfig( { jdlStore: 'app.jdl', @@ -168,7 +164,7 @@ describe(`generator - ${generator}`, () => { describe('questions', () => { describe('without answers', () => { before(async () => { - await helpers.run(generatorPath).withSkipWritingPriorities(); + await helpers.runJHipster(generator).withSkipWritingPriorities(); }); it('should match order', () => { @@ -202,7 +198,7 @@ describe(`generator - ${generator}`, () => { describe('with gateway, gradle and no cacheProvider', () => { before(async () => { await helpers - .run(generatorPath) + .runJHipster(generator) .withAnswers({ applicationType: 'gateway', buildTool: 'gradle', cacheProvider: 'no' }) .withSkipWritingPriorities(); }); @@ -241,7 +237,7 @@ describe(`generator - ${generator}`, () => { describe('with microservice', () => { before(async () => { await helpers - .run(generatorPath) + .runJHipster(generator) .withAnswers({ applicationType: 'microservice', databaseType: 'mongodb' }) .withSkipWritingPriorities(); }); diff --git a/generators/base-application/types.d.ts b/generators/base-application/types.d.ts index ca0d5c8b02c0..42d01d54d498 100644 --- a/generators/base-application/types.d.ts +++ b/generators/base-application/types.d.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type { ExportApplicationPropertiesFromCommand } from '../../lib/command/types.js'; import type CoreGenerator from '../base-core/generator.ts'; import type { ClientApplication } from '../client/types.js'; import type { I18nApplication } from '../languages/types.js'; @@ -143,6 +145,7 @@ export type CommonClientServerApplication = BaseApplication & AuthenticationProperties & SpringBootApplication & ClientApplication & + ExportApplicationPropertiesFromCommand & ApplicationProperties & { clientRootDir: string; clientSrcDir: string; diff --git a/generators/base/blueprints.spec.ts b/generators/base/blueprints.spec.ts index 664f1b115027..429245ff0497 100644 --- a/generators/base/blueprints.spec.ts +++ b/generators/base/blueprints.spec.ts @@ -1,9 +1,8 @@ import type { Mock } from 'node:test'; import { mock } from 'node:test'; import { before, describe, expect, it } from 'esmocha'; -import type { RunResult } from 'yeoman-test'; -import { defaultHelpers as helpers } from '../../lib/testing/index.js'; +import { defaultHelpers as helpers, runResult } from '../../lib/testing/index.js'; import { packageJson } from '../../lib/index.js'; import BaseGenerator from './index.js'; @@ -11,9 +10,8 @@ const jhipsterVersion = packageJson.version; describe('generator - base - with blueprint', () => { describe('generate application with a version-compatible blueprint', () => { - let runResult: RunResult; before(async () => { - runResult = await helpers + await helpers .runTestBlueprintGenerator() .withFakeTestBlueprint('generator-jhipster-myblueprint', { packageJson: { @@ -83,9 +81,8 @@ describe('generator - base - with blueprint', () => { }); describe('generate application with a peer version-compatible blueprint', () => { - let runResult: RunResult; before(async () => { - runResult = await helpers + await helpers .runTestBlueprintGenerator() .withFakeTestBlueprint('generator-jhipster-myblueprint', { packageJson: { @@ -129,9 +126,8 @@ describe('generator - base - with blueprint', () => { }); describe('generate application with a engines compatible blueprint', () => { - let runResult: RunResult; before(async () => { - runResult = await helpers + await helpers .runTestBlueprintGenerator() .withFakeTestBlueprint('generator-jhipster-myblueprint', { packageJson: { @@ -189,9 +185,8 @@ describe('generator - base - with blueprint', () => { describe('generator - base - with scoped blueprint', () => { describe('generate monolith application with scoped blueprint', () => { - let runResult: RunResult; before(async () => { - runResult = await helpers + await helpers .runTestBlueprintGenerator() .withFakeTestBlueprint('@jhipster/generator-jhipster-scoped-blueprint') .withMockedGenerators(['@jhipster/jhipster-scoped-blueprint:test-blueprint']) @@ -215,9 +210,8 @@ describe('generator - base - with scoped blueprint', () => { describe('generator - base - with blueprints disabled', () => { describe('should not compose with blueprint', () => { - let runResult: RunResult; before(async () => { - runResult = await helpers + await helpers .runTestBlueprintGenerator() .withFakeTestBlueprint('@jhipster/generator-jhipster-scoped-blueprint') .withMockedGenerators(['@jhipster/jhipster-scoped-blueprint:test-blueprint']) @@ -259,10 +253,8 @@ describe('generator - base - with blueprint with constructor error', () => { describe('generator - base - with multiple blueprints', () => { describe('generate monolith application with scoped blueprint', () => { - let runResult: RunResult; - before(async () => { - runResult = await helpers + await helpers .runTestBlueprintGenerator() .withMockedGenerators(['jhipster-blueprint1:test-blueprint', 'jhipster-blueprint2:test-blueprint']) .withJHipsterConfig() @@ -298,13 +290,8 @@ describe('generator - base - local blueprint', () => { `; describe('generates application', () => { - let runResult; before(async () => { - runResult = await helpers - .run(BLUEPRINT_NS) - .withFiles({ '.blueprint/app/index.mjs': BLUEPRINT_CONTENTS }) - .commitFiles() - .withJHipsterConfig(); + await helpers.run(BLUEPRINT_NS).withFiles({ '.blueprint/app/index.mjs': BLUEPRINT_CONTENTS }).commitFiles().withJHipsterConfig(); }); it('creates expected default files', () => { diff --git a/generators/bootstrap-application-base/generator.spec.ts b/generators/bootstrap-application-base/generator.spec.ts index 9500d1898344..ab5b4e95f9c1 100644 --- a/generators/bootstrap-application-base/generator.spec.ts +++ b/generators/bootstrap-application-base/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, beforeEach, describe, expect, it } from 'esmocha'; import { snakeCase } from 'lodash-es'; @@ -29,7 +29,6 @@ import Generator from './index.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); -const generatorPath = join(__dirname, 'index.ts'); const generator = basename(__dirname); describe(`generator - ${generator}`, () => { @@ -43,9 +42,8 @@ describe(`generator - ${generator}`, () => { describe('with', () => { describe('default config', () => { - let runResult; before(async () => { - runResult = await helpers.run(generatorPath).withJHipsterConfig(); + await helpers.runJHipster(generator).withJHipsterConfig(); }); it('should succeed', () => { @@ -71,7 +69,7 @@ describe(`generator - ${generator}`, () => { describe('when there is no configured lastLiquibaseTimestamp', () => { let firstChangelogDate; before(async () => { - await helpers.run(generatorPath).withJHipsterConfig(); + await helpers.runJHipster(generator).withJHipsterConfig(); firstChangelogDate = runResult.generator.dateFormatForLiquibase(); }); it('should return a valid changelog date', () => { @@ -85,7 +83,7 @@ describe(`generator - ${generator}`, () => { let firstChangelogDate; before(async () => { const lastLiquibaseTimestamp = new Date(2000, 1, 1); - await helpers.run(generatorPath).withJHipsterConfig({ lastLiquibaseTimestamp: lastLiquibaseTimestamp.getTime() }); + await helpers.runJHipster(generator).withJHipsterConfig({ lastLiquibaseTimestamp: lastLiquibaseTimestamp.getTime() }); firstChangelogDate = runResult.generator.dateFormatForLiquibase(); }); it('should return a valid changelog date', () => { @@ -104,7 +102,7 @@ describe(`generator - ${generator}`, () => { beforeEach(async () => { const lastLiquibaseTimestamp = new Date(Date.parse('2030-01-01')); await helpers - .run(generatorPath) + .runJHipster(generator) .withJHipsterConfig({ lastLiquibaseTimestamp: lastLiquibaseTimestamp.getTime(), creationTimestamp: undefined }) .withOptions({ reproducible: false }); firstChangelogDate = runResult.generator.dateFormatForLiquibase(); @@ -128,7 +126,7 @@ describe(`generator - ${generator}`, () => { let firstChangelogDate; let secondChangelogDate; before(async () => { - await helpers.run(generatorPath).withJHipsterConfig(); + await helpers.runJHipster(generator).withJHipsterConfig(); firstChangelogDate = runResult.generator.dateFormatForLiquibase(false); secondChangelogDate = runResult.generator.dateFormatForLiquibase(false); }); @@ -148,7 +146,7 @@ describe(`generator - ${generator}`, () => { let secondChangelogDate; before(async () => { - await helpers.run(generatorPath).withJHipsterConfig().withOptions({ creationTimestamp: '2000-01-01' }); + await helpers.runJHipster(generator).withJHipsterConfig().withOptions({ creationTimestamp: '2000-01-01' }); firstChangelogDate = runResult.generator.dateFormatForLiquibase(); secondChangelogDate = runResult.generator.dateFormatForLiquibase(); @@ -169,7 +167,7 @@ describe(`generator - ${generator}`, () => { }); describe('with a future creationTimestamp option', () => { it('should throw', async () => { - await expect(helpers.run(generatorPath).withJHipsterConfig().withOptions({ creationTimestamp: '2030-01-01' })).rejects.toThrow( + await expect(helpers.runJHipster(generator).withJHipsterConfig().withOptions({ creationTimestamp: '2030-01-01' })).rejects.toThrow( /^Creation timestamp should not be in the future: 2030-01-01\.$/, ); }); diff --git a/generators/bootstrap-application-client/generator.spec.ts b/generators/bootstrap-application-client/generator.spec.ts index 14cbd082d717..76d04df070be 100644 --- a/generators/bootstrap-application-client/generator.spec.ts +++ b/generators/bootstrap-application-client/generator.spec.ts @@ -16,19 +16,18 @@ * 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'; -import { defaultHelpers as helpers } from '../../lib/testing/index.js'; +import { defaultHelpers as helpers, runResult } from '../../lib/testing/index.js'; import { shouldSupportFeatures } from '../../test/support/tests.js'; import Generator from './index.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); -const generatorPath = join(__dirname, 'index.ts'); const generator = basename(__dirname); describe(`generator - ${generator}`, () => { @@ -42,9 +41,8 @@ describe(`generator - ${generator}`, () => { describe('with', () => { describe('default config', () => { - let runResult; before(async () => { - runResult = await helpers.run(generatorPath).withJHipsterConfig(); + await helpers.runJHipster(generator).withJHipsterConfig(); }); it('should succeed', () => { diff --git a/generators/bootstrap-application-server/generator.spec.ts b/generators/bootstrap-application-server/generator.spec.ts index 14cbd082d717..76d04df070be 100644 --- a/generators/bootstrap-application-server/generator.spec.ts +++ b/generators/bootstrap-application-server/generator.spec.ts @@ -16,19 +16,18 @@ * 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'; -import { defaultHelpers as helpers } from '../../lib/testing/index.js'; +import { defaultHelpers as helpers, runResult } from '../../lib/testing/index.js'; import { shouldSupportFeatures } from '../../test/support/tests.js'; import Generator from './index.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); -const generatorPath = join(__dirname, 'index.ts'); const generator = basename(__dirname); describe(`generator - ${generator}`, () => { @@ -42,9 +41,8 @@ describe(`generator - ${generator}`, () => { describe('with', () => { describe('default config', () => { - let runResult; before(async () => { - runResult = await helpers.run(generatorPath).withJHipsterConfig(); + await helpers.runJHipster(generator).withJHipsterConfig(); }); it('should succeed', () => { diff --git a/generators/bootstrap-application/generator.spec.ts b/generators/bootstrap-application/generator.spec.ts index 0b8a26a5144e..3df9216234cb 100644 --- a/generators/bootstrap-application/generator.spec.ts +++ b/generators/bootstrap-application/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'; @@ -33,7 +33,6 @@ const { const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); -const generatorPath = join(__dirname, 'index.ts'); const generator = basename(__dirname); const expectedField = () => ({ @@ -87,7 +86,7 @@ describe(`generator - ${generator}`, () => { describe('with', () => { describe('default config', () => { before(async () => { - await helpers.run(generatorPath).withJHipsterConfig({}, [ + await helpers.runJHipster(generator).withJHipsterConfig({}, [ { name: 'EntityA', changelogDate: '20220129025419', @@ -1357,9 +1356,8 @@ describe(`generator - ${generator}`, () => { }); describe('skipUserManagement', () => { - let runResult; before(async () => { - runResult = await helpers.run(generatorPath).withJHipsterConfig( + await helpers.runJHipster(generator).withJHipsterConfig( { skipUserManagement: true, }, diff --git a/generators/ci-cd/ci-cd.spec.ts b/generators/ci-cd/ci-cd.spec.ts index 8ab91771cabe..6a4bf2390bde 100644 --- a/generators/ci-cd/ci-cd.spec.ts +++ b/generators/ci-cd/ci-cd.spec.ts @@ -1,6 +1,6 @@ import { before, describe, expect, it } from 'esmocha'; import { GENERATOR_CI_CD } from '../generator-list.js'; -import { defaultHelpers as helpers } from '../../lib/testing/index.js'; +import { defaultHelpers as helpers, runResult } from '../../lib/testing/index.js'; const expectedFiles = { travis: ['.travis.yml'], @@ -31,17 +31,15 @@ describe('generator - CI-CD', () => { //-------------------------------------------------- describe('Jenkins tests', () => { describe('Jenkins: Maven Angular NPM', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(mavenSample) .withAnswers({ ciCd: ['jenkins'], insideDocker: false, ciCdIntegrations: [], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -57,17 +55,15 @@ describe('generator - CI-CD', () => { }); }); describe('Jenkins: Gradle Angular NPM', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(gradleSample) .withAnswers({ ciCd: ['jenkins'], insideDocker: false, ciCdIntegrations: [], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -83,10 +79,9 @@ describe('generator - CI-CD', () => { }); }); describe('Jenkins: Maven Angular NPM with full options', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(mavenSample) .withFiles({ 'pom.xml': pomFile }) .withAnswers({ @@ -98,8 +93,7 @@ describe('generator - CI-CD', () => { artifactoryReleasesId: 'releases', artifactoryReleasesUrl: 'http://artifactory:8081/artifactory/libs-release', sonarName: 'sonarName', - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -118,10 +112,9 @@ describe('generator - CI-CD', () => { }); }); describe('Jenkins: Maven Angular NPM inside Docker', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(mavenSample) .withFiles({ 'pom.xml': pomFile }) .withAnswers({ @@ -133,8 +126,7 @@ describe('generator - CI-CD', () => { artifactoryReleasesId: 'releases', artifactoryReleasesUrl: 'http://artifactory:8081/artifactory/libs-release', sonarName: 'sonarName', - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -157,17 +149,15 @@ describe('generator - CI-CD', () => { //-------------------------------------------------- describe('GitLab CI tests', () => { describe('GitLab CI: Maven Angular NPM', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(mavenSample) .withAnswers({ ciCd: ['gitlab'], insideDocker: false, ciCdIntegrations: [], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -183,16 +173,14 @@ describe('generator - CI-CD', () => { }); }); describe('GitLab CI: Gradle Angular NPM', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(gradleSample) .withAnswers({ ciCd: ['gitlab'], ciCdIntegrations: [], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -208,17 +196,15 @@ describe('generator - CI-CD', () => { }); }); describe('GitLab CI: npm skip server', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(skipServerSample) .withAnswers({ ciCd: ['gitlab'], insideDocker: true, ciCdIntegrations: [], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -231,10 +217,9 @@ describe('generator - CI-CD', () => { }); }); describe('GitLab CI: Maven Angular NPM with full options', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(mavenSample) .withFiles({ 'pom.xml': pomFile }) .withAnswers({ @@ -246,8 +231,7 @@ describe('generator - CI-CD', () => { artifactoryReleasesId: 'releases', artifactoryReleasesUrl: 'http://artifactory:8081/artifactory/libs-release', sonarUrl: 'http://localhost:9000', - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -266,10 +250,9 @@ describe('generator - CI-CD', () => { }); }); describe('GitLab CI: Maven Angular NPM inside Docker', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(mavenSample) .withFiles({ 'pom.xml': pomFile }) .withAnswers({ @@ -281,8 +264,7 @@ describe('generator - CI-CD', () => { artifactoryReleasesId: 'releases', artifactoryReleasesUrl: 'http://artifactory:8081/artifactory/libs-release', sonarUrl: 'http://localhost:9000', - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -301,16 +283,10 @@ describe('generator - CI-CD', () => { }); }); describe('GitLab CI: Maven Angular Yarn inside Docker Autoconfigure', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) - .withJHipsterConfig(mavenSample) - .withArguments(['gitlab']) - .withAnswers({ - insideDocker: true, - }) - .run(); + await helpers.runJHipster(GENERATOR_CI_CD).withJHipsterConfig(mavenSample).withArguments(['gitlab']).withAnswers({ + insideDocker: true, + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -332,16 +308,14 @@ describe('generator - CI-CD', () => { //-------------------------------------------------- describe('Travis CI tests', () => { describe('Travis CI: Maven Angular NPM', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(mavenSample) .withAnswers({ ciCd: ['travis'], ciCdIntegrations: [], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -355,16 +329,14 @@ describe('generator - CI-CD', () => { }); }); describe('Travis CI: Gradle Angular NPM', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(gradleSample) .withAnswers({ ciCd: ['travis'], ciCdIntegrations: [], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -382,10 +354,9 @@ describe('generator - CI-CD', () => { }); }); describe('Travis CI: Maven Angular NPM with full options', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(mavenSample) .withFiles({ 'pom.xml': pomFile }) .withAnswers({ @@ -396,8 +367,7 @@ describe('generator - CI-CD', () => { artifactoryReleasesId: 'releases', artifactoryReleasesUrl: 'http://artifactory:8081/artifactory/libs-release', sonarUrl: 'http://localhost:9000', - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -425,16 +395,14 @@ describe('generator - CI-CD', () => { //-------------------------------------------------- describe('Azure Pipelines tests', () => { describe('Azure Pipelines: Maven Angular NPM', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(mavenSample) .withAnswers({ ciCd: ['azure'], ciCdIntegrations: ['cypressDashboard'], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -450,16 +418,14 @@ describe('generator - CI-CD', () => { }); }); describe('Azure Pipelines: Gradle Angular NPM', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(gradleSample) .withAnswers({ ciCd: ['azure'], ciCdIntegrations: [], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -473,16 +439,14 @@ describe('generator - CI-CD', () => { }); }); describe('Azure Pipelines: Maven Angular NPM with Snyk', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(mavenSample) .withAnswers({ ciCd: ['azure'], ciCdIntegrations: ['snyk'], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -495,16 +459,14 @@ describe('generator - CI-CD', () => { }); }); describe('Azure Pipelines: Gradle Angular NPM with Snyk', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(gradleSample) .withAnswers({ ciCd: ['azure'], ciCdIntegrations: ['snyk'], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -517,9 +479,8 @@ describe('generator - CI-CD', () => { }); }); describe('Azure Pipelines: autoconfigure', () => { - let runResult; before(async () => { - runResult = await helpers.createJHipster(GENERATOR_CI_CD).withJHipsterConfig(mavenSample).withArguments(['azure']).run(); + await helpers.runJHipster(GENERATOR_CI_CD).withJHipsterConfig(mavenSample).withArguments(['azure']); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -535,16 +496,14 @@ describe('generator - CI-CD', () => { //-------------------------------------------------- describe('GitHub Actions tests', () => { describe('GitHub Actions: Maven Angular NPM', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(mavenSample) .withAnswers({ ciCd: ['github'], ciCdIntegrations: [], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -554,16 +513,14 @@ describe('generator - CI-CD', () => { }); }); describe('GitHub Actions: Gradle Angular NPM', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(gradleSample) .withAnswers({ ciCd: ['github'], ciCdIntegrations: [], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -573,10 +530,9 @@ describe('generator - CI-CD', () => { }); }); describe('GitHub Actions: Maven Angular NPM with full options', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(mavenSample) .withFiles({ 'pom.xml': pomFile }) .withAnswers({ @@ -588,8 +544,7 @@ describe('generator - CI-CD', () => { artifactoryReleasesId: 'releases', artifactoryReleasesUrl: 'http://artifactory:8081/artifactory/libs-release', sonarUrl: 'http://sonar.com:9000', - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -614,18 +569,16 @@ describe('generator - CI-CD', () => { }); }); describe('GitHub Actions: Gradle Angular NPM with full options', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(gradleSample) .withAnswers({ ciCd: ['github'], ciCdIntegrations: ['sonar', 'publishDocker', 'heroku', 'snyk'], dockerImage: 'jhipster-publish-docker', sonarUrl: 'http://sonar.com:9000', - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -647,9 +600,8 @@ describe('generator - CI-CD', () => { }); }); describe('GitHub Actions: autoconfigure', () => { - let runResult; before(async () => { - runResult = await helpers.createJHipster(GENERATOR_CI_CD).withJHipsterConfig(mavenSample).withArguments(['github']).run(); + await helpers.runJHipster(GENERATOR_CI_CD).withJHipsterConfig(mavenSample).withArguments(['github']); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -665,16 +617,14 @@ describe('generator - CI-CD', () => { //-------------------------------------------------- describe('Circle CI test', () => { describe('Circle CI: Maven Angular NPM', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(mavenSample) .withAnswers({ ciCd: ['circle'], ciCdIntegrations: ['cypressDashboard'], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -691,16 +641,14 @@ describe('generator - CI-CD', () => { }); }); describe('Circle CI: Gradle Angular NPM', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(gradleSample) .withAnswers({ ciCd: ['circle'], ciCdIntegrations: [], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -717,16 +665,14 @@ describe('generator - CI-CD', () => { }); }); describe('Circle CI: Maven with Snyk', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(mavenSample) .withAnswers({ ciCd: ['circle'], ciCdIntegrations: ['snyk'], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -739,16 +685,14 @@ describe('generator - CI-CD', () => { }); }); describe('Circle CI: Gradle with Snyk', () => { - let runResult; before(async () => { - runResult = await helpers - .createJHipster(GENERATOR_CI_CD) + await helpers + .runJHipster(GENERATOR_CI_CD) .withJHipsterConfig(gradleSample) .withAnswers({ ciCd: ['circle'], ciCdIntegrations: ['snyk'], - }) - .run(); + }); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); diff --git a/generators/client/generator-needles.spec.ts b/generators/client/generator-needles.spec.ts index 6c9e5089c47f..7841de1d2dd5 100644 --- a/generators/client/generator-needles.spec.ts +++ b/generators/client/generator-needles.spec.ts @@ -1,5 +1,5 @@ import { before, describe, it } from 'esmocha'; -import { getGenerator, dryRunHelpers as helpers, result as runResult } from '../../lib/testing/index.js'; +import { dryRunHelpers as helpers, result as runResult } from '../../lib/testing/index.js'; import { CLIENT_WEBPACK_DIR } from '../generator-constants.js'; import { clientFrameworkTypes } from '../../lib/jhipster/index.js'; import ClientGenerator from './index.js'; @@ -23,7 +23,7 @@ const mockBlueprintSubGen: any = class extends ClientGenerator { describe('needle API Webpack: JHipster client generator with blueprint', () => { function generateAppWithClientFramework(clientFramework) { return helpers - .create(getGenerator('client')) + .runJHipster('client') .withOptions({ blueprint: ['myblueprint'], }) @@ -38,8 +38,7 @@ describe('needle API Webpack: JHipster client generator with blueprint', () => { nativeLanguage: 'en', languages: ['en', 'fr'], }) - .withGenerators([[mockBlueprintSubGen, { namespace: 'jhipster-myblueprint:client' }]]) - .run(); + .withGenerators([[mockBlueprintSubGen, { namespace: 'jhipster-myblueprint:client' }]]); } describe('Angular clientFramework', () => { diff --git a/generators/client/generator.spec.ts b/generators/client/generator.spec.ts index 602dd67a7c1c..37e5299af367 100644 --- a/generators/client/generator.spec.ts +++ b/generators/client/generator.spec.ts @@ -21,7 +21,7 @@ import { fileURLToPath } from 'url'; import { snakeCase } from 'lodash-es'; import { before, describe, expect, it } from 'esmocha'; import { checkEnforcements, shouldSupportFeatures, testBlueprintSupport } from '../../test/support/index.js'; -import { defaultHelpers as helpers, result } from '../../lib/testing/index.js'; +import { defaultHelpers as helpers, result, runResult } from '../../lib/testing/index.js'; import { testFrameworkTypes } from '../../lib/jhipster/index.js'; import { GENERATOR_CLIENT } from '../generator-list.js'; import Generator from './index.js'; @@ -46,10 +46,9 @@ describe(`generator - ${generator}`, () => { const mockedComposedGenerators = ['jhipster:common', 'jhipster:languages', 'jhipster:cypress']; describe('with translation disabled', () => { - let runResult; const options = { enableTranslation: false }; before(async () => { - runResult = await helpers + await helpers .run(generatorFile) .withControl({ getWebappTranslation: () => 'translations' }) .withJHipsterConfig(options) @@ -66,10 +65,9 @@ describe(`generator - ${generator}`, () => { }); describe('with translation enabled', () => { - let runResult; const options = { enableTranslation: true }; before(async () => { - runResult = await helpers + await helpers .run(generatorFile) .withControl({ getWebappTranslation: () => 'translations' }) .withJHipsterConfig(options) @@ -86,10 +84,9 @@ describe(`generator - ${generator}`, () => { }); describe('without cypress', () => { - let runResult; const options = { testFrameworks: [] }; before(async () => { - runResult = await helpers + await helpers .run(generatorFile) .withControl({ getWebappTranslation: () => 'translations' }) .withJHipsterConfig(options) @@ -109,10 +106,9 @@ describe(`generator - ${generator}`, () => { }); describe('with cypress', () => { - let runResult; const options = { testFrameworks: [CYPRESS] }; before(async () => { - runResult = await helpers + await helpers .run(generatorFile) .withControl({ getWebappTranslation: () => 'translations' }) .withJHipsterConfig(options) diff --git a/generators/client/needle-client.spec.ts b/generators/client/needle-client.spec.ts index ddb8ac028090..8263dcb58867 100644 --- a/generators/client/needle-client.spec.ts +++ b/generators/client/needle-client.spec.ts @@ -1,7 +1,7 @@ import { before, describe, it } from 'esmocha'; import ClientGenerator from '../../generators/client/index.js'; import { CLIENT_MAIN_SRC_DIR } from '../generator-constants.js'; -import { getGenerator, dryRunHelpers as helpers, result as runResult } from '../../lib/testing/index.js'; +import { dryRunHelpers as helpers, result as runResult } from '../../lib/testing/index.js'; const mockBlueprintSubGen: any = class extends ClientGenerator { constructor(args, opts, features) { @@ -30,7 +30,7 @@ const mockBlueprintSubGen: any = class extends ClientGenerator { describe('needle API Client: JHipster client generator with blueprint', () => { before(async () => { await helpers - .run(getGenerator('client')) + .runJHipster('client') .withJHipsterConfig({ skipServer: true, }) diff --git a/generators/client/prompts.spec.ts b/generators/client/prompts.spec.ts index 1229dea387c3..6e7554335e6a 100644 --- a/generators/client/prompts.spec.ts +++ b/generators/client/prompts.spec.ts @@ -1,5 +1,5 @@ import { before, describe, it } from 'esmocha'; -import { defaultHelpers as helpers } from '../../lib/testing/index.js'; +import { defaultHelpers as helpers, runResult } from '../../lib/testing/index.js'; import { applicationTypes, authenticationTypes, @@ -24,9 +24,8 @@ const mockedComposedGenerators = ['jhipster:common', 'jhipster:server', 'jhipste describe('generator - client - prompts', () => { describe('clientTestFrameworks prompt', () => { describe('with cypress value', () => { - let runResult; before(async () => { - runResult = await helpers + await helpers .runJHipster(GENERATOR_APP) .withControl({ getWebappTranslation: () => 'translations' }) .withAnswers({ diff --git a/generators/cypress/generator.spec.ts b/generators/cypress/generator.spec.ts index 47530673fc4f..222e15093654 100644 --- a/generators/cypress/generator.spec.ts +++ b/generators/cypress/generator.spec.ts @@ -16,12 +16,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import path, { basename, dirname } from 'path'; +import { basename, dirname } from 'path'; import { fileURLToPath } from 'url'; import { before, describe, expect, it } from 'esmocha'; import { snakeCase } from 'lodash-es'; import { clientFrameworkTypes, testFrameworkTypes } from '../../lib/jhipster/index.js'; -import { AuthenticationTypeMatrix, extendMatrix, fromMatrix, defaultHelpers as helpers } from '../../lib/testing/index.js'; +import { AuthenticationTypeMatrix, extendMatrix, fromMatrix, defaultHelpers as helpers, runResult } from '../../lib/testing/index.js'; import { checkEnforcements, shouldSupportFeatures, testBlueprintSupport } from '../../test/support/index.js'; import { GENERATOR_CYPRESS } from '../generator-list.js'; import Generator from './generator.js'; @@ -34,8 +34,6 @@ const __dirname = dirname(__filename); const generator = basename(__dirname); -const generatorPath = path.join(__dirname, 'index.ts'); - const e2eMatrix = extendMatrix( fromMatrix({ ...AuthenticationTypeMatrix, @@ -79,10 +77,8 @@ describe(`generator - ${generator}`, () => { Object.entries(e2eSamples).forEach(([name, sampleConfig]) => { describe(name, () => { - let runResult; - before(async () => { - runResult = await helpers.run(generatorPath).withJHipsterConfig(sampleConfig, entities); + await helpers.runJHipster(generator).withJHipsterConfig(sampleConfig, entities); }); it('should match generated files snapshot', () => { @@ -101,7 +97,7 @@ describe(`generator - ${generator}`, () => { const adminUiRoutingTitle = generateAdminUi ? 'should generate admin routing' : 'should not generate admin routing'; it(adminUiRoutingTitle, () => { const assertion = (...args) => - generateAdminUi ? runResult.assertFileContent(...args) : runResult.assertNoFileContent(...args); + generateAdminUi ? (runResult.assertFileContent as any)(...args) : (runResult.assertNoFileContent as any)(...args); assertion( `${clientRootDir}src/test/javascript/cypress/e2e/administration/administration.cy.ts`, diff --git a/generators/docker-compose/docker-compose.spec.ts b/generators/docker-compose/docker-compose.spec.ts index df8c6d86ad92..0231885f8314 100644 --- a/generators/docker-compose/docker-compose.spec.ts +++ b/generators/docker-compose/docker-compose.spec.ts @@ -17,15 +17,14 @@ const expectedFiles = { describe('generator - Docker Compose', () => { describe('only gateway', () => { - let runResult; const chosenApps = ['01-gateway']; before(async () => { - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) .withAnswers({ deploymentApplicationType: MICROSERVICE, @@ -53,15 +52,14 @@ describe('generator - Docker Compose', () => { }); describe('only one microservice', () => { - let runResult; const chosenApps = ['02-mysql']; before(async () => { - runResult = await helpers + await helpers .generateDeploymentWorkspaces() .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) .withAnswers({ deploymentApplicationType: MICROSERVICE, @@ -89,15 +87,14 @@ describe('generator - Docker Compose', () => { }); describe('one microservice and a directory path without a trailing slash', () => { - let runResult; const chosenApps = ['02-mysql']; before(async () => { - runResult = await helpers + await helpers .generateDeploymentWorkspaces() .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) .withAnswers({ deploymentApplicationType: MICROSERVICE, @@ -155,15 +152,14 @@ describe('generator - Docker Compose', () => { }); describe('gateway and one microservice', () => { - let runResult; const chosenApps = ['01-gateway', '02-mysql']; before(async () => { - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) .withAnswers({ deploymentApplicationType: MICROSERVICE, @@ -193,15 +189,14 @@ describe('generator - Docker Compose', () => { }); describe('gateway and one microservice, with curator', () => { - let runResult; const chosenApps = ['01-gateway', '02-mysql']; before(async () => { - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) .withAnswers({ deploymentApplicationType: MICROSERVICE, @@ -231,15 +226,14 @@ describe('generator - Docker Compose', () => { }); describe('gateway and one microservice, with prometheus', () => { - let runResult; const chosenApps = ['01-gateway', '02-mysql']; before(async () => { - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) .withAnswers({ deploymentApplicationType: MICROSERVICE, @@ -270,15 +264,14 @@ describe('generator - Docker Compose', () => { }); describe('gateway and multi microservices', () => { - let runResult; const chosenApps = ['01-gateway', '02-mysql', '03-psql', '04-mongo', '07-mariadb']; before(async () => { - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) .withAnswers({ deploymentApplicationType: MICROSERVICE, @@ -305,15 +298,14 @@ describe('generator - Docker Compose', () => { }); describe('gateway and multi microservices, with 1 mongodb cluster', () => { - let runResult; const chosenApps = ['01-gateway', '02-mysql', '03-psql', '04-mongo']; before(async () => { - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) .withAnswers({ deploymentApplicationType: MICROSERVICE, @@ -340,15 +332,14 @@ describe('generator - Docker Compose', () => { }); describe('gateway and 1 microservice, with Cassandra', () => { - let runResult; const chosenApps = ['01-gateway', '05-cassandra']; before(async () => { - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) .withAnswers({ deploymentApplicationType: MICROSERVICE, @@ -375,15 +366,14 @@ describe('generator - Docker Compose', () => { }); describe('monolith', () => { - let runResult; const chosenApps = ['08-monolith']; before(async () => { - runResult = await helpers + await helpers .generateDeploymentWorkspaces() .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) .withAnswers({ deploymentApplicationType: MONOLITH, @@ -407,15 +397,14 @@ describe('generator - Docker Compose', () => { }); describe('gateway and multi microservices using oauth2', () => { - let runResult; const chosenApps = ['01-gateway', '02-mysql', '03-psql', '10-couchbase', '07-mariadb']; before(async () => { - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ authenticationType: 'oauth2' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) .withAnswers({ deploymentApplicationType: MICROSERVICE, @@ -447,15 +436,14 @@ describe('generator - Docker Compose', () => { }); describe('gateway and multi microservices, with couchbase', () => { - let runResult; const chosenApps = ['01-gateway', '02-mysql', '03-psql', '10-couchbase', '07-mariadb']; before(async () => { - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) .withAnswers({ deploymentApplicationType: MICROSERVICE, @@ -482,15 +470,14 @@ describe('generator - Docker Compose', () => { }); describe('gateway and 1 microservice, with 1 couchbase cluster', () => { - let runResult; const chosenApps = ['01-gateway', '10-couchbase']; before(async () => { - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) .withAnswers({ deploymentApplicationType: MICROSERVICE, @@ -517,15 +504,14 @@ describe('generator - Docker Compose', () => { }); describe('oracle monolith', () => { - let runResult; const chosenApps = ['12-oracle']; before(async () => { - runResult = await helpers + await helpers .generateDeploymentWorkspaces() .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_DOCKER_COMPOSE)) .withAnswers({ deploymentApplicationType: MONOLITH, diff --git a/generators/docker/__test-support/service-discovery-matcher.ts b/generators/docker/__test-support/service-discovery-matcher.ts index 416e24f51188..2ec97ee5e164 100644 --- a/generators/docker/__test-support/service-discovery-matcher.ts +++ b/generators/docker/__test-support/service-discovery-matcher.ts @@ -1,5 +1,4 @@ import { it } from 'esmocha'; -import type { RunResult } from 'yeoman-test'; import { JAVA_DOCKER_DIR } from '../../generator-constants.js'; import { matchWrittenConfig, matchWrittenFiles } from '../../../lib/testing/index.js'; @@ -32,12 +31,12 @@ const desiredConsulConfig = { }, }; -export const matchEureka = (resultGetter: () => RunResult, shouldMatch: boolean) => { - it(...matchWrittenFiles('eureka', expectedEurekaFiles, shouldMatch, resultGetter())); - it(...matchWrittenConfig('eureka', desiredEurekaConfig, shouldMatch, resultGetter())); +export const matchEureka = (shouldMatch: boolean) => { + it(...matchWrittenFiles('eureka', expectedEurekaFiles, shouldMatch)); + it(...matchWrittenConfig('eureka', desiredEurekaConfig, shouldMatch)); }; -export const matchConsul = (resultGetter: () => RunResult, shouldMatch: boolean) => { - it(...matchWrittenFiles('consul', expectedConsulFiles, shouldMatch, resultGetter())); - it(...matchWrittenConfig('consul', desiredConsulConfig, shouldMatch, resultGetter())); +export const matchConsul = (shouldMatch: boolean) => { + it(...matchWrittenFiles('consul', expectedConsulFiles, shouldMatch)); + it(...matchWrittenConfig('consul', desiredConsulConfig, shouldMatch)); }; diff --git a/generators/docker/generator.spec.ts b/generators/docker/generator.spec.ts index 6923212996aa..cbf359ae1cd7 100644 --- a/generators/docker/generator.spec.ts +++ b/generators/docker/generator.spec.ts @@ -97,11 +97,11 @@ describe(`generator - ${generator}`, () => { }); describe('searchEngine', () => { const elasticsearch = searchEngine === ELASTICSEARCH; - matchElasticSearchDocker(() => runResult, elasticsearch); + matchElasticSearchDocker(elasticsearch); }); describe('serviceDiscoveryType', () => { - matchEureka(() => runResult, serviceDiscoveryType === EUREKA); - matchConsul(() => runResult, serviceDiscoveryType === CONSUL); + matchEureka(serviceDiscoveryType === EUREKA); + matchConsul(serviceDiscoveryType === CONSUL); }); }); diff --git a/generators/entities/generator.spec.ts b/generators/entities/generator.spec.ts index ba1f000c65af..0546950c60c4 100644 --- a/generators/entities/generator.spec.ts +++ b/generators/entities/generator.spec.ts @@ -29,7 +29,6 @@ import Generator from './generator.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const generator = basename(__dirname); -const generatorPath = `${__dirname}/index.ts`; describe(`generator - ${generator}`, () => { it('generator-list constant matches folder name', async () => { @@ -75,7 +74,7 @@ describe(`generator - ${generator}`, () => { describe('some entities', () => { before(async () => { await helpers - .run(generatorPath) + .runJHipster(generator) .withJHipsterConfig({}, entities) .withArguments(['Foo', 'Bar']) .withOptions({ @@ -110,7 +109,7 @@ describe(`generator - ${generator}`, () => { describe('all entities', () => { before(async () => { await helpers - .run(generatorPath) + .runJHipster(generator) .withJHipsterConfig({}, entities) .withOptions({ regenerate: true, diff --git a/generators/entity/database-changelog.spec.ts b/generators/entity/database-changelog.spec.ts index e5af64d05166..f3d125770f53 100644 --- a/generators/entity/database-changelog.spec.ts +++ b/generators/entity/database-changelog.spec.ts @@ -1,5 +1,5 @@ import { before, describe, 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 { SERVER_MAIN_RES_DIR } from '../generator-constants.js'; import BaseApplicationGenerator from '../base-application/generator.js'; @@ -20,7 +20,7 @@ describe('generator - entity database changelogs', () => { describe('with cassandra database', () => { before(async () => { await helpers - .run(getGenerator('entity')) + .runJHipster('entity') .withGenerators([[MockedLanguagesGenerator, { namespace: 'jhipster:languages' }]]) .withJHipsterConfig({ databaseType: 'cassandra' }, [entityFoo]) .withArguments(['Foo']) @@ -34,7 +34,7 @@ describe('generator - entity database changelogs', () => { describe('with gateway application type', () => { before(async () => { await helpers - .run(getGenerator('entity')) + .runJHipster('entity') .withGenerators([[MockedLanguagesGenerator, { namespace: 'jhipster:languages' }]]) .withJHipsterConfig({ applicationType: 'gateway' }, [{ ...entityFoo, microserviceName: 'microservice1' }]) .withArguments(['Foo']) diff --git a/generators/entity/single-entity.spec.ts b/generators/entity/single-entity.spec.ts index cc518013fd02..6f64769ad7e9 100644 --- a/generators/entity/single-entity.spec.ts +++ b/generators/entity/single-entity.spec.ts @@ -52,9 +52,8 @@ describe('generator - entity --single-entity', () => { }); describe('with cassandra database', () => { - let runResult; before(async () => { - runResult = await helpers + await helpers .runJHipster(GENERATOR_ENTITY) .withGenerators([[MockedLanguagesGenerator, { namespace: 'jhipster:languages' }]]) .withJHipsterConfig({ databaseType: 'cassandra' }, [entityFoo, entityBar]) diff --git a/generators/export-jdl/export-jdl.spec.ts b/generators/export-jdl/export-jdl.spec.ts index e6c84bc6b53d..77682ec80bd2 100644 --- a/generators/export-jdl/export-jdl.spec.ts +++ b/generators/export-jdl/export-jdl.spec.ts @@ -1,5 +1,5 @@ import { before, describe, expect, it } from 'esmocha'; -import { defaultHelpers as helpers } from '../../lib/testing/index.js'; +import { defaultHelpers as helpers, runResult } from '../../lib/testing/index.js'; import { GENERATOR_EXPORT_JDL } from '../generator-list.js'; const files = { @@ -368,10 +368,8 @@ const applicationConfig = { describe('generator - export-jdl', () => { describe('exports entities to a JDL file without argument', () => { - let runResult; - before(async () => { - runResult = await helpers.runJHipster(GENERATOR_EXPORT_JDL).withJHipsterConfig(applicationConfig).withFiles(files).commitFiles(); + await helpers.runJHipster(GENERATOR_EXPORT_JDL).withJHipsterConfig(applicationConfig).withFiles(files).commitFiles(); }); it('should match snapshot', () => { @@ -383,10 +381,8 @@ describe('generator - export-jdl', () => { }); describe('exports entities to a JDL file with file argument', () => { - let runResult; - before(async () => { - runResult = await helpers + await helpers .runJHipster(GENERATOR_EXPORT_JDL) .withJHipsterConfig(applicationConfig) .withFiles(files) diff --git a/generators/generate-blueprint/generator.spec.ts b/generators/generate-blueprint/generator.spec.ts index 31faba1999c5..fc7170f28553 100644 --- a/generators/generate-blueprint/generator.spec.ts +++ b/generators/generate-blueprint/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'; @@ -28,7 +28,6 @@ import Generator from './index.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); -const generatorPath = join(__dirname, 'index.js'); const generator = basename(__dirname); const mockedGenerators = ['jhipster:init']; @@ -44,7 +43,7 @@ describe(`generator - ${generator}`, () => { describe('with', () => { describe('default config', () => { before(async () => { - await helpers.run(generatorPath).withJHipsterConfig().withMockedGenerators(mockedGenerators); + await helpers.runJHipster(generator).withJHipsterConfig().withMockedGenerators(mockedGenerators); }); it('should compose with init generator', () => { runResult.assertGeneratorComposedOnce('jhipster:init'); @@ -55,7 +54,7 @@ describe(`generator - ${generator}`, () => { }); describe('all option', () => { before(async () => { - await helpers.run(generatorPath).withOptions({ allGenerators: true }).withMockedGenerators(mockedGenerators); + await helpers.runJHipster(generator).withOptions({ allGenerators: true }).withMockedGenerators(mockedGenerators); }); it('should compose with init generator', () => { runResult.assertGeneratorComposedOnce('jhipster:init'); @@ -65,9 +64,8 @@ describe(`generator - ${generator}`, () => { }); }); describe('local-blueprint option', () => { - let runResult; before(async () => { - runResult = await helpers.run(generatorPath).withOptions({ localBlueprint: true }).withMockedGenerators(mockedGenerators); + await helpers.runJHipster(generator).withOptions({ localBlueprint: true }).withMockedGenerators(mockedGenerators); }); it('should not compose with init generator', () => { runResult.assertGeneratorNotComposed('jhipster:init'); @@ -83,10 +81,9 @@ describe(`generator - ${generator}`, () => { }); }); describe('local-blueprint option and app generator', () => { - let runResult; before(async () => { - runResult = await helpers - .run(generatorPath) + await helpers + .runJHipster(generator) .withOptions({ localBlueprint: true, subGenerators: ['app'], allPriorities: true }) .withMockedGenerators(mockedGenerators); }); diff --git a/generators/git/generator.spec.ts b/generators/git/generator.spec.ts index 1a7f507f8a47..4e71eebb23d6 100644 --- a/generators/git/generator.spec.ts +++ b/generators/git/generator.spec.ts @@ -21,7 +21,7 @@ import { fileURLToPath } from 'url'; import { access } from 'fs/promises'; import { before, describe, expect, it } from 'esmocha'; import { testBlueprintSupport } from '../../test/support/tests.js'; -import { skipPrettierHelpers as helpers } from '../../lib/testing/index.js'; +import { skipPrettierHelpers as helpers, runResult } from '../../lib/testing/index.js'; import { GENERATOR_GIT } from '../generator-list.js'; const __filename = fileURLToPath(import.meta.url); @@ -37,9 +37,8 @@ describe(`generator - ${generator}`, () => { describe('blueprint support', () => testBlueprintSupport(generator)); describe('with', () => { describe('default config', () => { - let runResult; before(async () => { - runResult = await helpers.run(generatorPath); + await helpers.runJHipster(generator); }); it('should write files and match snapshot', () => { expect(runResult.getStateSnapshot()).toMatchSnapshot(); @@ -48,9 +47,8 @@ describe(`generator - ${generator}`, () => { }); describe('git feature', () => { describe('with default option', () => { - let runResult; before(async () => { - runResult = await helpers.run(generatorPath).withOptions({ skipGit: false }); + await helpers.runJHipster(generator).withOptions({ skipGit: false }); }); it('should create .git', async () => { await expect(access(resolve(runResult.cwd, '.git'))).resolves.toBeUndefined(); @@ -64,19 +62,17 @@ describe(`generator - ${generator}`, () => { }); }); describe('with skipGit option', () => { - let runResult; before(async () => { - runResult = await helpers.run(generatorPath).withOptions({ skipGit: true }); + await helpers.runJHipster(generator).withOptions({ skipGit: true }); }); it('should not create .git', async () => { await expect(access(resolve(runResult.cwd, '.git'))).rejects.toMatchObject({ code: 'ENOENT' }); }); }); describe('regenerating', () => { - let runResult; before(async () => { - runResult = await helpers.run(generatorPath).withOptions({ skipGit: false }); - runResult = await runResult.create(generatorPath).withOptions({ skipGit: false, baseName: 'changed' }).run(); + await helpers.runJHipster(generator).withOptions({ skipGit: false }); + await runResult.create(generatorPath).withOptions({ skipGit: false, baseName: 'changed' }).run(); }); it('should create a single commit', async () => { const git = runResult.generator.createGit(); @@ -84,10 +80,9 @@ describe(`generator - ${generator}`, () => { }); }); describe('regenerating with --force-git', () => { - let runResult; before(async () => { - runResult = await helpers.run(generatorPath).withOptions({ skipGit: false }); - runResult = await runResult.create(generatorPath).withOptions({ skipGit: false, forceGit: true, baseName: 'changed' }).run(); + await helpers.runJHipster(generator).withOptions({ skipGit: false }); + await runResult.create(generatorPath).withOptions({ skipGit: false, forceGit: true, baseName: 'changed' }).run(); }); it('should create 2 commits', async () => { const git = runResult.generator.createGit(); diff --git a/generators/heroku/heroku.spec.ts b/generators/heroku/heroku.spec.ts index 9edf58867300..58611e020bc4 100644 --- a/generators/heroku/heroku.spec.ts +++ b/generators/heroku/heroku.spec.ts @@ -48,7 +48,7 @@ describe('generator - Heroku', () => { describe('with JAR deployment', () => { beforeEach(async () => { await helpers - .createJHipster(GENERATOR_HEROKU) + .runJHipster(GENERATOR_HEROKU) .withJHipsterConfig({ applicationType: 'microservice' }) .withOptions({ skipBuild: true }) .withAnswers({ @@ -60,8 +60,7 @@ describe('generator - Heroku', () => { herokuJHipsterRegistryPassword: 'changeme', herokuJavaVersion: '17', }) - .withSpawnMock(stub) - .run(); + .withSpawnMock(stub); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -84,7 +83,7 @@ describe('generator - Heroku', () => { .returns(createSpawnCommandReturn({ stdout: `https://git.heroku.com/${autogeneratedAppName}.git` })); await helpers - .createJHipster(GENERATOR_HEROKU) + .runJHipster(GENERATOR_HEROKU) .withJHipsterConfig() .withOptions({ skipBuild: true }) .withAnswers({ @@ -94,8 +93,7 @@ describe('generator - Heroku', () => { herokuForceName: 'No', herokuJavaVersion: '11', }) - .withSpawnMock(stub) - .run(); + .withSpawnMock(stub); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -112,7 +110,7 @@ describe('generator - Heroku', () => { describe('with Git deployment', () => { beforeEach(async () => { await helpers - .createJHipster(GENERATOR_HEROKU) + .runJHipster(GENERATOR_HEROKU) .withJHipsterConfig() .withAnswers({ herokuAppName, @@ -120,8 +118,7 @@ describe('generator - Heroku', () => { herokuDeployType: 'git', herokuJavaVersion: '11', }) - .withSpawnMock(stub) - .run(); + .withSpawnMock(stub); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -138,7 +135,7 @@ describe('generator - Heroku', () => { describe('in the US', () => { beforeEach(async () => { await helpers - .createJHipster(GENERATOR_HEROKU) + .runJHipster(GENERATOR_HEROKU) .withJHipsterConfig() .withOptions({ skipBuild: true }) .withAnswers({ @@ -147,8 +144,7 @@ describe('generator - Heroku', () => { herokuDeployType: 'jar', herokuJavaVersion: '11', }) - .withSpawnMock(stub) - .run(); + .withSpawnMock(stub); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -167,7 +163,7 @@ describe('generator - Heroku', () => { describe('in the EU', () => { beforeEach(async () => { await helpers - .createJHipster(GENERATOR_HEROKU) + .runJHipster(GENERATOR_HEROKU) .withJHipsterConfig() .withOptions({ skipBuild: true }) .withAnswers({ @@ -176,8 +172,7 @@ describe('generator - Heroku', () => { herokuDeployType: 'jar', herokuJavaVersion: '11', }) - .withSpawnMock(stub) - .run(); + .withSpawnMock(stub); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -193,7 +188,7 @@ describe('generator - Heroku', () => { describe('with PostgreSQL', () => { beforeEach(async () => { await helpers - .createJHipster(GENERATOR_HEROKU) + .runJHipster(GENERATOR_HEROKU) .withJHipsterConfig() .withOptions({ skipBuild: true }) .withAnswers({ @@ -202,8 +197,7 @@ describe('generator - Heroku', () => { herokuDeployType: 'jar', herokuJavaVersion: '11', }) - .withSpawnMock(stub) - .run(); + .withSpawnMock(stub); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -225,11 +219,10 @@ describe('generator - Heroku', () => { .withArgs('spawn', 'heroku', sinon.match(['apps:info', '--json', existingHerokuAppName])) .returns(createSpawnCommandReturn({ stdout: `{"app":{"name":"${existingHerokuAppName}"}, "dynos":[]}` })); await helpers - .createJHipster(GENERATOR_HEROKU) + .runJHipster(GENERATOR_HEROKU) .withJHipsterConfig({ herokuAppName: 'jhipster-existing', herokuDeployType: 'git' }) .withOptions({ skipBuild: true }) - .withSpawnMock(stub) - .run(); + .withSpawnMock(stub); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); @@ -246,7 +239,7 @@ describe('generator - Heroku', () => { describe('with elasticsearch', () => { beforeEach(async () => { await helpers - .createJHipster(GENERATOR_HEROKU) + .runJHipster(GENERATOR_HEROKU) .withJHipsterConfig({ searchEngine: 'elasticsearch' }) .withOptions({ skipBuild: true }) .withAnswers({ @@ -255,8 +248,7 @@ describe('generator - Heroku', () => { herokuDeployType: 'jar', herokuJavaVersion: '11', }) - .withSpawnMock(stub) - .run(); + .withSpawnMock(stub); }); it('should match files snapshot', function () { expect(runResult.getSnapshot()).toMatchSnapshot(); diff --git a/generators/java/generators/build-tool/generator.spec.ts b/generators/java/generators/build-tool/generator.spec.ts index 970688784cc5..7d9af89b8a19 100644 --- a/generators/java/generators/build-tool/generator.spec.ts +++ b/generators/java/generators/build-tool/generator.spec.ts @@ -21,7 +21,7 @@ import { fileURLToPath } from 'node:url'; import { before, describe, expect, it } from 'esmocha'; import { shouldSupportFeatures, testBlueprintSupport } from '../../../../test/support/tests.js'; -import { defaultHelpers as helpers, result } from '../../../../lib/testing/index.js'; +import { defaultHelpers as helpers, result, runResult } from '../../../../lib/testing/index.js'; import Generator from './index.js'; const __filename = fileURLToPath(import.meta.url); @@ -45,9 +45,8 @@ describe(`generator - ${generator}`, () => { describe('buildTool option', () => { describe('maven', () => { - let runResult; before(async () => { - runResult = await helpers + await helpers .runJHipster(generator) .withJHipsterConfig({ buildTool: 'maven', @@ -64,9 +63,8 @@ describe(`generator - ${generator}`, () => { }); }); describe('gradle', () => { - let runResult; before(async () => { - runResult = await helpers + await helpers .runJHipster(generator) .withJHipsterConfig({ buildTool: 'gradle', diff --git a/generators/jdl/generator.spec.ts b/generators/jdl/generator.spec.ts index b9bb20ea292c..b35b5a14d5e1 100644 --- a/generators/jdl/generator.spec.ts +++ b/generators/jdl/generator.spec.ts @@ -21,7 +21,6 @@ import { fileURLToPath } from 'url'; import { before, describe, expect, it } from 'esmocha'; import { snakeCase } from 'lodash-es'; -import type { RunResult } from 'yeoman-test'; import { getCommandHelpOutput, shouldSupportFeatures, testBlueprintSupport } from '../../test/support/tests.js'; import { defaultHelpers as helpers, result as runResult } from '../../lib/testing/index.js'; import * as GENERATORS from '../generator-list.js'; @@ -77,10 +76,8 @@ describe(`generator - ${generator}`, () => { }); describe('with valid parameters', () => { - let runResult: RunResult; - before(async () => { - runResult = await helpers.runJHipster(GENERATOR_JDL).withMockedGenerators(mockedGenerators).withOptions({ + await helpers.runJHipster(GENERATOR_JDL).withMockedGenerators(mockedGenerators).withOptions({ inline: 'entity Foo {}', db: 'postgresql', baseName: 'jhipster', @@ -105,10 +102,8 @@ describe(`generator - ${generator}`, () => { }); describe('with valid config', () => { - let runResult: RunResult; - before(async () => { - runResult = await helpers.runJHipster(GENERATOR_JDL).withJHipsterConfig().withMockedGenerators(mockedGenerators).withOptions({ + await helpers.runJHipster(GENERATOR_JDL).withJHipsterConfig().withMockedGenerators(mockedGenerators).withOptions({ inline: 'entity Foo {}', }); }); @@ -133,10 +128,8 @@ describe(`generator - ${generator}`, () => { describe('for application jdl', () => { describe('with valid jdl', () => { - let runResult: RunResult; - before(async () => { - runResult = await helpers.runJHipster(GENERATOR_JDL).withMockedGenerators(mockedGenerators).withOptions({ + await helpers.runJHipster(GENERATOR_JDL).withMockedGenerators(mockedGenerators).withOptions({ inline: 'application { }', }); }); @@ -157,10 +150,8 @@ describe(`generator - ${generator}`, () => { }); describe('with blueprint jdl with blueprint config', () => { - let runResult: RunResult; - before(async () => { - runResult = await helpers.runJHipster(GENERATOR_JDL).withOptions({ + await helpers.runJHipster(GENERATOR_JDL).withOptions({ jsonOnly: true, inline: 'application { config { blueprints [foo, bar] } config(foo) { config fooValue } config(bar) { config barValue } }', }); @@ -198,10 +189,8 @@ describe(`generator - ${generator}`, () => { describe('for one application and entity jdl', () => { describe('with valid jdl', () => { - let runResult: RunResult; - before(async () => { - runResult = await helpers.runJHipster(GENERATOR_JDL).withMockedGenerators(mockedGenerators).withOptions({ + await helpers.runJHipster(GENERATOR_JDL).withMockedGenerators(mockedGenerators).withOptions({ inline: 'application { entities Foo } entity Foo {}', }); }); @@ -223,10 +212,8 @@ describe(`generator - ${generator}`, () => { }); describe('with --ignore-application option', () => { - let runResult: RunResult; - before(async () => { - runResult = await helpers.runJHipster(GENERATOR_JDL).withMockedGenerators(mockedGenerators).withOptions({ + await helpers.runJHipster(GENERATOR_JDL).withMockedGenerators(mockedGenerators).withOptions({ ignoreApplication: true, inline: 'application { entities Foo } entity Foo {}', }); @@ -240,10 +227,8 @@ describe(`generator - ${generator}`, () => { describe('for two applications and entity jdl', () => { describe('with valid jdl', () => { - let runResult: RunResult; - before(async () => { - runResult = await helpers.runJHipster(GENERATOR_JDL).withMockedGenerators(mockedGenerators).withOptions({ + await helpers.runJHipster(GENERATOR_JDL).withMockedGenerators(mockedGenerators).withOptions({ inline: 'application { entities Foo } entity Foo {} application { config { baseName jhipster2 } entities Bar } entity Bar', }); }); @@ -268,10 +253,8 @@ describe(`generator - ${generator}`, () => { }); describe('with --ignore-application option', () => { - let runResult: RunResult; - before(async () => { - runResult = await helpers.runJHipster(GENERATOR_JDL).withMockedGenerators(mockedGenerators).withOptions({ + await helpers.runJHipster(GENERATOR_JDL).withMockedGenerators(mockedGenerators).withOptions({ ignoreApplication: true, inline: 'application { entities Foo } entity Foo {} application { config { baseName jhipster2 } entities Bar } entity Bar', }); @@ -297,10 +280,8 @@ describe(`generator - ${generator}`, () => { describe('--json-only option', () => { describe('for entities only jdl', () => { describe('with valid parameters', () => { - let runResult: RunResult; - before(async () => { - runResult = await helpers.runJHipster(GENERATOR_JDL).withOptions({ + await helpers.runJHipster(GENERATOR_JDL).withOptions({ jsonOnly: true, inline: 'entity Foo {}', db: 'postgresql', @@ -316,10 +297,8 @@ describe(`generator - ${generator}`, () => { }); describe('with valid config', () => { - let runResult: RunResult; - before(async () => { - runResult = await helpers.runJHipster(GENERATOR_JDL).withJHipsterConfig().withOptions({ + await helpers.runJHipster(GENERATOR_JDL).withJHipsterConfig().withOptions({ jsonOnly: true, inline: 'entity Foo {}', }); @@ -335,10 +314,8 @@ describe(`generator - ${generator}`, () => { describe('for application jdl', () => { describe('with valid jdl', () => { - let runResult: RunResult; - before(async () => { - runResult = await helpers.runJHipster(GENERATOR_JDL).withOptions({ + await helpers.runJHipster(GENERATOR_JDL).withOptions({ jsonOnly: true, inline: 'application { }', }); @@ -354,10 +331,8 @@ describe(`generator - ${generator}`, () => { describe('for one application and entity jdl', () => { describe('with valid jdl', () => { - let runResult: RunResult; - before(async () => { - runResult = await helpers.runJHipster(GENERATOR_JDL).withOptions({ + await helpers.runJHipster(GENERATOR_JDL).withOptions({ jsonOnly: true, inline: 'application { entities Foo } entity Foo {}', }); @@ -372,10 +347,8 @@ describe(`generator - ${generator}`, () => { }); describe('with --ignore-application option', () => { - let runResult: RunResult; - before(async () => { - runResult = await helpers.runJHipster(GENERATOR_JDL).withOptions({ + await helpers.runJHipster(GENERATOR_JDL).withOptions({ jsonOnly: true, ignoreApplication: true, inline: 'application { entities Foo } entity Foo {}', @@ -392,10 +365,8 @@ describe(`generator - ${generator}`, () => { describe('for two applications and entity jdl', () => { describe('with valid jdl', () => { - let runResult: RunResult; - before(async () => { - runResult = await helpers.runJHipster(GENERATOR_JDL).withOptions({ + await helpers.runJHipster(GENERATOR_JDL).withOptions({ jsonOnly: true, inline: 'application { entities Foo } entity Foo {} application { config { baseName jhipster2 } entities Bar } entity Bar', }); @@ -407,10 +378,8 @@ describe(`generator - ${generator}`, () => { }); describe('with --ignore-application option', () => { - let runResult: RunResult; - before(async () => { - runResult = await helpers.runJHipster(GENERATOR_JDL).withOptions({ + await helpers.runJHipster(GENERATOR_JDL).withOptions({ jsonOnly: true, ignoreApplication: true, inline: 'application { entities Foo } entity Foo {} application { config { baseName jhipster2 } entities Bar } entity Bar', diff --git a/generators/kubernetes-helm/kubernetes.helm.spec.ts b/generators/kubernetes-helm/kubernetes.helm.spec.ts index 6d9c28aa8c4f..6a00319f89aa 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 } from '../../lib/testing/index.js'; +import { getGenerator, defaultHelpers as helpers, runResult } from '../../lib/testing/index.js'; import { GENERATOR_KUBERNETES_HELM } from '../generator-list.js'; const expectedFiles = { @@ -72,16 +72,15 @@ const expectedFiles = { describe('generator - Kubernetes Helm', () => { describe('only gateway', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_HELM)) .withOptions({ askAnswered: true, @@ -117,16 +116,15 @@ describe('generator - Kubernetes Helm', () => { }); describe('gateway and mysql microservice', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway', '02-mysql']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_HELM)) .withOptions({ askAnswered: true, @@ -164,16 +162,15 @@ describe('generator - Kubernetes Helm', () => { }); describe('mysql microservice with custom namespace', () => { - let runResult; before(async () => { const chosenApps = ['02-mysql']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_HELM)) .withOptions({ askAnswered: true, @@ -211,16 +208,15 @@ describe('generator - Kubernetes Helm', () => { }); describe('gateway and ingress', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_HELM)) .withOptions({ askAnswered: true, @@ -263,16 +259,15 @@ describe('generator - Kubernetes Helm', () => { }); describe('MySQL and PostgreSQL microservices without gateway', () => { - let runResult; before(async () => { const chosenApps = ['02-mysql', '03-psql']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_HELM)) .withOptions({ askAnswered: true, @@ -315,16 +310,15 @@ describe('generator - Kubernetes Helm', () => { }); describe('gateway, mysql, psql, mongodb, mariadb microservices', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway', '02-mysql', '03-psql', '04-mongo', '07-mariadb']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_HELM)) .withOptions({ askAnswered: true, @@ -376,16 +370,15 @@ describe('generator - Kubernetes Helm', () => { }); describe('monolith application', () => { - let runResult; before(async () => { const chosenApps = ['08-monolith']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces() .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_HELM)) .withOptions({ askAnswered: true, @@ -419,16 +412,15 @@ describe('generator - Kubernetes Helm', () => { }); describe('Kafka application', () => { - let runResult; before(async () => { const chosenApps = ['09-kafka']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces() .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_HELM)) .withOptions({ askAnswered: true, @@ -461,16 +453,15 @@ describe('generator - Kubernetes Helm', () => { }); describe('mysql microservice with custom namespace and jhipster prometheus monitoring', () => { - let runResult; before(async () => { const chosenApps = ['02-mysql']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_HELM)) .withOptions({ askAnswered: true, @@ -511,16 +502,15 @@ describe('generator - Kubernetes Helm', () => { }); describe('gateway with istio', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_HELM)) .withOptions({ askAnswered: true, diff --git a/generators/kubernetes-knative/knative.spec.ts b/generators/kubernetes-knative/knative.spec.ts index e38f55208d05..bacfcbacfb78 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 } from '../../lib/testing/index.js'; +import { getGenerator, defaultHelpers as helpers, runResult } from '../../lib/testing/index.js'; import { GENERATOR_KUBERNETES_KNATIVE } from '../generator-list.js'; const expectedFiles = { @@ -98,16 +98,15 @@ const helmExpectedFiles = { describe('generator - Knative', () => { describe('Using K8s generator type', () => { describe('only gateway', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) .withOptions({ askAnswered: true, @@ -144,16 +143,15 @@ describe('generator - Knative', () => { }); describe('gateway and mysql microservice', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway', '02-mysql']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) .withOptions({ askAnswered: true, @@ -190,16 +188,15 @@ describe('generator - Knative', () => { }); describe('mysql microservice with custom namespace', () => { - let runResult; before(async () => { const chosenApps = ['02-mysql']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) .withOptions({ askAnswered: true, @@ -236,16 +233,15 @@ describe('generator - Knative', () => { }); describe('gateway and ingress', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) .withOptions({ askAnswered: true, @@ -280,16 +276,15 @@ describe('generator - Knative', () => { }); describe('MySQL and PostgreSQL microservices without gateway', () => { - let runResult; before(async () => { const chosenApps = ['02-mysql', '03-psql']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) .withOptions({ askAnswered: true, @@ -329,16 +324,15 @@ describe('generator - Knative', () => { }); describe('gateway, mysql, psql, mongodb, mariadb, mssql microservices', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway', '02-mysql', '03-psql', '04-mongo', '07-mariadb', '11-mssql']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) .withOptions({ askAnswered: true, @@ -387,16 +381,15 @@ describe('generator - Knative', () => { }); describe('mysql microservice with custom namespace and jhipster prometheus monitoring', () => { - let runResult; before(async () => { const chosenApps = ['02-mysql']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) .withOptions({ askAnswered: true, @@ -435,16 +428,15 @@ describe('generator - Knative', () => { }); describe('gateway with istio routing files', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) .withOptions({ askAnswered: true, @@ -483,16 +475,15 @@ describe('generator - Knative', () => { describe('Using Helm generator type', () => { describe('only gateway', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) .withOptions({ askAnswered: true, @@ -529,16 +520,15 @@ describe('generator - Knative', () => { }); describe('gateway and mysql microservice', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway', '02-mysql']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) .withOptions({ askAnswered: true, @@ -577,16 +567,15 @@ describe('generator - Knative', () => { }); describe('mysql microservice with custom namespace', () => { - let runResult; before(async () => { const chosenApps = ['02-mysql']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) .withOptions({ askAnswered: true, @@ -625,16 +614,15 @@ describe('generator - Knative', () => { }); describe('gateway and ingress', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) .withOptions({ askAnswered: true, @@ -676,16 +664,15 @@ describe('generator - Knative', () => { }); describe('MySQL and PostgreSQL microservices without gateway', () => { - let runResult; before(async () => { const chosenApps = ['02-mysql', '03-psql']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) .withOptions({ askAnswered: true, @@ -729,16 +716,15 @@ describe('generator - Knative', () => { }); describe('gateway, mysql, psql, mongodb, mariadb microservices', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway', '02-mysql', '03-psql', '04-mongo', '07-mariadb']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) .withOptions({ askAnswered: true, @@ -791,16 +777,15 @@ describe('generator - Knative', () => { }); describe('mysql microservice with custom namespace and jhipster prometheus monitoring', () => { - let runResult; before(async () => { const chosenApps = ['02-mysql']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) .withOptions({ askAnswered: true, @@ -842,16 +827,15 @@ describe('generator - Knative', () => { }); describe('gateway with istio routing files', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES_KNATIVE)) .withOptions({ askAnswered: true, diff --git a/generators/kubernetes/kubernetes.spec.ts b/generators/kubernetes/kubernetes.spec.ts index 74631330aaf7..061e052ea254 100644 --- a/generators/kubernetes/kubernetes.spec.ts +++ b/generators/kubernetes/kubernetes.spec.ts @@ -44,16 +44,15 @@ const expectedFiles = { describe('generator - Kubernetes', () => { describe('only gateway', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces() .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES)) .withSpawnMock() .withOptions({ @@ -96,16 +95,15 @@ describe('generator - Kubernetes', () => { }); describe('only gateway with eureka', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'eureka' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES)) .withSpawnMock() .withOptions({ @@ -147,16 +145,15 @@ describe('generator - Kubernetes', () => { }); describe('gateway and mysql microservice', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway', '02-mysql']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES)) .withSpawnMock() .withOptions({ @@ -248,16 +245,15 @@ describe('generator - Kubernetes', () => { }); describe('gateway and ingress', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES)) .withSpawnMock() .withOptions({ @@ -299,16 +295,15 @@ describe('generator - Kubernetes', () => { }); describe('gateway and ingressType gke', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ authenticationType: 'oauth2' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES)) .withSpawnMock() .withOptions({ @@ -357,16 +352,15 @@ describe('generator - Kubernetes', () => { }); describe('gateway and ingressType nginx', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ authenticationType: 'oauth2' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES)) .withSpawnMock() .withOptions({ @@ -414,16 +408,15 @@ describe('generator - Kubernetes', () => { }); describe('MySQL and PostgreSQL microservices without gateway', () => { - let runResult; before(async () => { const chosenApps = ['02-mysql', '03-psql']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES)) .withSpawnMock() .withOptions({ @@ -468,16 +461,15 @@ describe('generator - Kubernetes', () => { }); describe('gateway, mysql, psql, mongodb, mariadb, mssql microservices', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway', '02-mysql', '03-psql', '04-mongo', '07-mariadb', '11-mssql']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES)) .withSpawnMock() .withOptions({ @@ -531,16 +523,15 @@ describe('generator - Kubernetes', () => { }); describe('monolith application', () => { - let runResult; before(async () => { const chosenApps = ['08-monolith']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces() .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES)) .withSpawnMock() .withOptions({ @@ -580,16 +571,15 @@ describe('generator - Kubernetes', () => { }); describe('Kafka application', () => { - let runResult; before(async () => { const chosenApps = ['09-kafka']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces() .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES)) .withSpawnMock() .withOptions({ @@ -629,16 +619,15 @@ describe('generator - Kubernetes', () => { }); describe('mysql microservice with custom namespace and jhipster prometheus monitoring', () => { - let runResult; before(async () => { const chosenApps = ['02-mysql']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES)) .withSpawnMock() .withOptions({ @@ -682,16 +671,15 @@ describe('generator - Kubernetes', () => { }); describe('gateway with istio routing', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES)) .withSpawnMock() .withOptions({ @@ -733,16 +721,15 @@ describe('generator - Kubernetes', () => { }); describe('mysql, psql, mongodb, mariadb, mssql microservices with dynamic storage provisioning', () => { - let runResult; before(async () => { const chosenApps = ['01-gateway', '02-mysql', '03-psql', '04-mongo', '07-mariadb', '11-mssql']; - runResult = await helpers + await helpers .generateDeploymentWorkspaces({ serviceDiscoveryType: 'consul' }) .withWorkspacesSamples(...chosenApps) .withGenerateWorkspaceApplications(); - runResult = await runResult + await runResult .create(getGenerator(GENERATOR_KUBERNETES)) .withSpawnMock() .withOptions({ diff --git a/generators/languages/generator-needles.spec.ts b/generators/languages/generator-needles.spec.ts index db16f53d2454..20fcaa21e8b7 100644 --- a/generators/languages/generator-needles.spec.ts +++ b/generators/languages/generator-needles.spec.ts @@ -1,10 +1,10 @@ import { before, describe, it } from 'esmocha'; -import { getGenerator, defaultHelpers as helpers, result as runResult } from '../../lib/testing/index.js'; +import { defaultHelpers as helpers, result as runResult } from '../../lib/testing/index.js'; import { CLIENT_MAIN_SRC_DIR } from '../generator-constants.js'; import LanguagesGenerator from './index.js'; -const generatorPath = getGenerator('languages'); +const generator = 'languages'; const mockBlueprintSubGen: any = class extends LanguagesGenerator { constructor(args, opts, features) { @@ -30,7 +30,7 @@ const mockBlueprintSubGen: any = class extends LanguagesGenerator { describe('needle API i18n: JHipster language generator with blueprint', () => { before(async () => { await helpers - .run(generatorPath) + .runJHipster(generator) .withJHipsterConfig({ baseName: 'jhipster' }) .withOptions({ ignoreNeedlesError: true }) .withOptions({ diff --git a/generators/languages/languages.spec.ts b/generators/languages/languages.spec.ts index 5385a268b604..80e6f8acaf78 100644 --- a/generators/languages/languages.spec.ts +++ b/generators/languages/languages.spec.ts @@ -1,5 +1,5 @@ import { fileURLToPath } from 'url'; -import { dirname, join } from 'path'; +import { basename, dirname, join } from 'path'; import { before, describe, it } from 'esmocha'; import { basicHelpers, defaultHelpers as helpers, result as runResult } from '../../lib/testing/index.js'; @@ -9,6 +9,7 @@ import { supportedLanguages } from './support/index.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); +const generator = basename(__dirname); const generatorPath = join(__dirname, 'index.js'); const createClientProject = (options?) => @@ -112,7 +113,7 @@ describe('generator - languages', () => { describe(`with options for ${language.name}`, () => { before(() => helpers - .run(generatorPath) + .runJHipster(generator) .withArguments([language.languageTag]) .withJHipsterConfig({ enableTranslation: true, nativeLanguage: language.languageTag }) .withOptions({ ignoreNeedlesError: true }), @@ -125,7 +126,7 @@ describe('generator - languages', () => { describe('for already generated native language', () => { before(() => helpers - .run(generatorPath) + .runJHipster(generator) .withJHipsterConfig({ enableTranslation: true, nativeLanguage: 'fr', languages: ['fr'], baseName: 'jhipster' }) .withOptions({ commandName: 'languages', ignoreNeedlesError: true }), ); @@ -134,7 +135,7 @@ describe('generator - languages', () => { describe('for already generated languages', () => { before(() => helpers - .run(generatorPath) + .runJHipster(generator) .withJHipsterConfig({ enableTranslation: true, nativeLanguage: 'fr', languages: ['en', 'fr'] }) .withOptions({ commandName: 'languages', ignoreNeedlesError: true }), ); @@ -145,7 +146,7 @@ describe('generator - languages', () => { describe('should create default i18n files for the native language', () => { describe('using prompts', () => { before(() => - helpers.run(generatorPath).withOptions({ ignoreNeedlesError: true }).withAnswers({ + helpers.runJHipster(generator).withOptions({ ignoreNeedlesError: true }).withAnswers({ enableTranslation: true, nativeLanguage: 'fr', languages: [], @@ -156,7 +157,7 @@ describe('generator - languages', () => { describe('using arguments', () => { before(() => helpers - .run(generatorPath) + .runJHipster(generator) .withLocalConfig({ enableTranslation: true }) .withOptions({ ignoreNeedlesError: true }) .withOptions({ nativeLanguage: 'fr', baseName: 'jhipster' }), @@ -166,7 +167,7 @@ describe('generator - languages', () => { describe('when regenerating', () => { before(() => helpers - .run(generatorPath) + .runJHipster(generator) .withLocalConfig({ enableTranslation: true, nativeLanguage: 'fr', languages: ['fr'] }) .withOptions({ ignoreNeedlesError: true }) .withOptions({ skipPrompts: true, regenerate: true, baseName: 'jhipster' }), @@ -176,13 +177,13 @@ describe('generator - languages', () => { }); describe('should create default i18n files for the native language and an additional language', () => { describe('by default', () => { - before(() => helpers.run(generatorPath).withJHipsterConfig().withOptions({ ignoreNeedlesError: true })); + before(() => helpers.runJHipster(generator).withJHipsterConfig().withOptions({ ignoreNeedlesError: true })); containsLanguageFiles('en'); }); describe('using prompts', () => { before(() => helpers - .run(generatorPath) + .runJHipster(generator) .withOptions({ ignoreNeedlesError: true }) .withAnswers({ enableTranslation: true, @@ -205,7 +206,7 @@ describe('generator - languages', () => { describe('using arguments', () => { before(() => helpers - .run(generatorPath) + .runJHipster(generator) .withLocalConfig({ enableTranslation: true }) .withArguments(['en']) .withOptions({ ignoreNeedlesError: true }) @@ -217,7 +218,7 @@ describe('generator - languages', () => { describe('when regenerating', () => { before(() => helpers - .run(generatorPath) + .runJHipster(generator) .withJHipsterConfig({ enableTranslation: true, nativeLanguage: 'fr', languages: ['en', 'fr'] }) .withOptions({ ignoreNeedlesError: true }) .withOptions({ skipPrompts: true, regenerate: true, baseName: 'jhipster' }), @@ -239,7 +240,7 @@ describe('generator - languages', () => { describe('with prompts', () => { before(() => helpers - .run(generatorPath) + .runJHipster(generator) .withOptions({ ignoreNeedlesError: true }) .withAnswers({ enableTranslation: true, @@ -253,7 +254,7 @@ describe('generator - languages', () => { describe('with options', () => { before(() => helpers - .run(generatorPath) + .runJHipster(generator) .withJHipsterConfig({ enableTranslation: true, nativeLanguage: 'en' }) .withOptions({ ignoreNeedlesError: true }) .withArguments(['fr', 'de']) diff --git a/generators/server/generator.spec.ts b/generators/server/generator.spec.ts index fae936a53c82..2308b53a0b54 100644 --- a/generators/server/generator.spec.ts +++ b/generators/server/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'; @@ -31,7 +31,6 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const generator = basename(__dirname); -const generatorPath = join(__dirname, 'index.js'); describe(`generator - ${generator}`, () => { it('generator-list constant matches folder name', async () => { @@ -44,10 +43,9 @@ describe(`generator - ${generator}`, () => { describe('composing', () => { describe('messageBroker option', () => { describe('no', () => { - let runResult; before(async () => { - runResult = await helpers - .run(generatorPath) + await helpers + .runJHipster(generator) .withJHipsterConfig({ messageBroker: 'no', }) @@ -59,10 +57,9 @@ describe(`generator - ${generator}`, () => { shouldComposeWithSpringCloudStream(false, () => runResult); }); describe('kafka', () => { - let runResult; before(async () => { - runResult = await helpers - .run(generatorPath) + await helpers + .runJHipster(generator) .withJHipsterConfig({ messageBroker: 'kafka', }) @@ -73,10 +70,9 @@ describe(`generator - ${generator}`, () => { shouldComposeWithSpringCloudStream(true, () => runResult); }); describe('pulsar', () => { - let runResult; before(async () => { - runResult = await helpers - .run(generatorPath) + await helpers + .runJHipster(generator) .withJHipsterConfig({ messageBroker: 'pulsar', }) @@ -92,7 +88,7 @@ describe(`generator - ${generator}`, () => { describe('no with jwt', () => { before(async () => { await helpers - .run(generatorPath) + .runJHipster(generator) .withJHipsterConfig({ databaseType: 'no', authenticationType: 'jwt', @@ -110,7 +106,7 @@ describe(`generator - ${generator}`, () => { describe('no with session', () => { before(async () => { await helpers - .run(generatorPath) + .runJHipster(generator) .withJHipsterConfig({ databaseType: 'no', authenticationType: 'session', @@ -128,7 +124,7 @@ describe(`generator - ${generator}`, () => { describe('no with oauth2', () => { before(async () => { await helpers - .run(generatorPath) + .runJHipster(generator) .withJHipsterConfig({ databaseType: 'no', authenticationType: 'oauth2', @@ -144,10 +140,9 @@ describe(`generator - ${generator}`, () => { shouldComposeWithCouchbase(false, () => runResult); }); describe('couchbase', () => { - let runResult; before(async () => { - runResult = await helpers - .run(generatorPath) + await helpers + .runJHipster(generator) .withJHipsterConfig({ databaseType: 'couchbase', }) diff --git a/generators/spring-cloud-stream/generator-pulsar.spec.ts b/generators/spring-cloud-stream/generator-pulsar.spec.ts index 69f238ca237e..9ebd5b5921bb 100644 --- a/generators/spring-cloud-stream/generator-pulsar.spec.ts +++ b/generators/spring-cloud-stream/generator-pulsar.spec.ts @@ -22,7 +22,7 @@ import { before, describe, expect, it } from 'esmocha'; import { snakeCase } from 'lodash-es'; import { shouldSupportFeatures, testBlueprintSupport } from '../../test/support/tests.js'; -import { buildSamplesFromMatrix, buildServerMatrix, defaultHelpers as helpers } from '../../lib/testing/index.js'; +import { buildSamplesFromMatrix, buildServerMatrix, defaultHelpers as helpers, runResult } from '../../lib/testing/index.js'; import { messageBrokerTypes } from '../../lib/jhipster/index.js'; import Generator from './index.js'; @@ -47,10 +47,8 @@ describe(`generator - ${generator}`, () => { Object.entries(testSamples).forEach(([name, config]) => { describe(name, () => { - let runResult; - before(async () => { - runResult = await helpers.run(generatorFile).withJHipsterConfig(config); + await helpers.run(generatorFile).withJHipsterConfig(config); }); it('should match generated files snapshot', () => { diff --git a/generators/spring-cloud-stream/generator.spec.ts b/generators/spring-cloud-stream/generator.spec.ts index a668c6d21fa5..85b916e8b588 100644 --- a/generators/spring-cloud-stream/generator.spec.ts +++ b/generators/spring-cloud-stream/generator.spec.ts @@ -22,7 +22,7 @@ import { before, describe, expect, it } from 'esmocha'; import { snakeCase } from 'lodash-es'; import { shouldSupportFeatures, testBlueprintSupport } from '../../test/support/tests.js'; -import { buildSamplesFromMatrix, buildServerMatrix, defaultHelpers as helpers } from '../../lib/testing/index.js'; +import { buildSamplesFromMatrix, buildServerMatrix, defaultHelpers as helpers, runResult } from '../../lib/testing/index.js'; import { messageBrokerTypes } from '../../lib/jhipster/index.js'; import Generator from './index.js'; @@ -46,10 +46,8 @@ describe(`generator - ${generator}`, () => { Object.entries(testSamples).forEach(([name, config]) => { describe(name, () => { - let runResult; - before(async () => { - runResult = await helpers.runJHipster(generator).withJHipsterConfig(config).withMockedSource(); + await helpers.runJHipster(generator).withJHipsterConfig(config).withMockedSource(); }); it('should match generated files snapshot', () => { diff --git a/generators/spring-data-cassandra/database-changelog.spec.ts b/generators/spring-data-cassandra/database-changelog.spec.ts index dd95f5e0fc42..e95de5aa2f03 100644 --- a/generators/spring-data-cassandra/database-changelog.spec.ts +++ b/generators/spring-data-cassandra/database-changelog.spec.ts @@ -1,5 +1,5 @@ import { before, describe, it } from 'esmocha'; -import { defaultHelpers as helpers } from '../../lib/testing/index.js'; +import { defaultHelpers as helpers, runResult } from '../../lib/testing/index.js'; import { SERVER_MAIN_RES_DIR } from '../generator-constants.js'; import { GENERATOR_SPRING_DATA_CASSANDRA } from '../generator-list.js'; @@ -9,9 +9,8 @@ const entityFoo = { name: 'Foo', changelogDate: '20160926101210' }; describe('generator - app - database changelogs', () => { describe('when regenerating the application', () => { describe('with cassandra database', () => { - let runResult; before(async () => { - runResult = await helpers + await helpers .runJHipster(GENERATOR_SPRING_DATA_CASSANDRA) .withJHipsterConfig({ databaseType: 'cassandra' }, [entityFoo]) .withOptions({ force: true, skipClient: true }); diff --git a/generators/spring-data-elasticsearch/__test-support/elastic-search-matcher.ts b/generators/spring-data-elasticsearch/__test-support/elastic-search-matcher.ts index 637e458f8fe7..23c7646730b9 100644 --- a/generators/spring-data-elasticsearch/__test-support/elastic-search-matcher.ts +++ b/generators/spring-data-elasticsearch/__test-support/elastic-search-matcher.ts @@ -1,15 +1,14 @@ import { it } from 'esmocha'; -import type { RunResult } from 'yeoman-test'; import { JAVA_DOCKER_DIR, SERVER_MAIN_SRC_DIR } from '../../generator-constants.js'; -import { matchWrittenConfig, matchWrittenFiles } from '../../../lib/testing/index.js'; +import { matchWrittenConfig, matchWrittenFiles, runResult } from '../../../lib/testing/index.js'; const expectedElasticsearchFiles = () => { return [`${JAVA_DOCKER_DIR}elasticsearch.yml`]; }; -const expectedElasticsearchUserFiles = (resultGetter: () => RunResult) => { - const application = (resultGetter() as any).generator.sharedData.getApplication(); +const expectedElasticsearchUserFiles = () => { + const application = runResult.generator.sharedData.getApplication(); return application.generateBuiltInUserEntity ? [`${SERVER_MAIN_SRC_DIR}${application.packageFolder}/repository/search/UserSearchRepository.java`] : []; @@ -21,14 +20,14 @@ const desiredConfig = { }, }; -export const matchElasticSearchDocker = (resultGetter: () => RunResult, shouldMatch: boolean) => { - it(...matchWrittenFiles('elasticsearch', expectedElasticsearchFiles, shouldMatch, resultGetter())); +export const matchElasticSearchDocker = (shouldMatch: boolean) => { + it(...matchWrittenFiles('elasticsearch', expectedElasticsearchFiles, shouldMatch)); }; -export const matchElasticSearch = (resultGetter: () => RunResult, shouldMatch: boolean) => { - it(...matchWrittenConfig('elasticsearch', desiredConfig, shouldMatch, resultGetter())); +export const matchElasticSearch = (shouldMatch: boolean) => { + it(...matchWrittenConfig('elasticsearch', desiredConfig, shouldMatch)); }; -export const matchElasticSearchUser = (resultGetter: () => RunResult, shouldMatch: boolean) => { - it(...matchWrittenFiles('elasticsearch user', () => expectedElasticsearchUserFiles(resultGetter), shouldMatch, resultGetter())); +export const matchElasticSearchUser = (shouldMatch: boolean) => { + it(...matchWrittenFiles('elasticsearch user', () => expectedElasticsearchUserFiles(), shouldMatch)); }; diff --git a/generators/spring-data-elasticsearch/generator.spec.ts b/generators/spring-data-elasticsearch/generator.spec.ts index 98d3c1d5930b..6561cb4abd5c 100644 --- a/generators/spring-data-elasticsearch/generator.spec.ts +++ b/generators/spring-data-elasticsearch/generator.spec.ts @@ -106,9 +106,8 @@ describe('generator - elasticsearch', () => { describe('searchEngine', () => { const elasticsearch = sampleConfig.searchEngine === ELASTICSEARCH; - matchElasticSearch(() => runResult, elasticsearch); + matchElasticSearch(elasticsearch); matchElasticSearchUser( - () => runResult, elasticsearch && (sampleConfig.authenticationType === OAUTH2 || (sampleConfig.applicationType !== MICROSERVICE && !sampleConfig.skipUserManagement)), diff --git a/lib/testing/helpers.ts b/lib/testing/helpers.ts index 313622ba88c3..72912c20c16a 100644 --- a/lib/testing/helpers.ts +++ b/lib/testing/helpers.ts @@ -455,6 +455,7 @@ class JHipsterTest extends YeomanTest { return super.create(GeneratorOrNamespace, settings, envOptions) as any; } + /** @deprecated */ createJHipster( jhipsterGenerator: string, settings?: RunContextSettings | undefined, diff --git a/lib/testing/support/matcher.ts b/lib/testing/support/matcher.ts index bff607c3c1fe..327880c51f35 100644 --- a/lib/testing/support/matcher.ts +++ b/lib/testing/support/matcher.ts @@ -1,4 +1,4 @@ -import { result } from 'yeoman-test'; +import { runResult } from '../helpers.js'; /** * Requires a global `it` function to be available. @@ -6,12 +6,7 @@ import { result } from 'yeoman-test'; * @example * it(..matchWrittenFiles('eureka', () => ['file'], true)); */ -export const matchWrittenFiles = ( - title: string, - expectedFilesGetter: () => string[], - shouldMatch: boolean, - runResult = result, -): [string, () => void] => [ +export const matchWrittenFiles = (title: string, expectedFilesGetter: () => string[], shouldMatch: boolean): [string, () => void] => [ shouldMatch ? `writes ${title} files` : `doesn't write ${title} files`, () => { if (shouldMatch) { @@ -28,7 +23,7 @@ export const matchWrittenFiles = ( * @example * it(..matchWrittenFiles('eureka', { 'generator-jhipster': { config: true } }, true)); */ -export const matchWrittenConfig = (title: string, config: any, shouldMatch: boolean, runResult = result): [string, () => void] => [ +export const matchWrittenConfig = (title: string, config: any, shouldMatch: boolean): [string, () => void] => [ shouldMatch ? `writes ${title} config` : `doesn't write ${title} config`, () => { if (shouldMatch) { diff --git a/lib/types/application/options.d.ts b/lib/types/application/options.d.ts index a089c1ed9a1d..88482926d6c3 100644 --- a/lib/types/application/options.d.ts +++ b/lib/types/application/options.d.ts @@ -7,6 +7,7 @@ export type ApplicationOptions = Simplify< ExportGeneratorOptionsFromCommand & ExportGeneratorOptionsFromCommand & ExportGeneratorOptionsFromCommand & + ExportGeneratorOptionsFromCommand & ExportGeneratorOptionsFromCommand & ExportGeneratorOptionsFromCommand & ExportGeneratorOptionsFromCommand & diff --git a/lib/types/application/yo-rc.d.ts b/lib/types/application/yo-rc.d.ts index 909ba4e572e4..99424fbdb665 100644 --- a/lib/types/application/yo-rc.d.ts +++ b/lib/types/application/yo-rc.d.ts @@ -16,6 +16,7 @@ export type ApplicationConfiguration = Simplify< ExportStoragePropertiesFromCommand & ExportStoragePropertiesFromCommand & ExportStoragePropertiesFromCommand & + ExportStoragePropertiesFromCommand & ExportStoragePropertiesFromCommand & ExportStoragePropertiesFromCommand & ExportStoragePropertiesFromCommand & diff --git a/test/needle-api/needle-client-angular.spec.ts b/test/needle-api/needle-client-angular.spec.ts index e9a9bb2981c1..1fe48a971487 100644 --- a/test/needle-api/needle-client-angular.spec.ts +++ b/test/needle-api/needle-client-angular.spec.ts @@ -1,5 +1,5 @@ import { before, describe, it } from 'esmocha'; -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'; import { CLIENT_MAIN_SRC_DIR } from '../../generators/generator-constants.js'; import BaseApplicationGenerator from '../../generators/base-application/index.js'; @@ -33,15 +33,14 @@ const mockBlueprintSubGen = class extends AngularGenerator { describe('needle API Angular: JHipster angular generator with blueprint', () => { before(async () => { await helpers - .create(getGenerator('angular')) + .runJHipster('angular') .withJHipsterConfig({ skipServer: true, }) .withOptions({ blueprint: ['myblueprint'], }) - .withGenerators([[mockBlueprintSubGen, { namespace: 'jhipster-myblueprint:angular' }]]) - .run(); + .withGenerators([[mockBlueprintSubGen, { namespace: 'jhipster-myblueprint:angular' }]]); }); it('vendor.scss contains the specific change (without comment) added by needle api', () => { diff --git a/test/needle-api/needle-client-react-generator.spec.ts b/test/needle-api/needle-client-react-generator.spec.ts index 7bf36be67fd4..059e0477dd1a 100644 --- a/test/needle-api/needle-client-react-generator.spec.ts +++ b/test/needle-api/needle-client-react-generator.spec.ts @@ -1,5 +1,5 @@ import { before, describe, it } from 'esmocha'; -import { getGenerator, defaultHelpers as helpers, result as runResult } from '../../lib/testing/index.js'; +import { defaultHelpers as helpers, result as runResult } from '../../lib/testing/index.js'; import { CLIENT_MAIN_SRC_DIR } from '../../generators/generator-constants.js'; import { clientFrameworkTypes } from '../../lib/jhipster/index.js'; import ReactGenerator from '../../generators/react/index.js'; @@ -39,7 +39,7 @@ describe('needle API React: JHipster client generator with blueprint', () => { before(async () => { result = await helpers - .run(getGenerator('react')) + .runJHipster('react') .withOptions({ build: 'maven', auth: 'jwt', diff --git a/test/needle-api/needle-client-react.spec.ts b/test/needle-api/needle-client-react.spec.ts index 9b34e5d94f5d..4f8ffbc48396 100644 --- a/test/needle-api/needle-client-react.spec.ts +++ b/test/needle-api/needle-client-react.spec.ts @@ -1,5 +1,5 @@ import { before, describe, it } from 'esmocha'; -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'; import { CLIENT_MAIN_SRC_DIR } from '../../generators/generator-constants.js'; import { clientFrameworkTypes } from '../../lib/jhipster/index.js'; import BaseApplicationGenerator from '../../generators/base-application/index.js'; @@ -32,7 +32,7 @@ const mockBlueprintSubGen: any = class extends ReactGenerator { describe('needle API React: JHipster react generator with blueprint', () => { before(async () => { await helpers - .run(getGenerator('react')) + .runJHipster('react') .withOptions({ build: 'maven', auth: 'jwt', diff --git a/test/needle-api/needle-client-vue-generator.spec.ts b/test/needle-api/needle-client-vue-generator.spec.ts index 1388d8a56bb7..844c8b287a7f 100644 --- a/test/needle-api/needle-client-vue-generator.spec.ts +++ b/test/needle-api/needle-client-vue-generator.spec.ts @@ -1,5 +1,5 @@ import { before, describe, it } from 'esmocha'; -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'; import { CLIENT_MAIN_SRC_DIR } from '../../generators/generator-constants.js'; import { clientFrameworkTypes } from '../../lib/jhipster/index.js'; @@ -40,7 +40,7 @@ const mockBlueprintSubGen: any = class extends VueGenerator { describe('needle API Vue: JHipster client generator with blueprint', () => { before(() => helpers - .run(getGenerator('vue')) + .runJHipster('vue') .withOptions({ build: 'maven', auth: 'jwt', diff --git a/test/needle-api/needle-client-vue.spec.ts b/test/needle-api/needle-client-vue.spec.ts index 07870f8fbb53..a16fd47c8289 100644 --- a/test/needle-api/needle-client-vue.spec.ts +++ b/test/needle-api/needle-client-vue.spec.ts @@ -1,5 +1,5 @@ import { before, describe } from 'esmocha'; -import { getGenerator, basicHelpers as helpers } from '../../lib/testing/index.js'; +import { basicHelpers as helpers } from '../../lib/testing/index.js'; import ClientGenerator from '../../generators/client/index.js'; import { clientFrameworkTypes } from '../../lib/jhipster/index.js'; @@ -20,7 +20,7 @@ const mockBlueprintSubGen: any = class extends ClientGenerator { describe('needle API Vue: JHipster client generator with blueprint', () => { before(() => helpers - .run(getGenerator('client')) + .runJHipster('client') .withOptions({ build: 'maven', auth: 'jwt', diff --git a/test/support/tests.js b/test/support/tests.js index 87770f1c661b..f674b14bb6ac 100644 --- a/test/support/tests.js +++ b/test/support/tests.js @@ -3,7 +3,7 @@ import sinon from 'sinon'; import { before, describe, expect, it } from 'esmocha'; import { buildJHipster } from '../../cli/index.mjs'; import { GENERATOR_JHIPSTER } from '../../generators/generator-constants.js'; -import { getGenerator, skipPrettierHelpers as helpers } from '../../lib/testing/index.js'; +import { getGenerator, skipPrettierHelpers as helpers, runResult } from '../../lib/testing/index.js'; import { ENTITY_PRIORITY_NAMES, PRIORITY_NAMES, PRIORITY_NAMES_LIST } from '../../generators/base-application/priorities.js'; import { WORKSPACES_PRIORITY_NAMES } from '../../generators/base-workspaces/priorities.js'; @@ -35,9 +35,8 @@ export const getCommandHelpOutput = async command => { export const testOptions = data => { const { generatorPath, customOptions, contextBuilder = () => helpers.create(generatorPath) } = data; - let runResult; before(async () => { - runResult = await contextBuilder() + await contextBuilder() .withOptions({ ...customOptions }) .run(); }); @@ -59,9 +58,8 @@ export const basicTests = data => { contextBuilder = () => helpers.create(generatorPath), } = data; describe('with default options', () => { - let runResult; before(async () => { - runResult = await contextBuilder() + await contextBuilder() .withOptions({ skipPrompts: true, configure: true, @@ -77,9 +75,8 @@ export const basicTests = data => { }); }); describe('with defaults option', () => { - let runResult; before(async () => { - runResult = await contextBuilder().withOptions({ defaults: true, skipPriorities: skipWritingPriorities }).run(); + await contextBuilder().withOptions({ defaults: true, skipPriorities: skipWritingPriorities }).run(); }); it('should write default config to .yo-rc.json', () => { runResult.assertJsonFileContent('.yo-rc.json', { [GENERATOR_JHIPSTER]: requiredConfig }); @@ -89,13 +86,9 @@ export const basicTests = data => { }); }); describe('with custom prompt values', () => { - let runResult; describe('and default options', () => { before(async () => { - runResult = await contextBuilder() - .withOptions({ configure: true, skipPriorities: skipWritingPriorities }) - .withAnswers(customPrompts) - .run(); + await contextBuilder().withOptions({ configure: true, skipPriorities: skipWritingPriorities }).withAnswers(customPrompts).run(); }); it('should show prompts and write prompt values to .yo-rc.json', () => { runResult.assertJsonFileContent('.yo-rc.json', { [GENERATOR_JHIPSTER]: customPrompts }); @@ -106,10 +99,7 @@ export const basicTests = data => { }); describe('and defaults option', () => { before(async () => { - runResult = await contextBuilder() - .withOptions({ defaults: true, skipPriorities: skipWritingPriorities }) - .withAnswers(customPrompts) - .run(); + await contextBuilder().withOptions({ defaults: true, skipPriorities: skipWritingPriorities }).withAnswers(customPrompts).run(); }); it('should not show prompts and write default config to .yo-rc.json', () => { runResult.assertJsonFileContent('.yo-rc.json', { [GENERATOR_JHIPSTER]: requiredConfig }); @@ -119,12 +109,8 @@ export const basicTests = data => { }); }); describe('and skipPrompts option', () => { - let runResult; before(async () => { - runResult = await contextBuilder() - .withOptions({ skipPrompts: true, skipPriorities: skipWritingPriorities }) - .withAnswers(customPrompts) - .run(); + await contextBuilder().withOptions({ skipPrompts: true, skipPriorities: skipWritingPriorities }).withAnswers(customPrompts).run(); }); it('should not show prompts and write required config to .yo-rc.json', () => { runResult.assertJsonFileContent('.yo-rc.json', { [GENERATOR_JHIPSTER]: requiredConfig }); @@ -134,10 +120,9 @@ export const basicTests = data => { }); }); describe('and existing config', () => { - let runResult; const existing = { baseName: 'existing' }; before(async () => { - runResult = await contextBuilder() + await contextBuilder() .withJHipsterConfig(existing) .withOptions({ skipPriorities: skipWritingPriorities }) .withAnswers(customPrompts) @@ -151,9 +136,8 @@ export const basicTests = data => { }); }); describe('and askAnswered option on an existing project', () => { - let runResult; before(async () => { - runResult = await contextBuilder() + await contextBuilder() .withJHipsterConfig({ baseName: 'existing' }) .withOptions({ askAnswered: true, @@ -170,10 +154,9 @@ export const basicTests = data => { }); }); describe('and add option on an existing project', () => { - let runResult; const existingConfig = { baseName: 'existing' }; before(async () => { - runResult = await contextBuilder() + await contextBuilder() .withJHipsterConfig(existingConfig) .withOptions({ add: true, @@ -248,7 +231,7 @@ export const testBlueprintSupport = (generatorName, options = {}) => { let spy; before(async () => { result = await helpers - .run(generatorPath) + .runJHipster(generatorName) .withMockedJHipsterGenerators({ filter: () => true }) .withMockedGenerators([`jhipster-foo:${generatorName}`]) .withJHipsterConfig() @@ -272,7 +255,7 @@ export const testBlueprintSupport = (generatorName, options = {}) => { this.skip(); } const context = helpers - .run(generatorPath) + .runJHipster(generatorName) .withMockedJHipsterGenerators({ filter: () => true }) .withMockedGenerators([`jhipster-foo-sbs:${generatorName}`]) .withJHipsterConfig(