PHP 8.2.30
Preview: adminjs.spec.js Size: 4.39 KB
/home/byroehnu/easepaybiz.easetack.com/node_modules/adminjs/lib/adminjs.spec.js

import path from 'path';
import { expect } from 'chai';
import * as url from 'url';
import AdminJS from './adminjs.js';
import BaseDatabase from './backend/adapters/database/base-database.js';
import BaseResource from './backend/adapters/resource/base-resource.js';
import { ComponentLoader } from './backend/utils/component-loader.js';
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
describe('AdminJS', function () {
  beforeEach(function () {
    global.RegisteredAdapters = [];
  });
  describe('#constructor', function () {
    it('sets default root path when no given', function () {
      expect(new AdminJS().options.rootPath).to.equal('/admin');
    });
  });
  describe('.AdminJS.registerAdapter', function () {
    beforeEach(function () {
      class Database extends BaseDatabase {}
      class Resource extends BaseResource {}
      this.DatabaseAdapter = {
        Database,
        Resource
      };
    });
    it('adds given adapter to list off all available adapters', function () {
      AdminJS.registerAdapter(this.DatabaseAdapter);
      expect(global.RegisteredAdapters).to.have.lengthOf(1);
    });
    it('throws an error when adapter is not full', function () {
      expect(() => {
        AdminJS.registerAdapter({
          Resource: BaseResource,
          Database: null
        });
      }).to.throw('Adapter has to have both Database and Resource');
    });
    it('throws an error when adapter has elements not being subclassed from base adapter', function () {
      expect(() => {
        AdminJS.registerAdapter({
          Resource: {},
          Database: {}
        });
      }).to.throw('Adapter elements have to be a subclass of AdminJS.BaseResource and AdminJS.BaseDatabase');
    });
  });
  describe('resolveBabelConfigPath', function () {
    it('load .babelrc file', function () {
      const adminJS = new AdminJS({
        bundler: {
          babelConfig: '../.babelrc.json'
        }
      });
      expect(adminJS.options.bundler.babelConfig).not.to.undefined;
    });
    it('load with json object directly', function () {
      const adminJS = new AdminJS({
        bundler: {
          babelConfig: {
            presets: ['@babel/preset-react', ['@babel/preset-env', {
              targets: {
                node: '18'
              },
              modules: false,
              loose: true
            }], '@babel/preset-typescript'],
            plugins: ['@babel/plugin-syntax-import-assertions'],
            only: ['src/', 'spec/'],
            ignore: ['src/frontend/assets/scripts/app-bundle.development.js', 'src/frontend/assets/scripts/app-bundle.production.js', 'src/frontend/assets/scripts/global-bundle.development.js', 'src/frontend/assets/scripts/global-bundle.production.js']
          }
        }
      });
      expect(adminJS.options.bundler.babelConfig).not.to.undefined;
    });
    it('load babel.config.cjs file', function () {
      const adminJS = new AdminJS({
        bundler: {
          babelConfig: './babel.test.config.json'
        }
      });
      expect(adminJS.options.bundler.babelConfig).not.to.undefined;
    });
  });
  describe('ComponentLoader', function () {
    const loader = new ComponentLoader();
    afterEach(function () {
      loader.clear();
    });
    context('file exists', function () {
      beforeEach(function () {
        this.result = loader.add('ExampleComponent', '../spec/fixtures/example-component');
      });
      it('adds given file to a UserComponents object', function () {
        expect(Object.keys(loader.getComponents())).to.have.lengthOf(1);
      });
      it('returns uniqe id', function () {
        expect(loader.getComponents()[this.result]).not.to.be.undefined;
        expect(this.result).to.be.a('string');
      });
      it('converts relative path to absolute path', function () {
        expect(loader.getComponents()[this.result]).to.equal(path.join(__dirname, '../spec/fixtures/example-component'));
      });
    });
    context('component name given', function () {
      it('returns the same component name as which was given', function () {
        const name = loader.add('Dashboard', '../spec/fixtures/example-component');
        expect(name).to.eq('Dashboard');
      });
    });
    it('throws an error when component doesn\'t exist', function () {
      expect(() => {
        loader.add('ExampleComponent', './fixtures/example-components');
      }).to.throw().property('name', 'ConfigurationError');
    });
  });
});

Directory Contents

Dirs: 4 × Files: 9

Name Size Perms Modified Actions
backend DIR
- drwxr-xr-x 2026-03-14 01:49:12
Edit Download
frontend DIR
- drwxr-xr-x 2026-03-14 01:49:12
Edit Download
locale DIR
- drwxr-xr-x 2026-03-14 01:49:12
Edit Download
utils DIR
- drwxr-xr-x 2026-03-14 01:49:12
Edit Download
127 B lr--r--r-- 2026-03-14 01:49:12
Edit Download
10 B lrw-r--r-- 2026-03-05 00:20:15
Edit Download
8.69 KB lrw-r--r-- 2026-03-05 00:20:15
Edit Download
4.39 KB lrw-r--r-- 2026-03-05 00:20:15
Edit Download
592 B lrw-r--r-- 2026-03-05 00:20:26
Edit Download
227 B lrw-r--r-- 2026-03-05 00:20:23
Edit Download
10 B lrw-r--r-- 2026-03-05 00:20:23
Edit Download
10 B lrw-r--r-- 2026-03-05 00:20:23
Edit Download
327 B lrw-r--r-- 2026-03-05 00:20:26
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).