Skip to content

Commit

Permalink
Merge pull request #24579 from mshima/node-20
Browse files Browse the repository at this point in the history
[internal] Use the quibble for dependency mock in tests
  • Loading branch information
DanielFran authored Dec 16, 2023
2 parents fa95fc2 + 4aa8639 commit ff4449c
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/actions/build-matrix/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ outputs:
runs:
using: 'composite'
steps:
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 18
node-version: 18.19.0
- name: 'Check changes'
id: build-changes
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/setup-default-node-java/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ runs:
steps:
- uses: actions/setup-node@v4
with:
node-version: 18
node-version: 18.19.0
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18.18.2
node-version: 18.19.0
- name: 'SETUP: load npm cache'
uses: actions/cache/restore@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lock-maintenance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
steps:
- uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
- run: npm install -g npm@latest
- uses: actions/checkout@v4
- uses: jhipster/actions/restore-cache@v0
Expand Down
8 changes: 8 additions & 0 deletions .mocharc.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
const Module = require('module');
const process = require('process');

if (!Module.register) {
console.log('JHipster test requires node >=18.19.0 || >= 20.6.0\n');
process.exit(1);
}

module.exports = {
recursive: true,
reporter: 'spec',
Expand Down
35 changes: 22 additions & 13 deletions cli/cli.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,16 @@ import assert from 'assert';
import { fork } from 'child_process';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
import { before, it, describe, expect, mock, resetAllMocks, esmocha } from 'esmocha';
import { after, before, it, describe, expect, resetAllMocks, esmocha } from 'esmocha';
import { execaCommandSync } from 'execa';
import { BaseEnvironment } from '@yeoman/types';
import { coerce } from 'semver';
import { defaultHelpers as helpers, createBlueprintFiles } from '../test/support/index.js';
import quibble from 'quibble';

import { defaultHelpers as helpers, createBlueprintFiles } from '../test/support/index.js';
import { getCommand as actualGetCommonand } from './utils.mjs';
import { createProgram } from './program.mjs';

const { logger, getCommand } = await mock<typeof import('./utils.mjs')>('./utils.mjs');
const { buildJHipster } = await import('./program.mjs');

const __filename = fileURLToPath(import.meta.url);
const jhipsterCli = join(dirname(__filename), '..', 'bin', 'jhipster.cjs');

const mockCli = async (argv: string[], opts = {}) => {
const program = await buildJHipster({ printLogo: () => {}, ...opts, program: createProgram(), loadCommand: key => opts[`./${key}`] });
return program.parseAsync(argv);
};

const cliBlueprintFiles = {
'cli/commands.js': `export default {
foo: {
Expand Down Expand Up @@ -97,7 +87,26 @@ const cliSharedBlueprintFiles = {
};

describe('cli', () => {
const __filename = fileURLToPath(import.meta.url);
const jhipsterCli = join(dirname(__filename), '..', 'bin', 'jhipster.cjs');
const logger = { verboseInfo: esmocha.fn(), fatal: esmocha.fn(), debug: esmocha.fn() };
const getCommand = esmocha.fn();
let mockCli;
let argv;

before(async () => {
await quibble.esm('./utils.mjs', { logger, getCommand, CLI_NAME: 'jhipster', done: () => {} });
const { buildJHipster } = await import('./program.mjs');

mockCli = async (argv: string[], opts = {}) => {
const program = await buildJHipster({ printLogo: () => {}, ...opts, program: createProgram(), loadCommand: key => opts[`./${key}`] });
return program.parseAsync(argv);
};
});
after(() => {
quibble.reset();
});

beforeEach(async () => {
await helpers.prepareTemporaryDir();
});
Expand Down
12 changes: 10 additions & 2 deletions generators/java/support/checks/check-java.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { before, it, describe, expect, mock, resetAllMocks } from 'esmocha';
import { after, before, it, describe, expect, resetAllMocks, esmocha } from 'esmocha';
import { ExecaSyncReturnValue } from 'execa';
import quibble from 'quibble';

const execa = await mock<typeof import('execa')>('execa');
const execa = { execa: esmocha.fn(), execaSync: esmocha.fn(), execaCommandSync: esmocha.fn(), execaCommand: esmocha.fn() };

const baseResult: ExecaSyncReturnValue<string> = {
command: 'java',
Expand All @@ -15,6 +16,13 @@ const baseResult: ExecaSyncReturnValue<string> = {
};

describe('generator - server - checkJava', () => {
before(async () => {
await quibble.esm('execa', execa);
});
after(() => {
quibble.reset();
});

afterEach(() => {
resetAllMocks();
});
Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
"octokit": "3.1.2",
"open-cli": "7.2.0",
"prettier2": "npm:[email protected]",
"quibble": "0.9.1",
"rimraf": "5.0.5",
"sinon": "17.0.1",
"sinon-chai": "3.7.0",
Expand Down

0 comments on commit ff4449c

Please sign in to comment.