Add tests

Signed-off-by: soupette <cyril@strapi.io>
This commit is contained in:
soupette 2022-03-23 15:14:30 +01:00 committed by Convly
parent 3568beaa28
commit 4cfdbeed19
2 changed files with 26 additions and 2 deletions

View File

@ -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);
});
});

View File

@ -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);