npm-plugin.spec.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { rm } from 'node:fs/promises';
  2. import { join } from 'node:path';
  3. import tsconfigPaths from 'tsconfig-paths';
  4. import { describe, expect, it } from 'vitest';
  5. import { compile } from '../utils/compiler.js';
  6. import { debugLogger, noopLogger } from '../utils/logger.js';
  7. describe('detecting plugins in npm packages', () => {
  8. it('should detect plugins in npm packages', { timeout: 60_000 }, async () => {
  9. const tempDir = join(__dirname, './__temp/npm-plugin');
  10. await rm(tempDir, { recursive: true, force: true });
  11. const fakeNodeModules = join(__dirname, 'fixtures-npm-plugin', 'fake_node_modules');
  12. // For this test to work, we need to use tsconfigPaths to point
  13. // the `test-plugin` package to the `fake_node_modules` directory.
  14. // This is because the `test-plugin` package is not installed in
  15. // the `node_modules` directory, but in the `fake_node_modules`
  16. // directory.
  17. tsconfigPaths.register({
  18. baseUrl: fakeNodeModules,
  19. paths: {
  20. 'test-plugin': [join(fakeNodeModules, 'test-plugin')],
  21. },
  22. });
  23. const result = await compile({
  24. outputPath: tempDir,
  25. vendureConfigPath: join(__dirname, 'fixtures-npm-plugin', 'vendure-config.ts'),
  26. logger: process.env.LOG ? debugLogger : noopLogger,
  27. pluginPackageScanner: {
  28. nodeModulesRoot: fakeNodeModules,
  29. },
  30. });
  31. expect(result.pluginInfo).toHaveLength(1);
  32. expect(result.pluginInfo[0].name).toBe('TestPlugin');
  33. expect(result.pluginInfo[0].dashboardEntryPath).toBe('./dashboard/index.tsx');
  34. expect(result.pluginInfo[0].sourcePluginPath).toBeUndefined();
  35. expect(result.pluginInfo[0].pluginPath).toBe(join(fakeNodeModules, 'test-plugin', 'index.js'));
  36. });
  37. });