Skip to content

Commit

Permalink
Merge pull request #25702 from mshima/fs-extra
Browse files Browse the repository at this point in the history
drop fs-extra
  • Loading branch information
DanielFran authored Apr 1, 2024
2 parents 30448b4 + 6eb455c commit c85c141
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 80 deletions.
10 changes: 6 additions & 4 deletions generators/upgrade/upgrade.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import path, { dirname } from 'path';
import { fileURLToPath } from 'url';
import fse from 'fs-extra';
import { mkdirSync, writeFileSync } from 'fs';
import * as _ from 'lodash-es';
import { before, it, describe, expect } from 'esmocha';
import { execaCommandSync } from 'execa';
import { packageJson } from '../../lib/index.js';
import { GENERATOR_APP, GENERATOR_UPGRADE } from '../generator-list.js';
import { basicHelpers as helpers, getGenerator, result as runResult } from '../../testing/index.js';

const writeJsonSync = (file, content) => writeFileSync(file, JSON.stringify(content, null, 2));

const { escapeRegExp } = _;

const __filename = fileURLToPath(import.meta.url);
Expand Down Expand Up @@ -64,10 +66,10 @@ Initial version of upgradeTest generated by generator-jhipster@undefined"
version: blueprintVersion,
};
const fakeBlueprintModuleDir = path.join(dir, `node_modules/${blueprintName}`);
fse.ensureDirSync(path.join(fakeBlueprintModuleDir, 'generators', 'fake'));
fse.writeJsonSync(path.join(fakeBlueprintModuleDir, 'package.json'), packagejs);
mkdirSync(path.join(fakeBlueprintModuleDir, 'generators', 'fake'), { recursive: true });
writeJsonSync(path.join(fakeBlueprintModuleDir, 'package.json'), packagejs);
// Create an fake generator, otherwise env.lookup doesn't find it.
fse.writeFileSync(path.join(fakeBlueprintModuleDir, 'generators', 'fake', 'index.js'), '');
writeFileSync(path.join(fakeBlueprintModuleDir, 'generators', 'fake', 'index.js'), '');
return helpers
.create(path.join(__dirname, '../generators/app/index.js'), { tmpdir: false })
.withJHipsterConfig({
Expand Down
20 changes: 5 additions & 15 deletions jdl/jdl-importer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
/* eslint-disable no-new, no-unused-expressions */
import path, { dirname } from 'path';
import { fileURLToPath } from 'url';
import { before, it, describe, after, expect, expect as jestExpect } from 'esmocha';
import fse from 'fs-extra';
import { readFileSync, rmSync } from 'fs';
import { before, it, describe, after, expect as jestExpect } from 'esmocha';
import { expect } from 'chai';

import { applicationTypes, clientFrameworkTypes, databaseTypes } from './jhipster/index.js';
Expand Down Expand Up @@ -104,7 +104,7 @@ relationship OneToOne {
}
`,
{
application: JSON.parse(fse.readFileSync(path.join(__dirname, '__test-files__', 'jhipster_app', '.yo-rc.json'), 'utf-8')),
application: JSON.parse(readFileSync(path.join(__dirname, '__test-files__', 'jhipster_app', '.yo-rc.json'), 'utf-8')),
},
);
});
Expand Down Expand Up @@ -146,12 +146,6 @@ relationship OneToOne {
returned = importer.import();
});

after(() => {
APPLICATION_NAMES.forEach(applicationName => {
fse.removeSync(applicationName);
});
});

it('should return the import state', () => {
expect(returned.exportedEntities).to.have.lengthOf(1);
expect(returned.exportedApplications).to.have.lengthOf(2);
Expand Down Expand Up @@ -370,13 +364,13 @@ relationship OneToOne {
const importer = createImporterFromFiles([path.join(__dirname, '__test-files__', 'deployments.jdl')]);
importer.import();
DEPLOYMENT_NAMES.forEach(name => {
contents.push(JSON.parse(fse.readFileSync(path.join(name, '.yo-rc.json'), 'utf-8')));
contents.push(JSON.parse(readFileSync(path.join(name, '.yo-rc.json'), 'utf-8')));
});
});

after(() => {
DEPLOYMENT_NAMES.forEach(name => {
fse.removeSync(name);
rmSync(name, { recursive: true });
});
});

Expand Down Expand Up @@ -434,10 +428,6 @@ relationship ManyToMany {
});
});

after(() => {
fse.removeSync('.jhipster');
});

it('should not fail', () => {
expect(() => importer.import()).not.to.throw();
});
Expand Down
37 changes: 0 additions & 37 deletions package-lock.json

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

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@
"@types/chai": "4.3.11",
"@types/glob": "npm:noist@1.0.0",
"@types/minimatch": "npm:noist@1.0.0",
"@types/mocha": "10.0.6",
"@types/node": "20.11.25",
"@types/sinon-chai": "3.2.12",
"chai": "4.4.1",
Expand All @@ -188,7 +187,6 @@
"eslint-plugin-mocha": "10.4.1",
"eslint-plugin-prettier": "5.1.3",
"esmocha": "1.2.0",
"fs-extra": "11.2.0",
"jest-extended": "4.0.2",
"jsdoc": "4.0.2",
"octokit": "3.1.2",
Expand Down
30 changes: 16 additions & 14 deletions test/integration-test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@
*/
import { before, it, describe } from 'esmocha';
import assert from 'assert';
import fs from 'fs';
import fs, { existsSync, writeFileSync } from 'fs';
import path, { dirname } from 'path';
import { fileURLToPath } from 'url';
import fse from 'fs-extra';
import sortKeys from 'sort-keys';

import { applicationTypes, authenticationTypes } from '../jdl/jhipster/index.js';
import { formatDateForChangelog } from '../generators/base/support/index.js';

const writeJsonSync = (file, content) => writeFileSync(file, JSON.stringify(content, null, 2));
const readJsonSync = file => JSON.parse(fs.readFileSync(file, 'utf-8'));

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

Expand All @@ -46,13 +48,13 @@ const itSamplesEntries = fs
.filter(dirent => dirent.isDirectory())
.map(({ name }) => name)
.map(name => [name, path.join(itSamplesPath, name, '.yo-rc.json')])
.filter(([_name, yoFile]) => fs.existsSync(yoFile));
.filter(([_name, yoFile]) => existsSync(yoFile));
const dailyBuildEntries = fs
.readdirSync(dailyBuildsSamplesPath, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(({ name }) => name)
.map(name => [name, path.join(dailyBuildsSamplesPath, name, '.yo-rc.json')])
.filter(([_name, yoFile]) => fs.existsSync(yoFile));
.filter(([_name, yoFile]) => existsSync(yoFile));

const itEntitiesSamplesEntries = fs
.readdirSync(itEntitiesSamplesPath, { withFileTypes: true })
Expand All @@ -63,29 +65,29 @@ const itEntitiesSamplesEntries = fs
describe('integration-test', () => {
describe('::application samples', () => {
for (const [name, yoFile] of [...itSamplesEntries, ...dailyBuildEntries]) {
let yoJson = fse.readJsonSync(yoFile);
const writeConfig = () => fse.writeJsonSync(yoFile, yoJson);
let yoJson = readJsonSync(yoFile);
const writeConfig = () => writeJsonSync(yoFile, yoJson);
const config = yoJson['generator-jhipster'];
describe(`${name} test`, () => {
before(() => {
if (fixSamples) {
if (!config.creationTimestamp) {
config.creationTimestamp = 1596513172471;
fse.writeJsonSync(yoFile, yoJson);
writeJsonSync(yoFile, yoJson);
}
if (config.authenticationType === SESSION && config.rememberMeKey !== REMEMBER_ME_KEY) {
config.rememberMeKey = REMEMBER_ME_KEY;
fse.writeJsonSync(yoFile, yoJson);
writeJsonSync(yoFile, yoJson);
} else if (
(config.authenticationType === JWT || config.applicationType === MICROSERVICE || config.applicationType === GATEWAY) &&
config.jwtSecretKey !== JWT_SECRET_KEY
) {
config.jwtSecretKey = JWT_SECRET_KEY;
fse.writeJsonSync(yoFile, yoJson);
writeJsonSync(yoFile, yoJson);
}
const yoJsonOrdered = sortKeys(yoJson, { deep: true });
if (JSON.stringify(yoJson) !== JSON.stringify(yoJsonOrdered)) {
fse.writeJsonSync(yoFile, yoJsonOrdered);
writeJsonSync(yoFile, yoJsonOrdered);
yoJson = yoJsonOrdered;
}
}
Expand Down Expand Up @@ -157,12 +159,12 @@ describe('integration-test', () => {
describe('::entities samples reproducibility', () => {
const changelogDates = [];
for (const [name, entitySample] of itEntitiesSamplesEntries) {
let entityJson = fse.readJsonSync(entitySample);
let entityJson = readJsonSync(entitySample);
before(() => {
if (fixSamples) {
const entityJsonOrdered = sortKeys(entityJson, { deep: true });
if (JSON.stringify(entityJson) !== JSON.stringify(entityJsonOrdered)) {
fse.writeJsonSync(entitySample, entityJsonOrdered);
writeJsonSync(entitySample, entityJsonOrdered);
entityJson = entityJsonOrdered;
}
}
Expand All @@ -171,7 +173,7 @@ describe('integration-test', () => {
if (fixSamples) {
if (!entityJson.changelogDate) {
entityJson.changelogDate = formatDateForChangelog(new Date());
fse.writeJsonSync(entitySample, entityJson);
writeJsonSync(entitySample, entityJson);
}
}
assert(entityJson.changelogDate);
Expand All @@ -180,7 +182,7 @@ describe('integration-test', () => {
if (fixSamples) {
while (changelogDates.includes(entityJson.changelogDate)) {
entityJson.changelogDate = formatDateForChangelog(new Date());
fse.writeJsonSync(entitySample, entityJson);
writeJsonSync(entitySample, entityJson);
}
}
assert(!changelogDates.includes(entityJson.changelogDate));
Expand Down
15 changes: 7 additions & 8 deletions test/support/check-enforcements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@
* limitations under the License.
*/
import assert from 'assert';
import fs, { readFileSync } from 'fs';
import { opendirSync, readFileSync, writeFileSync } from 'fs';
import path, { basename } from 'path';
import fse from 'fs-extra';
import { describe, it, before } from 'mocha';
import { getGeneratorFolder } from '../../testing/get-generator.js';

const fixEnforcements = process.argv.includes('--fix-enforcements');

const readDir = dirPath => {
const files: string[] = [];
const dir = fs.opendirSync(dirPath);
const dir = opendirSync(dirPath);
let dirent = dir.readSync();
while (dirent !== null) {
const childPath = path.join(dirPath, dirent.name);
Expand All @@ -51,7 +50,7 @@ export default function checkEnforcements({ client }: { client?: boolean }, gene
describe(`file ${path.basename(file)}`, () => {
let content;
before(() => {
content = fse.readFileSync(file, 'utf-8');
content = readFileSync(file, 'utf-8');
});

[
Expand All @@ -70,12 +69,12 @@ export default function checkEnforcements({ client }: { client?: boolean }, gene
if (!fixEnforcements || !replacement) return;
if (file.endsWith('.ejs')) {
if (regexSeparator.test(content)) {
fse.writeFileSync(file, content.replace(regexSeparator, replacement));
content = fse.readFileSync(file, 'utf-8');
writeFileSync(file, content.replace(regexSeparator, replacement));
content = readFileSync(file, 'utf-8');
}
if (regex.test(content)) {
fse.writeFileSync(file, content.replace(regex, replacement));
content = fse.readFileSync(file, 'utf-8');
writeFileSync(file, content.replace(regex, replacement));
content = readFileSync(file, 'utf-8');
}
}
});
Expand Down

0 comments on commit c85c141

Please sign in to comment.