Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update yeoman-test to v9. #27247

Merged
merged 8 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .mocharc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ module.exports = {
// `loader` options is passed to forks, but `require` is not.
// Use node-option instead (it overrides loader option)
parallel: true,
require: ['yeoman-test/mocha-cleanup'],
};
68 changes: 23 additions & 45 deletions generators/app/composing.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from 'assert';
import { before, describe, it } from 'esmocha';

import { defaultHelpers as helpers } from '../../lib/testing/index.js';
Expand All @@ -25,35 +24,28 @@ describe('generator - app - composing', () => {
});

it('should compose with bootstrap generator', () => {
assert(runResult.mockedGenerators['jhipster:bootstrap'].called);
runResult.assertGeneratorComposed('jhipster:bootstrap');
});
it('should compose with common generator', () => {
const CommonGenerator = runResult.mockedGenerators['jhipster:common'];
assert(CommonGenerator.calledOnce);
runResult.assertGeneratorComposedOnce('jhipster:common');
});
it('should compose with server generator', () => {
const ServerGenerator = runResult.mockedGenerators['jhipster:server'];
assert(ServerGenerator.calledOnce);
runResult.assertGeneratorComposedOnce('jhipster:server');
});
it('should compose with client generator', () => {
const ClientGenerator = runResult.mockedGenerators['jhipster:client'];
assert(ClientGenerator.calledOnce);
runResult.assertGeneratorComposedOnce('jhipster:client');
});
it('should not compose with languages generator', () => {
const LanguagesGenerator = runResult.mockedGenerators['jhipster:languages'];
assert.equal(LanguagesGenerator.callCount, 0);
runResult.assertGeneratorNotComposed('jhipster:languages');
});
it('should not compose with entities generator', () => {
const MockedGenerator = runResult.mockedGenerators['jhipster:entities'];
assert.equal(MockedGenerator.callCount, 0);
runResult.assertGeneratorNotComposed('jhipster:entities');
});
it('should not compose with entity generator', () => {
const MockedGenerator = runResult.mockedGenerators['jhipster:entity'];
assert.equal(MockedGenerator.callCount, 0);
runResult.assertGeneratorNotComposed('jhipster:entity');
});
it('should not compose with database-changelog generator', () => {
const MockedGenerator = runResult.mockedGenerators['jhipster:database-changelog'];
assert.equal(MockedGenerator.callCount, 0);
runResult.assertGeneratorNotComposed('jhipster:database-changelog');
});
});

Expand All @@ -69,36 +61,28 @@ describe('generator - app - composing', () => {
});

it('should compose with bootstrap generator', () => {
const BootstrapGenerator = runResult.mockedGenerators['jhipster:bootstrap'];
assert(BootstrapGenerator.called);
runResult.assertGeneratorComposed('jhipster:bootstrap');
});
it('should compose with common generator', () => {
const CommonGenerator = runResult.mockedGenerators['jhipster:common'];
assert(CommonGenerator.calledOnce);
runResult.assertGeneratorComposedOnce('jhipster:common');
});
it('should compose with server generator', () => {
const ServerGenerator = runResult.mockedGenerators['jhipster:server'];
assert(ServerGenerator.calledOnce);
runResult.assertGeneratorComposedOnce('jhipster:server');
});
it('should not compose with client generator', () => {
const ClientGenerator = runResult.mockedGenerators['jhipster:client'];
assert.equal(ClientGenerator.callCount, 0);
runResult.assertGeneratorNotComposed('jhipster:client');
});
it('should not compose with languages generator', () => {
const LanguagesGenerator = runResult.mockedGenerators['jhipster:languages'];
assert.equal(LanguagesGenerator.callCount, 0);
runResult.assertGeneratorNotComposed('jhipster:languages');
});
it('should not compose with entities generator', () => {
const MockedGenerator = runResult.mockedGenerators['jhipster:entities'];
assert.equal(MockedGenerator.callCount, 0);
runResult.assertGeneratorNotComposed('jhipster:entities');
});
it('should not compose with entity generator', () => {
const MockedGenerator = runResult.mockedGenerators['jhipster:entity'];
assert.equal(MockedGenerator.callCount, 0);
runResult.assertGeneratorNotComposed('jhipster:entity');
});
it('should not compose with database-changelog generator', () => {
const MockedGenerator = runResult.mockedGenerators['jhipster:database-changelog'];
assert.equal(MockedGenerator.callCount, 0);
runResult.assertGeneratorNotComposed('jhipster:database-changelog');
});
});

