ManagerTest.php
4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
use Roots\Acorn\Assets\Contracts\Manifest as ManifestContract;
use Roots\Acorn\Assets\Contracts\ManifestNotFoundException;
use Roots\Acorn\Assets\Manager;
use Roots\Acorn\Assets\Manifest;
use Roots\Acorn\Tests\Test\TestCase;
use function Spatie\Snapshots\assertMatchesSnapshot;
uses(TestCase::class);
it('creates a manifest', function () {
$assets = new Manager();
$manifest = $assets->manifest('theme', [
'path' => $this->fixture('bud_single_runtime'),
'url' => 'https://k.jo',
'assets' => $this->fixture('bud_single_runtime/public/manifest.json'),
]);
expect($manifest)->toBeInstanceOf(ManifestContract::class);
});
it('registers a manifest', function () {
$assets = new Manager();
$assets->register('theme', new Manifest(
$this->fixture('bud_single_runtime'),
'https://k.jo',
[],
));
expect($assets->manifest('theme'))->toBeInstanceOf(ManifestContract::class);
});
it('throws an error if an assets manifest does not exist', function () {
$assets = new Manager([
'manifests' => [
'theme' => [
'path' => $this->fixture('bud_single_runtime'),
'url' => 'https://k.jo',
'assets' => __DIR__ . '/does/not/exist/manifest.json',
]
]
]);
$assets->manifest('theme')->asset('app.css')->uri();
})->throws(ManifestNotFoundException::class);
it('reads an assets manifest', function () {
$assets = new Manager([
'manifests' => [
'theme' => [
'path' => $this->fixture('bud_single_runtime'),
'url' => 'https://k.jo',
'assets' => $this->fixture('bud_single_runtime/public/manifest.json'),
]
]
]);
assertMatchesSnapshot($assets->manifest('theme')->asset('app.css')->uri());
assertMatchesSnapshot($assets->manifest('theme')->asset('app.js')->uri());
});
it('reads multiple manifests', function () {
$assets = new Manager([
'manifests' => [
'app' => [
'path' => $this->fixture('bud_single_runtime/public/app'),
'url' => 'https://k.jo/app',
'assets' => $this->fixture('bud_multi_compiler/public/app/manifest.json'),
'bundles' => $this->fixture('bud_multi_compiler/public/app/entrypoints.json'),
],
'editor' => [
'path' => $this->fixture('bud_single_runtime/public/editor'),
'url' => 'https://k.jo/editor',
'assets' => $this->fixture('bud_multi_compiler/public/editor/manifest.json'),
'bundles' => $this->fixture('bud_multi_compiler/public/editor/entrypoints.json'),
],
]
]);
assertMatchesSnapshot($assets->manifest('app')->asset('app.js')->uri());
assertMatchesSnapshot($assets->manifest('editor')->asset('editor.js')->uri());
});
it('throws an error if a bundles manifest does not exist', function () {
$assets = new Manager([
'manifests' => [
'theme' => [
'path' => $this->fixture('bud_single_runtime'),
'url' => 'https://k.jo',
'bundles' => __DIR__ . '/does/not/exist/entrypoints.json',
]
]
]);
$assets->manifest('theme')->bundle('app')->js()->toJson();
})->throws(ManifestNotFoundException::class);
it('reads a bundles manifest', function () {
$assets = new Manager([
'manifests' => [
'theme' => [
'path' => $this->fixture('bud_single_runtime'),
'url' => 'https://k.jo',
'bundles' => $this->fixture('bud_single_runtime/public/entrypoints.json'),
]
]
]);
assertMatchesSnapshot($assets->manifest('theme')->bundle('app')->js()->toJson());
assertMatchesSnapshot($assets->manifest('theme')->bundle('editor')->js()->toJson());
assertMatchesSnapshot($assets->manifest('theme')->bundle('editor')->js()->toJson());
});
it('reads a mix manifest', function () {
$assets = new Manager([
'manifests' => [
'theme' => [
'path' => $this->fixture('mix_no_bundle/public'),
'url' => 'https://k.jo/public',
'assets' => $this->fixture('mix_no_bundle/public/mix-manifest.json'),
]
]
]);
assertMatchesSnapshot($assets->manifest('theme')->asset('styles/app.css')->uri());
assertMatchesSnapshot($assets->manifest('theme')->asset('scripts/app.js')->uri());
});