Skip to content

Commit

Permalink
tests: switch to JHipster helpers (#27413)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima authored Sep 25, 2024
1 parent 90d109c commit 0101254
Show file tree
Hide file tree
Showing 47 changed files with 386 additions and 617 deletions.
11 changes: 4 additions & 7 deletions generators/app/composing.spec.ts
Original file line number Diff line number Diff line change
@@ -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 = [
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
28 changes: 12 additions & 16 deletions generators/app/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 () => {
Expand All @@ -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', () => {
Expand All @@ -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',
})
Expand All @@ -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',
})
Expand All @@ -108,7 +104,7 @@ describe(`generator - ${generator}`, () => {
describe('with application', () => {
before(async () => {
await helpers
.run(generatorPath)
.runJHipster(generator)
.withJHipsterConfig({
jdlStore: 'app.jdl',
skipServer: true,
Expand All @@ -125,7 +121,7 @@ describe(`generator - ${generator}`, () => {
describe('with application and entities', () => {
before(async () => {
await helpers
.run(generatorPath)
.runJHipster(generator)
.withJHipsterConfig(
{
jdlStore: 'app.jdl',
Expand All @@ -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',
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -241,7 +237,7 @@ describe(`generator - ${generator}`, () => {
describe('with microservice', () => {
before(async () => {
await helpers
.run(generatorPath)
.runJHipster(generator)
.withAnswers({ applicationType: 'microservice', databaseType: 'mongodb' })
.withSkipWritingPriorities();
});
Expand Down
3 changes: 3 additions & 0 deletions generators/base-application/types.d.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -143,6 +145,7 @@ export type CommonClientServerApplication<Entity> = BaseApplication &
AuthenticationProperties<Entity> &
SpringBootApplication &
ClientApplication &
ExportApplicationPropertiesFromCommand<typeof import('../git/command.ts').default> &
ApplicationProperties & {
clientRootDir: string;
clientSrcDir: string;
Expand Down
29 changes: 8 additions & 21 deletions generators/base/blueprints.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
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';

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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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'])
Expand All @@ -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'])
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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', () => {
Expand Down
18 changes: 8 additions & 10 deletions generators/bootstrap-application-base/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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}`, () => {
Expand All @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -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();
Expand All @@ -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);
});
Expand All @@ -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();
Expand All @@ -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\.$/,
);
});
Expand Down
8 changes: 3 additions & 5 deletions generators/bootstrap-application-client/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`, () => {
Expand All @@ -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', () => {
Expand Down
Loading

0 comments on commit 0101254

Please sign in to comment.