cypress-8.x-1.x-dev/tests/Unit/CypressRuntimeTest.php

tests/Unit/CypressRuntimeTest.php
<?php

namespace Drupal\Tests\cypress\Unit;

use Drupal\cypress\CypressOptions;
use Drupal\cypress\CypressRootFactory;
use Drupal\cypress\CypressRuntime;
use Drupal\cypress\NpmProjectManagerInterface;
use Drupal\Tests\UnitTestCase;
use org\bovigo\vfs\vfsStream;
use Symfony\Component\Filesystem\Filesystem;
use Prophecy\Prophecy\ObjectProphecy;

class CypressRuntimeTest extends UnitTestCase {

  /**
   * @var \org\bovigo\vfs\vfsStreamDirectory
   */
  protected $fileSystem;

  /**
   * @var string
   */
  protected $cypressRoot;

  /**
   * @var \Drupal\cypress\CypressRuntime
   */
  protected $cypressRuntime;

  /**
   * @var \Drupal\cypress\CypressOptions
   */
  protected $cypressOptions;

  /**
   * @var ObjectProphecy<NpmProjectManagerInterface>
   */
  protected $npmProjectManager;

  protected function setUp(): void {
    parent::setUp();
    $this->fileSystem = vfsStream::setup();
    $this->cypressRoot = $this->fileSystem->url() . '/' . CypressRootFactory::CYPRESS_ROOT_DIRECTORY;
    $this->cypressOptions = new CypressOptions();
    $this->npmProjectManager = $this->prophesize(NpmProjectManagerInterface::class);
    $this->cypressRuntime = new class (
      $this->cypressRoot,
      $this->npmProjectManager->reveal()
    ) extends CypressRuntime {
      protected function getFileSystem() {
        return new class extends Filesystem {
          /**
           * {@inheritDoc)
           *
           * Use `mirror` instead of symlink since the latter is not supported
           * by vfsStream.
           */
          public function symlink($originDir, $targetDir, $copyOnWindows = FALSE): bool {
            $this->mirror($originDir, $targetDir);
            return TRUE;
          }
        };
      }
    };
  }

  public function testCreateCypressDirectory(): void {
    $this->cypressRuntime->initiate($this->cypressOptions);
    $this->assertDirectoryExists($this->cypressRoot);
  }

  public function testClearDirectories(): void {
    vfsStream::create([
      CypressRootFactory::CYPRESS_ROOT_DIRECTORY => [
        'integration' => [ 'foo' => 'bar' ],
        'fixtures' => [ 'foo' => 'bar' ],
      ]
    ]);
    $this->cypressRuntime->initiate($this->cypressOptions);
    $this->assertFileNotExists($this->cypressRoot . '/integration/foo');
    $this->assertFileNotExists($this->cypressRoot . '/suites/foo');
  }

  public function testGenerateCypressJson(): void {
    $this->cypressRuntime->initiate($this->cypressOptions);
    $this->assertStringEqualsFile($this->cypressRoot . '/cypress.json', $this->cypressOptions->getCypressJson());
  }

  public function testGeneratePluginsJs(): void {
    $this->cypressRuntime->initiate($this->cypressOptions);
    $this->assertFileExists($this->cypressRoot . '/plugins.js');
  }

  public function testGenerateSupportJs(): void {
    $this->cypressRuntime->initiate($this->cypressOptions);
    $this->assertFileExists($this->cypressRoot . '/support.js');
  }

  public function testAddTestSuite(): void {
    vfsStream::create([
      'a' => [
        'integration' => [
          'foo' => 'bar',
        ],
        'steps' => [
          'foo' => 'bar',
        ],
        'support' => [
          'index.js' => 'bar',
        ],
        'plugins' => [
          'index.js' => 'bar',
        ],
        'package.json' => '',
      ],
    ], $this->fileSystem);
    $this->npmProjectManager->merge($this->fileSystem->url() . '/a/package.json')->shouldBeCalledOnce();
    $this->cypressRuntime->initiate($this->cypressOptions);
    $this->cypressRuntime->addSuite('a', $this->fileSystem->url() . '/a');

    $this->assertStringEqualsFile($this->cypressRoot . '/integration/a/foo', 'bar');
    $this->assertStringEqualsFile($this->cypressRoot . '/suites/a/integration/foo', 'bar');
    $this->assertStringEqualsFile($this->cypressRoot . '/integration/common/a/foo', 'bar');
    $this->assertStringEqualsFile(
      $this->cypressRoot . '/support.js',
      "// Automatically generated by the Cypress module for Drupal.
require('./support/a/index.js');"
    );

    $this->assertDirectoryExists($this->cypressRoot . '/plugins/a');
    $this->assertStringEqualsFile(
      $this->cypressRoot . '/plugins.js',
      "// Automatically generated by the Cypress module for Drupal.
module.exports = (on, config) => {
  require('./plugins/a/index.js')(on, config);
};"
    );
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc