From 4cfdbeed1937dc21597f8f1f9eaf77e868bc9c53 Mon Sep 17 00:00:00 2001 From: soupette Date: Wed, 23 Mar 2022 15:14:30 +0100 Subject: [PATCH] Add tests Signed-off-by: soupette --- .../utils/__tests__/get-plugins-path.test.js | 23 +++++++++++++++++++ packages/core/admin/utils/get-plugins-path.js | 5 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 packages/core/admin/utils/__tests__/get-plugins-path.test.js diff --git a/packages/core/admin/utils/__tests__/get-plugins-path.test.js b/packages/core/admin/utils/__tests__/get-plugins-path.test.js new file mode 100644 index 0000000000..c2ebdefd6b --- /dev/null +++ b/packages/core/admin/utils/__tests__/get-plugins-path.test.js @@ -0,0 +1,23 @@ +'use strict'; + +const getPluginsPath = require('../get-plugins-path'); + +describe('getPluginsPath', () => { + test('should return an array of directories that contains an admin/src/index.js file', () => { + const results = getPluginsPath(); + + expect(results.length).toBeGreaterThan(0); + // Test that the content-type-builder is included + expect(results.findIndex(p => p.includes('/core/content-type-builder/admin'))).not.toEqual(-1); + // Test that the upload is included + expect(results.findIndex(p => p.includes('/core/upload/admin'))).not.toEqual(-1); + // Test that the documentation is included + expect(results.findIndex(p => p.includes('/plugins/documentation/admin'))).not.toEqual(-1); + // Test that the CM is not included + expect(results.findIndex(p => p.includes('/core/content-manager/admin'))).toEqual(-1); + // Test that the admin package is not included + expect(results.findIndex(p => p.includes('/core/admin/admin'))).toEqual(-1); + // Test that the helper-plugin package is not included + expect(results.findIndex(p => p.includes('helper-plugin'))).toEqual(-1); + }); +}); diff --git a/packages/core/admin/utils/get-plugins-path.js b/packages/core/admin/utils/get-plugins-path.js index 3fb3813f71..d1da53a384 100644 --- a/packages/core/admin/utils/get-plugins-path.js +++ b/packages/core/admin/utils/get-plugins-path.js @@ -6,13 +6,14 @@ const fs = require('fs-extra'); const glob = require('glob'); const getPluginsPath = () => { - const rootPath = join('..', '..', '..', 'packages'); + const rootPath = resolve(__dirname, '..', join('..', '..', '..', 'packages')); const corePath = join(rootPath, 'core', '*'); const pluginsPath = join(rootPath, 'plugins', '*'); const corePackageDirs = glob.sync(corePath); const pluginsPackageDirs = glob.sync(pluginsPath); + const packageDirs = [...corePackageDirs, ...pluginsPackageDirs].filter(dir => { - const isCoreAdmin = dir.includes('packages/core/admin/'); + const isCoreAdmin = dir.includes('packages/core/admin'); const pathToEntryPoint = join(dir, 'admin', 'src', 'index.js'); const doesAdminFolderExist = fs.pathExistsSync(pathToEntryPoint);