Skip to content

Commit

Permalink
Merge pull request #26617 from mshima/internal
Browse files Browse the repository at this point in the history
Improve test apis.
  • Loading branch information
DanielFran authored Jul 4, 2024
2 parents ff191b8 + 8b707a1 commit 4d5f944
Show file tree
Hide file tree
Showing 23 changed files with 141 additions and 543 deletions.
2 changes: 1 addition & 1 deletion generators/base/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export type WriteFileTemplate<Generator = CoreGenerator, DataType = any> =
binary?: boolean;
/** ejs options. Refer to https://ejs.co/#docs */
options?: Record<string, object>;
override?: (this: Generator, data: DataType) => boolean;
override?: boolean | ((this: Generator, data: DataType) => boolean);
};

export type WriteFileBlock<Generator = CoreGenerator, DataType = any> = {
Expand Down
21 changes: 0 additions & 21 deletions generators/init/templates/.eslintignore.jhi.ejs

This file was deleted.

9 changes: 0 additions & 9 deletions generators/server/__snapshots__/generator.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ exports[`generator - server composing databaseType option no with jwt should mat
"pom.xml": {
"stateCleared": "modified",
},
"src/main/docker/jib/entrypoint.sh": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/ApplicationWebXml.java": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -253,9 +250,6 @@ exports[`generator - server composing databaseType option no with oauth2 should
"pom.xml": {
"stateCleared": "modified",
},
"src/main/docker/jib/entrypoint.sh": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/ApplicationWebXml.java": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -489,9 +483,6 @@ exports[`generator - server composing databaseType option no with session should
"pom.xml": {
"stateCleared": "modified",
},
"src/main/docker/jib/entrypoint.sh": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/ApplicationWebXml.java": {
"stateCleared": "modified",
},
Expand Down
60 changes: 15 additions & 45 deletions generators/server/__test-support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,17 @@ import assert from 'assert';

import { messageBrokerTypes, databaseTypes } from '../../../jdl/jhipster/index.js';
import {
GENERATOR_CUCUMBER,
GENERATOR_GATLING,
GENERATOR_SPRING_CACHE,
GENERATOR_SPRING_WEBSOCKET,
GENERATOR_SPRING_DATA_RELATIONAL,
GENERATOR_SPRING_DATA_CASSANDRA,
GENERATOR_SPRING_DATA_COUCHBASE,
GENERATOR_SPRING_DATA_MONGODB,
GENERATOR_MAVEN,
GENERATOR_LIQUIBASE,
GENERATOR_LANGUAGES,
GENERATOR_SPRING_CLOUD_STREAM,
GENERATOR_GRADLE,
GENERATOR_DOCKER,
GENERATOR_COMMON,
GENERATOR_JAVA,
GENERATOR_PROJECT_NAME,
GENERATOR_SERVER,
GENERATOR_SPRING_BOOT,
GENERATOR_BOOTSTRAP,
} from '../../generator-list.js';

const { KAFKA, PULSAR } = messageBrokerTypes;
const { SQL, COUCHBASE } = databaseTypes;

export const mockedGenerators = [
`jhipster:${GENERATOR_COMMON}`,
`jhipster:${GENERATOR_SPRING_DATA_COUCHBASE}`,
`jhipster:${GENERATOR_CUCUMBER}`,
`jhipster:${GENERATOR_DOCKER}`,
`jhipster:${GENERATOR_GATLING}`,
`jhipster:${GENERATOR_GRADLE}`,
`jhipster:${GENERATOR_GRADLE}:code-quality`,
`jhipster:${GENERATOR_GRADLE}:jib`,
`jhipster:${GENERATOR_GRADLE}:node-gradle`,
`jhipster:${GENERATOR_SPRING_CLOUD_STREAM}`,
// `jhipster:${GENERATOR_JAVA}`,
// `jhipster:${GENERATOR_JAVA}:domain`,
// `jhipster:${GENERATOR_JAVA}:bootstrap`,
`jhipster:${GENERATOR_JAVA}:build-tool`,
`jhipster:${GENERATOR_JAVA}:code-quality`,
`jhipster:${GENERATOR_JAVA}:node`,
`jhipster:${GENERATOR_LANGUAGES}`,
`jhipster:${GENERATOR_LIQUIBASE}`,
`jhipster:${GENERATOR_MAVEN}`,
`jhipster:${GENERATOR_MAVEN}:code-quality`,
`jhipster:${GENERATOR_MAVEN}:jib`,
`jhipster:${GENERATOR_MAVEN}:node`,
'jhipster:spring-cloud:gateway',
`jhipster:${GENERATOR_SPRING_DATA_CASSANDRA}`,
`jhipster:${GENERATOR_SPRING_DATA_MONGODB}`,
`jhipster:${GENERATOR_SPRING_DATA_RELATIONAL}`,
`jhipster:${GENERATOR_SPRING_CACHE}`,
`jhipster:${GENERATOR_SPRING_WEBSOCKET}`,
];

export const shouldComposeWithLiquibase = (testSample, runResultSupplier) => {
const liquibaseEnabled = typeof testSample === 'boolean' ? testSample : testSample?.databaseType === SQL;
if (liquibaseEnabled) {
Expand Down Expand Up @@ -97,3 +56,14 @@ const shouldComposeWithDatabasetype = (databaseType: string, shouldCompose: bool

export const shouldComposeWithCouchbase = (shouldCompose: boolean, runResultSupplier) =>
shouldComposeWithDatabasetype(COUCHBASE, shouldCompose, runResultSupplier);

export const filterBasicServerGenerators = (ns: string) =>
!ns.startsWith(`jhipster:${GENERATOR_BOOTSTRAP}`) &&
![
`jhipster:${GENERATOR_PROJECT_NAME}`,
`jhipster:${GENERATOR_JAVA}`,
`jhipster:${GENERATOR_JAVA}:bootstrap`,
`jhipster:${GENERATOR_JAVA}:domain`,
`jhipster:${GENERATOR_SERVER}`,
`jhipster:${GENERATOR_SPRING_BOOT}`,
].includes(ns);
16 changes: 8 additions & 8 deletions generators/server/generator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { snakeCase } from 'lodash-es';
import { shouldSupportFeatures, testBlueprintSupport, checkEnforcements } from '../../test/support/index.js';
import { defaultHelpers as helpers, result as runResult } from '../../testing/index.js';
import { GENERATOR_SERVER, GENERATOR_SPRING_BOOT } from '../generator-list.js';
import { mockedGenerators, shouldComposeWithCouchbase, shouldComposeWithSpringCloudStream } from './__test-support/index.js';
import { filterBasicServerGenerators, shouldComposeWithCouchbase, shouldComposeWithSpringCloudStream } from './__test-support/index.js';
import Generator from './index.js';

const __filename = fileURLToPath(import.meta.url);
Expand Down Expand Up @@ -52,7 +52,7 @@ describe(`generator - ${generator}`, () => {
messageBroker: 'no',
})
.withSkipWritingPriorities()
.withMockedGenerators(mockedGenerators);
.withMockedJHipsterGenerators({ filter: filterBasicServerGenerators });
});

shouldComposeWithSpringCloudStream(false, () => runResult);
Expand All @@ -66,7 +66,7 @@ describe(`generator - ${generator}`, () => {
messageBroker: 'kafka',
})
.withSkipWritingPriorities()
.withMockedGenerators(mockedGenerators);
.withMockedJHipsterGenerators({ filter: filterBasicServerGenerators });
});
shouldComposeWithSpringCloudStream(true, () => runResult);
});
Expand All @@ -79,7 +79,7 @@ describe(`generator - ${generator}`, () => {
messageBroker: 'pulsar',
})
.withSkipWritingPriorities()
.withMockedGenerators(mockedGenerators);
.withMockedJHipsterGenerators({ filter: filterBasicServerGenerators });
});
shouldComposeWithSpringCloudStream(true, () => runResult);
});
Expand All @@ -94,7 +94,7 @@ describe(`generator - ${generator}`, () => {
databaseType: 'no',
authenticationType: 'jwt',
})
.withMockedGenerators(mockedGenerators);
.withMockedJHipsterGenerators({ filter: filterBasicServerGenerators });
});

