Skip to content

Commit

Permalink
test: update MimeTest and PluginsTest for mjs
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaskuske committed Aug 4, 2022
1 parent 81209de commit e9aa698
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
9 changes: 9 additions & 0 deletions tests/Filesystem/MimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ public function testFixCss()
$this->assertSame('text/css', Mime::fix('something.css', 'text/plain', 'css'));
}

/**
* @covers ::fix
*/
public function testFixMjs()
{
$this->assertSame('text/javascript', Mime::fix('something.mjs', 'text/x-java', 'mjs'));
$this->assertSame('text/javascript', Mime::fix('something.mjs', 'text/plain', 'mjs'));
}

/**
* @covers ::fix
*/
Expand Down
36 changes: 33 additions & 3 deletions tests/Panel/PluginsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ class PluginsTest extends TestCase
protected $tmp = __DIR__ . '/tmp';
protected $cssA;
protected $cssB;
protected $cssC;
protected $jsA;
protected $jsB;
protected $jsC;
protected $mjsA;
protected $mjsB;
protected $mjsC;

public function setUp(): void
{
Expand All @@ -38,13 +43,24 @@ public function createPlugins()
touch($this->cssA, $time);
F::write($this->jsA = $this->tmp . '/site/plugins/a/index.js', 'a');
touch($this->jsA, $time);
$this->mjsA = $this->tmp . '/site/plugins/a/index.dev.mjs';

F::write($this->tmp . '/site/plugins/b/index.php', '<?php Kirby::plugin("test/b", []);');
touch($this->tmp . '/site/plugins/b/index.php', $time);
F::write($this->cssB = $this->tmp . '/site/plugins/b/index.css', 'b');
touch($this->cssB, $time);
F::write($this->jsB = $this->tmp . '/site/plugins/b/index.js', 'b');
touch($this->jsB, $time);
$this->mjsB = $this->tmp . '/site/plugins/b/index.dev.mjs';

F::write($this->tmp . '/site/plugins/c/index.php', '<?php Kirby::plugin("test/c", []);');
touch($this->tmp . '/site/plugins/c/index.php', $time);
F::write($this->cssC = $this->tmp . '/site/plugins/c/index.css', 'c');
touch($this->cssC, $time);
F::write($this->jsC = $this->tmp . '/site/plugins/c/index.js', 'c');
touch($this->jsC, $time);
F::write($this->mjsC = $this->tmp . '/site/plugins/c/index.dev.mjs', 'c');
touch($this->mjsC, $time);

return $time;
}
Expand All @@ -65,7 +81,17 @@ public function testFiles()
$app = $this->app->clone();

$plugins = new Plugins();
$expected = [$this->cssA, $this->jsA, $this->cssB, $this->jsB];
$expected = [
$this->cssA,
$this->jsA,
$this->mjsA,
$this->cssB,
$this->jsB,
$this->mjsB,
$this->cssC,
$this->jsC,
$this->mjsC
];

$this->assertSame($expected, $plugins->files());
// from cached property
Expand Down Expand Up @@ -105,12 +131,16 @@ public function testRead()
$plugins = new Plugins();

// css
$expected = "a\n\nb";
$expected = "a\n\nb\n\nc";
$this->assertSame($expected, $plugins->read('css'));

// js
// js - shouldn't include c because c has an index.dev.mjs
$expected = "a;\n\nb;";
$this->assertSame($expected, $plugins->read('js'));

// mjs - c as base64 data uri
$expected = 'try { await Promise.all(["data:text/javascript;base64,Yw=="].map(url => import(url))) } catch (e) { console.error(e) }';
$this->assertSame($expected, $plugins->read('mjs'));
}

/**
Expand Down

0 comments on commit e9aa698

Please sign in to comment.