Expand All @@ -114,31 +98,25 @@ describe('generator - app - composing', () => {
});

it('should compose with bootstrap generator', () => {
assert(runResult.mockedGenerators['jhipster:bootstrap'].called);
runResult.assertGeneratorComposed('jhipster:bootstrap');
});
it('should compose with common generator', () => {
const CommonGenerator = runResult.mockedGenerators['jhipster:common'];
assert(CommonGenerator.calledOnce);
runResult.assertGeneratorComposedOnce('jhipster:common');
});
it('should not compose with server generator', () => {
const ServerGenerator = runResult.mockedGenerators['jhipster:server'];
assert(ServerGenerator.callCount === 0);
runResult.assertGeneratorNotComposed('jhipster:server');
});
it('should compose with client generator', () => {
const ClientGenerator = runResult.mockedGenerators['jhipster:client'];
assert(ClientGenerator.calledOnce);
runResult.assertGeneratorComposedOnce('jhipster:client');
});
it('should not compose with entities generator', () => {
const EntityGenerator = runResult.mockedGenerators['jhipster:entities'];
assert.equal(EntityGenerator.callCount, 0);
runResult.assertGeneratorNotComposed('jhipster:entities');
});
it('should not compose with entity generator', () => {
const MockedGenerator = runResult.mockedGenerators['jhipster:entity'];
assert.equal(MockedGenerator.callCount, 0);
runResult.assertGeneratorNotComposed('jhipster:entity');
});
it('should not compose with database-changelog generator', () => {
const MockedGenerator = runResult.mockedGenerators['jhipster:database-changelog'];
assert.equal(MockedGenerator.callCount, 0);
runResult.assertGeneratorNotComposed('jhipster:database-changelog');
});
});
});
Expand Down
10 changes: 5 additions & 5 deletions generators/base/blueprints.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('generator - base - with blueprint', () => {
});

it('creates expected default files for server and angular', () => {
expect(runResult.mockedGenerators['jhipster-myblueprint:test-blueprint'].called);
runResult.assertGeneratorComposed('jhipster-myblueprint:test-blueprint');
});

it('blueprint version is saved in .yo-rc.json', () => {
Expand Down Expand Up @@ -202,7 +202,7 @@ describe('generator - base - with scoped blueprint', () => {
});

it('should compose with blueprint', () => {
expect(runResult.mockedGenerators['@jhipster/jhipster-scoped-blueprint:test-blueprint'].called).toBe(true);
runResult.assertGeneratorComposed('@jhipster/jhipster-scoped-blueprint:test-blueprint');
});

it('blueprint version is saved in .yo-rc.json', () => {
Expand All @@ -229,7 +229,7 @@ describe('generator - base - with blueprints disabled', () => {
});

it('should compose with blueprint', () => {
expect(runResult.mockedGenerators['@jhipster/jhipster-scoped-blueprint:test-blueprint'].called).toBeFalsy;
runResult.assertGeneratorNotComposed('@jhipster/jhipster-scoped-blueprint:test-blueprint');
});
});
});
Expand Down Expand Up @@ -271,8 +271,8 @@ describe('generator - base - with multiple blueprints', () => {
});
});
it('should compose with blueprints once', () => {
expect(runResult.mockedGenerators['jhipster-blueprint1:test-blueprint'].calledOnce);
expect(runResult.mockedGenerators['jhipster-blueprint2:test-blueprint'].calledOnce);
runResult.assertGeneratorComposedOnce('jhipster-blueprint1:test-blueprint');
runResult.assertGeneratorComposedOnce('jhipster-blueprint2:test-blueprint');
});
});
});
Expand Down
33 changes: 16 additions & 17 deletions generators/client/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
import { basename, dirname, join } from 'path';
import { fileURLToPath } from 'url';
import assert from 'assert';
import { snakeCase } from 'lodash-es';
import { before, describe, expect, it } from 'esmocha';
import { checkEnforcements, shouldSupportFeatures, testBlueprintSupport } from '../../test/support/index.js';
Expand Down Expand Up @@ -59,10 +58,10 @@ describe(`generator - ${generator}`, () => {
});

