Skip to content

Commit

Permalink
testing: adjusts to helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Sep 27, 2024
1 parent 39fb346 commit 9dbdfa3
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 10 deletions.
11 changes: 5 additions & 6 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
164 changes: 163 additions & 1 deletion lib/testing/__snapshots__/helpers.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
38 changes: 37 additions & 1 deletion lib/testing/helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand All @@ -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();
});
});
});
4 changes: 2 additions & 2 deletions lib/testing/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Check failure on line 16 in lib/testing/helpers.ts

View workflow job for this annotation

GitHub Actions / check-npm-test

Member 'getPackageRoot' of the import declaration should be sorted alphabetically
import type CoreGenerator from '../../generators/base-core/generator.js';
import type { ApplicationConfiguration } from '../types/application/yo-rc.js';
import { getDefaultJDLApplicationConfig } from '../command/jdl.js';
Expand Down Expand Up @@ -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/', ':')),
Expand Down

0 comments on commit 9dbdfa3

Please sign in to comment.