Merge branch 'main' into patch-1

This commit is contained in:
Iago Calazans 2022-09-28 11:34:48 -03:00 committed by GitHub
commit 01eed9f00c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -10,6 +10,12 @@ jest.mock('@strapi/typescript-utils', () => ({
}));
describe('getCustomAppConfigFile', () => {
test('It should return undefined when the src/admin does no exist', async () => {
const result = await getCustomAppConfigFile('/');
expect(result).toBeUndefined();
});
test('It should return undefined when the app config file extension is not .js and useTypeScript is falsy', async () => {
fse.readdir = jest.fn(() => {
return ['app.example.js', 'webpack.config.js', 'app.ts', 'app.tsx'];
@ -23,6 +29,10 @@ describe('getCustomAppConfigFile', () => {
});
test('It should return app.js when the app config file extension is not (.ts|.tsx) and useTypeScript is truthy', async () => {
fse.pathExistsSync = jest.fn(() => {
return true;
});
fse.readdir = jest.fn(() => {
return ['app.js', 'webpack.config.js', 'app.example.ts', 'app.example.tsx'];
});
@ -35,6 +45,10 @@ describe('getCustomAppConfigFile', () => {
});
test('It should return app.js when the app config file extension is .js and useTypeScript is falsy', async () => {
fse.pathExistsSync = jest.fn(() => {
return true;
});
fse.readdir = jest.fn(() => {
return ['app.js', 'webpack.config.js', 'app.ts', 'app.tsx'];
});

View File

@ -11,6 +11,11 @@ const { isUsingTypeScript } = require('@strapi/typescript-utils');
*/
const getCustomAppConfigFile = async (dir) => {
const adminSrcPath = join(dir, 'src', 'admin');
if (!fse.pathExistsSync(adminSrcPath)) {
return undefined;
}
const useTypeScript = await isUsingTypeScript(adminSrcPath, 'tsconfig.json');
const files = await fse.readdir(adminSrcPath);