it('should compose with jhipster:common', () => {
assert(runResult.mockedGenerators['jhipster:common'].calledOnce);
runResult.assertGeneratorComposedOnce('jhipster:common');
});
it('should compose with jhipster:languages', () => {
assert.equal(runResult.mockedGenerators['jhipster:languages'].callCount, 1);
runResult.assertGeneratorComposedOnce('jhipster:languages');
});
});

Expand All @@ -79,10 +78,10 @@ describe(`generator - ${generator}`, () => {
});

it('should compose with jhipster:common', () => {
assert(runResult.mockedGenerators['jhipster:common'].calledOnce);
runResult.assertGeneratorComposedOnce('jhipster:common');
});
it('should compose with jhipster:languages', () => {
assert.equal(runResult.mockedGenerators['jhipster:languages'].callCount, 1);
runResult.assertGeneratorComposedOnce('jhipster:languages');
});
});

Expand All @@ -99,13 +98,13 @@ describe(`generator - ${generator}`, () => {
});

it('should compose with jhipster:common', () => {
assert(runResult.mockedGenerators['jhipster:common'].calledOnce);
runResult.assertGeneratorComposedOnce('jhipster:common');
});
it('should compose with jhipster:languages', () => {
assert(runResult.mockedGenerators['jhipster:languages'].calledOnce);
runResult.assertGeneratorComposedOnce('jhipster:languages');
});
it('should not compose with jhipster:cypress', () => {
assert.equal(runResult.mockedGenerators['jhipster:cypress'].callCount, 0);
runResult.assertGeneratorNotComposed('jhipster:cypress');
});
});

Expand All @@ -122,13 +121,13 @@ describe(`generator - ${generator}`, () => {
});

it('should compose with jhipster:common', () => {
assert(runResult.mockedGenerators['jhipster:common'].calledOnce);
runResult.assertGeneratorComposedOnce('jhipster:common');
});
it('should compose with jhipster:languages', () => {
assert(runResult.mockedGenerators['jhipster:languages'].calledOnce);
runResult.assertGeneratorComposedOnce('jhipster:languages');
});
it('should compose with jhipster:cypress', () => {
assert(runResult.mockedGenerators['jhipster:cypress'].calledOnce);
runResult.assertGeneratorComposedOnce('jhipster:cypress');
});
});
});
Expand All @@ -152,22 +151,22 @@ describe(`generator - ${generator}`, () => {
});

it('should compose with jhipster:common', () => {
assert(result.mockedGenerators['jhipster:common'].calledOnce);
result.assertGeneratorComposedOnce('jhipster:common');
});
it('should compose with jhipster:languages', () => {
assert(result.mockedGenerators['jhipster:languages'].notCalled);
result.assertGeneratorNotComposed('jhipster:languages');
});
it('should compose with jhipster:cypress', () => {
assert(result.mockedGenerators['jhipster:cypress'].notCalled);
result.assertGeneratorNotComposed('jhipster:cypress');
});
it('should compose with jhipster:angular', () => {
assert(result.mockedGenerators['jhipster:angular'].notCalled);
result.assertGeneratorNotComposed('jhipster:angular');
});
it('should compose with jhipster:react', () => {
assert(result.mockedGenerators['jhipster:react'].notCalled);
result.assertGeneratorNotComposed('jhipster:react');
});
it('should compose with jhipster:vue', () => {
assert(result.mockedGenerators['jhipster:vue'].notCalled);
result.assertGeneratorNotComposed('jhipster:vue');
});
});
});
7 changes: 6 additions & 1 deletion generators/client/generators/common/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ describe(`generator - ${generator}`, () => {
});

