Skip to content

Commit

Permalink
tests: switch to JHipster helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Sep 26, 2024
1 parent 60a24d2 commit 7400dcb
Show file tree
Hide file tree
Showing 12 changed files with 280 additions and 380 deletions.
239 changes: 97 additions & 142 deletions generators/docker-compose/docker-compose.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { before, describe, expect, it } from 'esmocha';
import monitoringTypes from '../../lib/jhipster/monitoring-types.js';
import applicationTypes from '../../lib/jhipster/application-types.js';
import { GENERATOR_DOCKER_COMPOSE } from '../generator-list.js';
import { getGenerator, defaultHelpers as helpers, runResult } from '../../lib/testing/index.js';
import { defaultHelpers as helpers, runResult } from '../../lib/testing/index.js';

const { PROMETHEUS } = monitoringTypes;
const { MICROSERVICE, MONOLITH } = applicationTypes;
Expand All @@ -24,16 +24,13 @@ describe('generator - Docker Compose', () => {
.withWorkspacesSamples(...chosenApps)
.withGenerateWorkspaceApplications();

await runResult
.create(getGenerator(GENERATOR_DOCKER_COMPOSE))
.withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
monitoring: NO_MONITORING,
})
.run();
await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
monitoring: NO_MONITORING,
});
});
it('should match files snapshot', function () {
expect(runResult.getSnapshot()).toMatchSnapshot();
Expand All @@ -59,16 +56,13 @@ describe('generator - Docker Compose', () => {
.withWorkspacesSamples(...chosenApps)
.withGenerateWorkspaceApplications();

await runResult
.create(getGenerator(GENERATOR_DOCKER_COMPOSE))
.withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
monitoring: NO_MONITORING,
})
.run();
await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
monitoring: NO_MONITORING,
});
});
it('should match files snapshot', function () {
expect(runResult.getSnapshot()).toMatchSnapshot();
Expand All @@ -94,16 +88,13 @@ describe('generator - Docker Compose', () => {
.withWorkspacesSamples(...chosenApps)
.withGenerateWorkspaceApplications();

await runResult
.create(getGenerator(GENERATOR_DOCKER_COMPOSE))
.withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: '.',
appsFolders: chosenApps,
clusteredDbApps: [],
monitoring: NO_MONITORING,
})
.run();
await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: '.',
appsFolders: chosenApps,
clusteredDbApps: [],
monitoring: NO_MONITORING,
});
});
it('should match files snapshot', function () {
expect(runResult.getSnapshot()).toMatchSnapshot();
Expand All @@ -124,16 +115,13 @@ describe('generator - Docker Compose', () => {
.withWorkspacesSamples(...chosenApps)
.withGenerateWorkspaceApplications();

await runResult
.create(getGenerator(GENERATOR_DOCKER_COMPOSE))
.withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
monitoring: NO_MONITORING,
})
.run();
await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
monitoring: NO_MONITORING,
});
});
it('should match files snapshot', function () {
expect(runResult.getSnapshot()).toMatchSnapshot();
Expand All @@ -159,15 +147,12 @@ describe('generator - Docker Compose', () => {
.withWorkspacesSamples(...chosenApps)
.withGenerateWorkspaceApplications();

await runResult
.create(getGenerator(GENERATOR_DOCKER_COMPOSE))
.withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
})
.run();
await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
});
});
it('should match files snapshot', function () {
expect(runResult.getSnapshot()).toMatchSnapshot();
Expand Down Expand Up @@ -196,15 +181,12 @@ describe('generator - Docker Compose', () => {
.withWorkspacesSamples(...chosenApps)
.withGenerateWorkspaceApplications();

await runResult
.create(getGenerator(GENERATOR_DOCKER_COMPOSE))
.withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
})
.run();
await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
});
});
it('should match files snapshot', function () {
expect(runResult.getSnapshot()).toMatchSnapshot();
Expand Down Expand Up @@ -233,16 +215,13 @@ describe('generator - Docker Compose', () => {
.withWorkspacesSamples(...chosenApps)
.withGenerateWorkspaceApplications();

await runResult
.create(getGenerator(GENERATOR_DOCKER_COMPOSE))
.withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
monitoring: PROMETHEUS,
})
.run();
await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
monitoring: PROMETHEUS,
});
});
it('should match files snapshot', function () {
expect(runResult.getSnapshot()).toMatchSnapshot();
Expand Down Expand Up @@ -271,15 +250,12 @@ describe('generator - Docker Compose', () => {
.withWorkspacesSamples(...chosenApps)
.withGenerateWorkspaceApplications();

await runResult
.create(getGenerator(GENERATOR_DOCKER_COMPOSE))
.withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
})
.run();
await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
});
});
it('should match files snapshot', function () {
expect(runResult.getSnapshot()).toMatchSnapshot();
Expand All @@ -305,15 +281,12 @@ describe('generator - Docker Compose', () => {
.withWorkspacesSamples(...chosenApps)
.withGenerateWorkspaceApplications();

await runResult
.create(getGenerator(GENERATOR_DOCKER_COMPOSE))
.withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: ['04-mongo'],
})
.run();
await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: ['04-mongo'],
});
});
it('should match files snapshot', function () {
expect(runResult.getSnapshot()).toMatchSnapshot();
Expand All @@ -339,15 +312,12 @@ describe('generator - Docker Compose', () => {
.withWorkspacesSamples(...chosenApps)
.withGenerateWorkspaceApplications();

await runResult
.create(getGenerator(GENERATOR_DOCKER_COMPOSE))
.withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
})
.run();
await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
});
});
it('should match files snapshot', function () {
expect(runResult.getSnapshot()).toMatchSnapshot();
Expand All @@ -373,15 +343,12 @@ describe('generator - Docker Compose', () => {
.withWorkspacesSamples(...chosenApps)
.withGenerateWorkspaceApplications();

await runResult
.create(getGenerator(GENERATOR_DOCKER_COMPOSE))
.withAnswers({
deploymentApplicationType: MONOLITH,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
})
.run();
await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({
deploymentApplicationType: MONOLITH,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
});
});
it('should match files snapshot', function () {
expect(runResult.getSnapshot()).toMatchSnapshot();
Expand All @@ -404,15 +371,12 @@ describe('generator - Docker Compose', () => {
.withWorkspacesSamples(...chosenApps)
.withGenerateWorkspaceApplications();

await runResult
.create(getGenerator(GENERATOR_DOCKER_COMPOSE))
.withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
})
.run();
await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
});
});
it('should match files snapshot', function () {
expect(runResult.getSnapshot()).toMatchSnapshot({
Expand Down Expand Up @@ -443,15 +407,12 @@ describe('generator - Docker Compose', () => {
.withWorkspacesSamples(...chosenApps)
.withGenerateWorkspaceApplications();

await runResult
.create(getGenerator(GENERATOR_DOCKER_COMPOSE))
.withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
})
.run();
await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
});
});
it('should match files snapshot', function () {
expect(runResult.getSnapshot()).toMatchSnapshot();
Expand All @@ -477,15 +438,12 @@ describe('generator - Docker Compose', () => {
.withWorkspacesSamples(...chosenApps)
.withGenerateWorkspaceApplications();

await runResult
.create(getGenerator(GENERATOR_DOCKER_COMPOSE))
.withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: ['10-couchbase'],
})
.run();
await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({
deploymentApplicationType: MICROSERVICE,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: ['10-couchbase'],
});
});
it('should match files snapshot', function () {
expect(runResult.getSnapshot()).toMatchSnapshot();
Expand All @@ -511,16 +469,13 @@ describe('generator - Docker Compose', () => {
.withWorkspacesSamples(...chosenApps)
.withGenerateWorkspaceApplications();

await runResult
.create(getGenerator(GENERATOR_DOCKER_COMPOSE))
.withAnswers({
deploymentApplicationType: MONOLITH,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
monitoring: NO_MONITORING,
})
.run();
await helpers.runJHipsterInApplication(GENERATOR_DOCKER_COMPOSE).withAnswers({
deploymentApplicationType: MONOLITH,
directoryPath: './',
appsFolders: chosenApps,
clusteredDbApps: [],
monitoring: NO_MONITORING,
});
});
it('should match files snapshot', function () {
expect(runResult.getSnapshot()).toMatchSnapshot();
Expand Down
7 changes: 3 additions & 4 deletions generators/git/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, resolve } from 'path';
import { basename, dirname, resolve } from 'path';
import { fileURLToPath } from 'url';
import { access } from 'fs/promises';
import { before, describe, expect, it } from 'esmocha';
Expand All @@ -28,7 +28,6 @@ const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const generator = basename(__dirname);
const generatorPath = join(__dirname, 'index.ts');

describe(`generator - ${generator}`, () => {
it('generator-list constant matches folder name', () => {
Expand Down Expand Up @@ -72,7 +71,7 @@ describe(`generator - ${generator}`, () => {
describe('regenerating', () => {
before(async () => {
await helpers.runJHipster(generator).withOptions({ skipGit: false });
await runResult.create(generatorPath).withOptions({ skipGit: false, baseName: 'changed' }).run();
await helpers.runJHipsterInApplication(generator).withOptions({ skipGit: false, baseName: 'changed' });
});
it('should create a single commit', async () => {
const git = runResult.generator.createGit();
Expand All @@ -82,7 +81,7 @@ describe(`generator - ${generator}`, () => {
describe('regenerating with --force-git', () => {
before(async () => {
await helpers.runJHipster(generator).withOptions({ skipGit: false });
await runResult.create(generatorPath).withOptions({ skipGit: false, forceGit: true, baseName: 'changed' }).run();
await helpers.runJHipsterInApplication(generator).withOptions({ skipGit: false, forceGit: true, baseName: 'changed' });
});
it('should create 2 commits', async () => {
const git = runResult.generator.createGit();
Expand Down
Loading

0 comments on commit 7400dcb

Please sign in to comment.