it('should match generated files', () => {
Expand All @@ -111,7 +111,7 @@ describe(`generator - ${generator}`, () => {
databaseType: 'no',
authenticationType: 'session',
})
.withMockedGenerators(mockedGenerators);
.withMockedJHipsterGenerators({ filter: filterBasicServerGenerators });
});

it('should match generated files', () => {
Expand All @@ -128,7 +128,7 @@ describe(`generator - ${generator}`, () => {
databaseType: 'no',
authenticationType: 'oauth2',
})
.withMockedGenerators(mockedGenerators);
.withMockedJHipsterGenerators({ filter: filterBasicServerGenerators });
});

it('should match generated files', () => {
Expand All @@ -146,7 +146,7 @@ describe(`generator - ${generator}`, () => {
databaseType: 'couchbase',
})
.withSkipWritingPriorities()
.withMockedGenerators(mockedGenerators);
.withMockedJHipsterGenerators({ filter: filterBasicServerGenerators });
});
shouldComposeWithCouchbase(true, () => runResult);
});
Expand Down
6 changes: 0 additions & 6 deletions generators/spring-boot/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ exports[`generator - spring-boot with jwt should match generated files snapshot
"pom.xml": {
"stateCleared": "modified",
},
"src/main/docker/jib/entrypoint.sh": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/ApplicationWebXml.java": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -388,9 +385,6 @@ exports[`generator - spring-boot with oauth2 should match generated files snapsh
"pom.xml": {
"stateCleared": "modified",
},
"src/main/docker/jib/entrypoint.sh": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/ApplicationWebXml.java": {
"stateCleared": "modified",
},
Expand Down
12 changes: 9 additions & 3 deletions generators/spring-boot/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { defaultHelpers as helpers, runResult } from '../../testing/index.js';
import { shouldSupportFeatures, testBlueprintSupport, checkEnforcements } from '../../test/support/index.js';
import Generator from '../server/index.js';