it('should compose with generators', () => {
expect(result.composedMockedGenerators).toMatchInlineSnapshot('[]');
expect(result.getComposedGenerators()).toMatchInlineSnapshot(`
[
"jhipster:bootstrap",
"jhipster:project-name",
]
`);
});
});
});
4 changes: 1 addition & 3 deletions generators/cypress/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import path, { basename, dirname } from 'path';
import { fileURLToPath } from 'url';
import { after, before, describe, expect, it } from 'esmocha';
import { before, describe, expect, it } from 'esmocha';
import { snakeCase } from 'lodash-es';
import { clientFrameworkTypes, testFrameworkTypes } from '../../lib/jhipster/index.js';
import { AuthenticationTypeMatrix, extendMatrix, fromMatrix, defaultHelpers as helpers } from '../../lib/testing/index.js';
Expand Down Expand Up @@ -85,8 +85,6 @@ describe(`generator - ${generator}`, () => {
runResult = await helpers.run(generatorPath).withJHipsterConfig(sampleConfig, entities);
});

after(() => runResult.cleanup());

it('should match generated files snapshot', () => {
expect(runResult.getStateSnapshot()).toMatchSnapshot();
});
Expand Down
4 changes: 1 addition & 3 deletions generators/entity/single-entity.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { after, before, describe, expect, it } from 'esmocha';
import { before, describe, expect, it } from 'esmocha';
import { skipPrettierHelpers as helpers, result as runResult } from '../../lib/testing/index.js';
import { CLIENT_MAIN_SRC_DIR, SERVER_MAIN_RES_DIR, SERVER_MAIN_SRC_DIR } from '../generator-constants.js';
import BaseApplicationGenerator from '../base-application/generator.js';
Expand Down Expand Up @@ -62,8 +62,6 @@ describe('generator - entity --single-entity', () => {
.withOptions({ ignoreNeedlesError: true, regenerate: true, force: true, singleEntity: true });
});

after(() => runResult.cleanup());

it('should create files for entity Foo', () => {
runResult.assertFile([
`${SERVER_MAIN_RES_DIR}config/cql/changelog/20160926101210_added_entity_Foo.cql`,
Expand Down
8 changes: 4 additions & 4 deletions generators/generate-blueprint/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe(`generator - ${generator}`, () => {
await helpers.run(generatorPath).withJHipsterConfig().withMockedGenerators(mockedGenerators);
});
it('should compose with init generator', () => {
expect(runResult.mockedGenerators['jhipster:init'].calledOnce).toBe(true);
runResult.assertGeneratorComposedOnce('jhipster:init');
});
it('should write files and match snapshot', () => {
expect(runResult.getStateSnapshot()).toMatchSnapshot();
Expand All @@ -58,7 +58,7 @@ describe(`generator - ${generator}`, () => {
await helpers.run(generatorPath).withOptions({ allGenerators: true }).withMockedGenerators(mockedGenerators);
});
it('should compose with init generator', () => {
expect(runResult.mockedGenerators['jhipster:init'].calledOnce).toBe(true);
runResult.assertGeneratorComposedOnce('jhipster:init');
});
it('should match snapshot', () => {
expect(runResult.getStateSnapshot()).toMatchSnapshot();
Expand All @@ -70,7 +70,7 @@ describe(`generator - ${generator}`, () => {
runResult = await helpers.run(generatorPath).withOptions({ localBlueprint: true }).withMockedGenerators(mockedGenerators);
});
it('should not compose with init generator', () => {
expect(runResult.mockedGenerators['jhipster:init'].calledOnce).toBe(false);
runResult.assertGeneratorNotComposed('jhipster:init');
});
it('should match snapshot', () => {
expect(runResult.getStateSnapshot()).toMatchInlineSnapshot(`
Expand All @@ -91,7 +91,7 @@ describe(`generator - ${generator}`, () => {
.withMockedGenerators(mockedGenerators);
});
it('should not compose with init generator', () => {
expect(runResult.mockedGenerators['jhipster:init'].calledOnce).toBe(false);
runResult.assertGeneratorNotComposed('jhipster:init');
});
it('should write java files with gradle build tool and match snapshot', () => {
expect(runResult.getStateSnapshot()).toMatchInlineSnapshot(`
Expand Down
Loading
Loading