diff --git a/lib/index.ts b/lib/index.ts index 418168e1581a..56f51a92c905 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -6,18 +6,17 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); export const isDistFolder = () => { - return basename(join(__dirname, '..')) === 'dist'; + return basename(dirname(__dirname)) === 'dist'; }; export const getPackageRoot = (relativePath?: string) => { - const sourceRoot = join(__dirname, '..'); - const packageDirectory = isDistFolder() ? join(sourceRoot, '..') : sourceRoot; + const sourceRoot = dirname(__dirname); + const packageDirectory = isDistFolder() ? dirname(sourceRoot) : sourceRoot; return relativePath ? join(packageDirectory, relativePath) : packageDirectory; }; -export const getGeneratorsParentPath = (relativePath?: string) => { - const sourceRoot = join(__dirname, '..'); - return relativePath ? join(sourceRoot, relativePath) : sourceRoot; +export const getSourceRoot = () => { + return dirname(__dirname); }; export const packageJson = JSON.parse(readFileSync(getPackageRoot('package.json')).toString()); diff --git a/lib/testing/__snapshots__/helpers.spec.ts.snap b/lib/testing/__snapshots__/helpers.spec.ts.snap index 5634e66167a6..eb662d922656 100644 --- a/lib/testing/__snapshots__/helpers.spec.ts.snap +++ b/lib/testing/__snapshots__/helpers.spec.ts.snap @@ -1,6 +1,168 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`helpers defaults should register jhipster generators namespaces 1`] = ` +exports[`helpers run using withJHipsterGenerators should register jhipster generators namespaces 1`] = ` +[ + "jhipster:angular", + "jhipster:app", + "jhipster:base", + "jhipster:base-application", + "jhipster:base-core", + "jhipster:base-entity-changes", + "jhipster:base-workspaces", + "jhipster:bootstrap", + "jhipster:bootstrap-application", + "jhipster:bootstrap-application-base", + "jhipster:bootstrap-application-client", + "jhipster:bootstrap-application-server", + "jhipster:bootstrap-workspaces", + "jhipster:ci-cd", + "jhipster:client", + "jhipster:client:common", + "jhipster:common", + "jhipster:cucumber", + "jhipster:cypress", + "jhipster:docker", + "jhipster:docker-compose", + "jhipster:entities", + "jhipster:entity", + "jhipster:export-jdl", + "jhipster:feign-client", + "jhipster:gatling", + "jhipster:generate-blueprint", + "jhipster:git", + "jhipster:gradle", + "jhipster:gradle:code-quality", + "jhipster:gradle:jib", + "jhipster:gradle:node-gradle", + "jhipster:heroku", + "jhipster:info", + "jhipster:init", + "jhipster:java", + "jhipster:java:bootstrap", + "jhipster:java:build-tool", + "jhipster:java:code-quality", + "jhipster:java:domain", + "jhipster:java:jib", + "jhipster:java:node", + "jhipster:java:openapi-generator", + "jhipster:javascript:bootstrap", + "jhipster:javascript:eslint", + "jhipster:javascript:husky", + "jhipster:javascript:prettier", + "jhipster:jdl", + "jhipster:kubernetes", + "jhipster:kubernetes-helm", + "jhipster:kubernetes-knative", + "jhipster:languages", + "jhipster:liquibase", + "jhipster:maven", + "jhipster:maven:code-quality", + "jhipster:maven:frontend-plugin", + "jhipster:maven:jib", + "jhipster:project-name", + "jhipster:react", + "jhipster:server", + "jhipster:spring-boot", + "jhipster:spring-cache", + "jhipster:spring-cloud-stream", + "jhipster:spring-cloud-stream:kafka", + "jhipster:spring-cloud-stream:pulsar", + "jhipster:spring-cloud:gateway", + "jhipster:spring-data-cassandra", + "jhipster:spring-data-couchbase", + "jhipster:spring-data-elasticsearch", + "jhipster:spring-data-mongodb", + "jhipster:spring-data-neo4j", + "jhipster:spring-data-relational", + "jhipster:spring-websocket", + "jhipster:upgrade", + "jhipster:vue", + "jhipster:workspaces", +] +`; + +exports[`helpers runJHipster defaults should register jhipster generators namespaces 1`] = ` +[ + "jhipster:angular", + "jhipster:app", + "jhipster:base", + "jhipster:base-application", + "jhipster:base-core", + "jhipster:base-entity-changes", + "jhipster:base-workspaces", + "jhipster:bootstrap", + "jhipster:bootstrap-application", + "jhipster:bootstrap-application-base", + "jhipster:bootstrap-application-client", + "jhipster:bootstrap-application-server", + "jhipster:bootstrap-workspaces", + "jhipster:ci-cd", + "jhipster:client", + "jhipster:client:common", + "jhipster:common", + "jhipster:cucumber", + "jhipster:cypress", + "jhipster:docker", + "jhipster:docker-compose", + "jhipster:entities", + "jhipster:entity", + "jhipster:export-jdl", + "jhipster:feign-client", + "jhipster:gatling", + "jhipster:generate-blueprint", + "jhipster:git", + "jhipster:gradle", + "jhipster:gradle:code-quality", + "jhipster:gradle:jib", + "jhipster:gradle:node-gradle", + "jhipster:heroku", + "jhipster:info", + "jhipster:init", + "jhipster:java", + "jhipster:java:bootstrap", + "jhipster:java:build-tool", + "jhipster:java:code-quality", + "jhipster:java:domain", + "jhipster:java:jib", + "jhipster:java:node", + "jhipster:java:openapi-generator", + "jhipster:javascript:bootstrap", + "jhipster:javascript:eslint", + "jhipster:javascript:husky", + "jhipster:javascript:prettier", + "jhipster:jdl", + "jhipster:kubernetes", + "jhipster:kubernetes-helm", + "jhipster:kubernetes-knative", + "jhipster:languages", + "jhipster:liquibase", + "jhipster:maven", + "jhipster:maven:code-quality", + "jhipster:maven:frontend-plugin", + "jhipster:maven:jib", + "jhipster:project-name", + "jhipster:react", + "jhipster:server", + "jhipster:spring-boot", + "jhipster:spring-cache", + "jhipster:spring-cloud-stream", + "jhipster:spring-cloud-stream:kafka", + "jhipster:spring-cloud-stream:pulsar", + "jhipster:spring-cloud:gateway", + "jhipster:spring-data-cassandra", + "jhipster:spring-data-couchbase", + "jhipster:spring-data-elasticsearch", + "jhipster:spring-data-mongodb", + "jhipster:spring-data-neo4j", + "jhipster:spring-data-relational", + "jhipster:spring-websocket", + "jhipster:upgrade", + "jhipster:vue", + "jhipster:workspaces", +] +`; + +exports[`helpers runJHipster with useDefaultMocks should register jhipster generators namespaces 1`] = ` [ "jhipster:angular", "jhipster:app", diff --git a/lib/testing/helpers.spec.ts b/lib/testing/helpers.spec.ts index 90d4244529c7..ac4a186f0895 100644 --- a/lib/testing/helpers.spec.ts +++ b/lib/testing/helpers.spec.ts @@ -4,7 +4,19 @@ import { defaultHelpers as helpers, runResult } from './helpers.js'; const DUMMY_NAMESPACE = 'dummy'; describe('helpers', () => { - describe('defaults', () => { + describe('run defaults', () => { + before(async () => { + await helpers.run(helpers.createDummyGenerator(), { namespace: DUMMY_NAMESPACE }); + }); + it('should register not jhipster generators namespaces', () => { + expect( + Object.keys(runResult.env.store._meta) + .filter(ns => ns !== DUMMY_NAMESPACE) + .sort(), + ).toHaveLength(0); + }); + }); + describe('runJHipster defaults', () => { before(async () => { await helpers.runJHipster('info'); }); @@ -16,4 +28,28 @@ describe('helpers', () => { ).toMatchSnapshot(); }); }); + describe('run using withJHipsterGenerators', () => { + before(async () => { + await helpers.run(helpers.createDummyGenerator(), { namespace: DUMMY_NAMESPACE }).withJHipsterGenerators(); + }); + it('should register jhipster generators namespaces', () => { + expect( + Object.keys(runResult.env.store._meta) + .filter(ns => ns !== DUMMY_NAMESPACE) + .sort(), + ).toMatchSnapshot(); + }); + }); + describe('runJHipster with useDefaultMocks', () => { + before(async () => { + await helpers.runJHipster('info', { useDefaultMocks: true }); + }); + it('should register jhipster generators namespaces', () => { + expect( + Object.keys(runResult.env.store._meta) + .filter(ns => ns !== DUMMY_NAMESPACE) + .sort(), + ).toMatchSnapshot(); + }); + }); }); diff --git a/lib/testing/helpers.ts b/lib/testing/helpers.ts index 4faf9b2ffc16..78564c7756ec 100644 --- a/lib/testing/helpers.ts +++ b/lib/testing/helpers.ts @@ -13,7 +13,7 @@ import { GENERATOR_WORKSPACES } from '../../generators/generator-list.js'; import { createJHipsterLogger, normalizePathEnd, parseCreationTimestamp } from '../../generators/base/support/index.js'; import BaseGenerator from '../../generators/base/index.js'; import type { JHipsterGeneratorOptions } from '../../generators/base/api.js'; -import { getPackageRoot, isDistFolder } from '../index.js'; +import { getSourceRoot, getPackageRoot, isDistFolder } from '../index.js'; import type CoreGenerator from '../../generators/base-core/generator.js'; import type { ApplicationConfiguration } from '../types/application/yo-rc.js'; import { getDefaultJDLApplicationConfig } from '../command/jdl.js'; @@ -66,7 +66,7 @@ const DEFAULT_TEST_SETTINGS = { forwardCwd: true }; const DEFAULT_TEST_OPTIONS = { skipInstall: true }; const DEFAULT_TEST_ENV_OPTIONS = { skipInstall: true, dryRun: false }; -const generatorsDir = join(getPackageRoot(), 'generators'); +const generatorsDir = join(getSourceRoot(), 'generators'); const allGenerators = [ ...globSync('*/index.{j,t}s', { cwd: generatorsDir, posix: true }).map(file => dirname(file)), ...globSync('*/generators/*/index.{j,t}s', { cwd: generatorsDir, posix: true }).map(file => dirname(file).replace('/generators/', ':')),