import { mockedGenerators } from '../server/__test-support/index.js';
import { filterBasicServerGenerators } from '../server/__test-support/index.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
Expand All @@ -23,7 +23,10 @@ describe(`generator - ${generator}`, () => {

describe('with jwt', () => {
before(async () => {
await helpers.runJHipster(generator).withJHipsterConfig({ authenticationType: 'jwt' }).withMockedGenerators(mockedGenerators);
await helpers
.runJHipster(generator)
.withJHipsterConfig({ authenticationType: 'jwt' })
.withMockedJHipsterGenerators({ filter: filterBasicServerGenerators });
});

it('should match generated files snapshot', () => {
Expand All @@ -33,7 +36,10 @@ describe(`generator - ${generator}`, () => {

describe('with oauth2', () => {
before(async () => {
await helpers.runJHipster(generator).withJHipsterConfig({ authenticationType: 'oauth2' }).withMockedGenerators(mockedGenerators);
await helpers
.runJHipster(generator)
.withJHipsterConfig({ authenticationType: 'oauth2' })
.withMockedJHipsterGenerators({ filter: filterBasicServerGenerators });
});

it('should match generated files snapshot', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ exports[`generator - cassandra gateway-jwt-gradle-enableTranslation(true)-com.my
"settings.gradle": {
"stateCleared": "modified",
},
"src/main/docker/jib/entrypoint.sh": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/GeneratedByJHipster.java": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -493,9 +490,6 @@ exports[`generator - cassandra microservice-jwt-reactive(false)-maven-enableTran
"pom.xml": {
"stateCleared": "modified",
},
"src/main/docker/jib/entrypoint.sh": {
"stateCleared": "modified",
},
"src/main/java/tech/jhipster/ApplicationWebXml.java": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -837,9 +831,6 @@ exports[`generator - cassandra microservice-jwt-reactive(true)-gradle-enableTran
"settings.gradle": {
"stateCleared": "modified",
},
"src/main/docker/jib/entrypoint.sh": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/GeneratedByJHipster.java": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -1190,9 +1181,6 @@ exports[`generator - cassandra microservice-oauth2-reactive(true)-gradle-enableT
"settings.gradle": {
"stateCleared": "modified",
},
"src/main/docker/jib/entrypoint.sh": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/GeneratedByJHipster.java": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -1510,9 +1498,6 @@ exports[`generator - cassandra monolith-jwt-reactive(false)-maven-enableTranslat
"pom.xml": {
"stateCleared": "modified",
},
"src/main/docker/jib/entrypoint.sh": {
"stateCleared": "modified",
},
"src/main/java/tech/jhipster/ApplicationWebXml.java": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -1998,9 +1983,6 @@ exports[`generator - cassandra monolith-jwt-reactive(true)-gradle-enableTranslat
"settings.gradle": {
"stateCleared": "modified",
},
"src/main/docker/jib/entrypoint.sh": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/GeneratedByJHipster.java": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -2345,9 +2327,6 @@ exports[`generator - cassandra monolith-oauth2-reactive(false)-maven-enableTrans
"pom.xml": {
"stateCleared": "modified",
},
"src/main/docker/jib/entrypoint.sh": {
"stateCleared": "modified",
},
"src/main/java/tech/jhipster/ApplicationWebXml.java": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -2719,9 +2698,6 @@ exports[`generator - cassandra monolith-oauth2-reactive(true)-gradle-enableTrans
"settings.gradle": {
"stateCleared": "modified",
},
"src/main/docker/jib/entrypoint.sh": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/GeneratedByJHipster.java": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -3075,9 +3051,6 @@ exports[`generator - cassandra monolith-session-reactive(false)-maven-enableTran
"pom.xml": {
"stateCleared": "modified",
},
"src/main/docker/jib/entrypoint.sh": {
"stateCleared": "modified",
},
"src/main/java/tech/jhipster/ApplicationWebXml.java": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -3530,9 +3503,6 @@ exports[`generator - cassandra monolith-session-reactive(true)-gradle-enableTran
"settings.gradle": {
"stateCleared": "modified",
},
"src/main/docker/jib/entrypoint.sh": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/GeneratedByJHipster.java": {
"stateCleared": "modified",
},
Expand Down
Loading

0 comments on commit 4d5f944

Please sign in to comment.