Skip to content

Commit 93e2ff9

Browse files
committed
Fixing more tests
1 parent 0cb0aa3 commit 93e2ff9

File tree

3 files changed

+18
-127
lines changed

3 files changed

+18
-127
lines changed

src/Symfony/Component/AssetMapper/Tests/Compiler/JavaScriptImportPathCompilerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testCompile(string $sourceLogicalName, string $input, array $exp
4040
}
4141

4242
if ('module_in_importmap_remote' === $importName) {
43-
return new ImportMapEntry('module_in_importmap_local_asset', url: 'https://example.com/module.js');
43+
return new ImportMapEntry('module_in_importmap_local_asset', version: '1.2.3');
4444
}
4545

4646
return null;

src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapConfigReaderTest.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@ public function testGetEntriesAndWriteEntries()
4343
<?php
4444
return [
4545
'remote_package' => [
46-
'url' => 'https://unpkg.com/@hotwired/stimulus@3.2.1/dist/stimulus.js',
47-
],
48-
'remote_package_downloaded' => [
49-
'downloaded_to' => 'vendor/lodash.js',
50-
'url' => 'https://ga.jspm.io/npm:lodash@4.17.21/lodash.js',
46+
'version' => '3.2.1',
5147
],
5248
'local_package' => [
5349
'path' => 'app.js',
@@ -69,28 +65,23 @@ public function testGetEntriesAndWriteEntries()
6965
$this->assertInstanceOf(ImportMapEntries::class, $entries);
7066
/** @var ImportMapEntry[] $allEntries */
7167
$allEntries = iterator_to_array($entries);
72-
$this->assertCount(5, $allEntries);
68+
$this->assertCount(4, $allEntries);
7369

7470
$remotePackageEntry = $allEntries[0];
7571
$this->assertSame('remote_package', $remotePackageEntry->importName);
7672
$this->assertNull($remotePackageEntry->path);
77-
$this->assertSame('https://unpkg.com/@hotwired/stimulus@3.2.1/dist/stimulus.js', $remotePackageEntry->url);
78-
$this->assertFalse($remotePackageEntry->isDownloaded);
73+
$this->assertSame('3.2.1', $remotePackageEntry->version);
7974
$this->assertSame('js', $remotePackageEntry->type->value);
8075
$this->assertFalse($remotePackageEntry->isEntrypoint);
8176

82-
$remotePackageDownloadedEntry = $allEntries[1];
83-
$this->assertSame('https://ga.jspm.io/npm:lodash@4.17.21/lodash.js', $remotePackageDownloadedEntry->url);
84-
$this->assertSame('vendor/lodash.js', $remotePackageDownloadedEntry->path);
85-
86-
$localPackageEntry = $allEntries[2];
87-
$this->assertNull($localPackageEntry->url);
77+
$localPackageEntry = $allEntries[1];
78+
$this->assertNull($localPackageEntry->version);
8879
$this->assertSame('app.js', $localPackageEntry->path);
8980

90-
$typeCssEntry = $allEntries[3];
81+
$typeCssEntry = $allEntries[2];
9182
$this->assertSame('css', $typeCssEntry->type->value);
9283

93-
$entryPointEntry = $allEntries[4];
84+
$entryPointEntry = $allEntries[3];
9485
$this->assertTrue($entryPointEntry->isEntrypoint);
9586

9687
// now save the original raw data from importmap.php and delete the file

src/Symfony/Component/AssetMapper/Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php

Lines changed: 10 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ public function testResolvePackages(array $packages, array $expectedRequests, ar
4949
foreach ($actualResolvedPackages as $package) {
5050
$packageName = $package->requireOptions->packageName;
5151
$this->assertArrayHasKey($packageName, $expectedResolvedPackages);
52-
$this->assertSame($expectedResolvedPackages[$packageName]['url'], $package->url);
53-
if (isset($expectedResolvedPackages[$packageName]['content'])) {
54-
$this->assertSame($expectedResolvedPackages[$packageName]['content'], $package->content);
55-
}
52+
$this->assertSame($expectedResolvedPackages[$packageName]['version'], $package->version);
5653
}
5754
}
5855

@@ -76,7 +73,7 @@ public static function provideResolvePackagesTests(): iterable
7673
],
7774
'expectedResolvedPackages' => [
7875
'lodash' => [
79-
'url' => 'https://cdn.jsdelivr.net/npm/lodash.js@1.2.3/+esm',
76+
'version' => '1.2.3',
8077
],
8178
],
8279
];
@@ -99,7 +96,7 @@ public static function provideResolvePackagesTests(): iterable
9996
],
10097
'expectedResolvedPackages' => [
10198
'lodash' => [
102-
'url' => 'https://cdn.jsdelivr.net/npm/lodash.js@2.1.3/+esm',
99+
'version' => '2.1.3',
103100
],
104101
],
105102
];
@@ -122,7 +119,7 @@ public static function provideResolvePackagesTests(): iterable
122119
],
123120
'expectedResolvedPackages' => [
124121
'@hotwired/stimulus' => [
125-
'url' => 'https://cdn.jsdelivr.net/npm/@hotwired/stimulus.js@3.1.3/+esm',
122+
'version' => '3.1.3',
126123
],
127124
],
128125
];
@@ -145,7 +142,7 @@ public static function provideResolvePackagesTests(): iterable
145142
],
146143
'expectedResolvedPackages' => [
147144
'chart.js/auto' => [
148-
'url' => 'https://cdn.jsdelivr.net/npm/chart.js@3.0.1/auto/+esm',
145+
'version' => '3.0.1',
149146
],
150147
],
151148
];
@@ -168,104 +165,7 @@ public static function provideResolvePackagesTests(): iterable
168165
],
169166
'expectedResolvedPackages' => [
170167
'@chart/chart.js/auto' => [
171-
'url' => 'https://cdn.jsdelivr.net/npm/@chart/chart.js@3.0.1/auto/+esm',
172-
],
173-
],
174-
];
175-
176-
yield 'require package with simple download' => [
177-
'packages' => [new PackageRequireOptions('lodash', download: true)],
178-
'expectedRequests' => [
179-
[
180-
'url' => '/v1/packages/npm/lodash/resolved?specifier=%2A',
181-
'response' => ['body' => ['version' => '1.2.3']],
182-
],
183-
[
184-
'url' => '/lodash@1.2.3/+esm',
185-
'response' => [
186-
'url' => 'https://cdn.jsdelivr.net/npm/lodash.js@1.2.3/+esm',
187-
'body' => 'contents of file',
188-
],
189-
],
190-
[
191-
'url' => '/v1/packages/npm/lodash@1.2.3/entrypoints',
192-
'response' => ['body' => ['entrypoints' => []]],
193-
],
194-
],
195-
'expectedResolvedPackages' => [
196-
'lodash' => [
197-
'url' => 'https://cdn.jsdelivr.net/npm/lodash.js@1.2.3/+esm',
198-
'content' => 'contents of file',
199-
],
200-
],
201-
];
202-
203-
yield 'require package download with import dependencies' => [
204-
'packages' => [new PackageRequireOptions('lodash', download: true)],
205-
'expectedRequests' => [
206-
// lodash
207-
[
208-
'url' => '/v1/packages/npm/lodash/resolved?specifier=%2A',
209-
'response' => ['body' => ['version' => '1.2.3']],
210-
],
211-
[
212-
'url' => '/lodash@1.2.3/+esm',
213-
'response' => [
214-
'url' => 'https://cdn.jsdelivr.net/npm/lodash.js@1.2.3/+esm',
215-
'body' => 'import{Color as t}from"/npm/@kurkle/color@0.3.2/+esm";console.log("yo");',
216-
],
217-
],
218-
[
219-
'url' => '/v1/packages/npm/lodash@1.2.3/entrypoints',
220-
'response' => ['body' => ['entrypoints' => []]],
221-
],
222-
// @kurkle/color
223-
[
224-
'url' => '/v1/packages/npm/@kurkle/color/resolved?specifier=0.3.2',
225-
'response' => ['body' => ['version' => '0.3.2']],
226-
],
227-
[
228-
'url' => '/@kurkle/color@0.3.2/+esm',
229-
'response' => [
230-
'url' => 'https://cdn.jsdelivr.net/npm/@kurkle/color@0.3.2/+esm',
231-
'body' => 'import*as t from"/npm/@popperjs/core@2.11.7/+esm";// hello world',
232-
],
233-
],
234-
[
235-
'url' => '/v1/packages/npm/@kurkle/color@0.3.2/entrypoints',
236-
'response' => ['body' => ['entrypoints' => []]],
237-
],
238-
// @popperjs/core
239-
[
240-
'url' => '/v1/packages/npm/@popperjs/core/resolved?specifier=2.11.7',
241-
'response' => ['body' => ['version' => '2.11.7']],
242-
],
243-
[
244-
'url' => '/@popperjs/core@2.11.7/+esm',
245-
'response' => [
246-
'url' => 'https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.7/+esm',
247-
// point back to the original to try to confuse things or cause extra work
248-
'body' => 'import*as t from"/npm/lodash@1.2.9/+esm";// hello from popper',
249-
],
250-
],
251-
[
252-
'url' => '/v1/packages/npm/@popperjs/core@2.11.7/entrypoints',
253-
'response' => ['body' => ['entrypoints' => []]],
254-
],
255-
],
256-
'expectedResolvedPackages' => [
257-
'lodash' => [
258-
'url' => 'https://cdn.jsdelivr.net/npm/lodash.js@1.2.3/+esm',
259-
// file was updated correctly
260-
'content' => 'import{Color as t}from"@kurkle/color";console.log("yo");',
261-
],
262-
'@kurkle/color' => [
263-
'url' => 'https://cdn.jsdelivr.net/npm/@kurkle/color@0.3.2/+esm',
264-
'content' => 'import*as t from"@popperjs/core";// hello world',
265-
],
266-
'@popperjs/core' => [
267-
'url' => 'https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.7/+esm',
268-
'content' => 'import*as t from"lodash";// hello from popper',
168+
'version' => '3.0.1',
269169
],
270170
],
271171
];
@@ -285,7 +185,7 @@ public static function provideResolvePackagesTests(): iterable
285185
],
286186
'expectedResolvedPackages' => [
287187
'bootstrap/dist/css/bootstrap.min.css' => [
288-
'url' => 'https://cdn.jsdelivr.net/npm/bootstrap.js@3.3.0/dist/css/bootstrap.min.css',
188+
'version' => '3.3.0',
289189
],
290190
],
291191
];
@@ -319,10 +219,10 @@ public static function provideResolvePackagesTests(): iterable
319219
],
320220
'expectedResolvedPackages' => [
321221
'bootstrap' => [
322-
'url' => 'https://cdn.jsdelivr.net/npm/bootstrap.js@5.2.0/+esm',
222+
'version' => '5.2.0',
323223
],
324224
'bootstrap/dist/css/bootstrap.min.css' => [
325-
'url' => 'https://cdn.jsdelivr.net/npm/bootstrap.js@5.2.0/dist/css/bootstrap.min.css',
225+
'version' => '5.2.0',
326226
],
327227
],
328228
];
@@ -341,7 +241,7 @@ public static function provideResolvePackagesTests(): iterable
341241
],
342242
'expectedResolvedPackages' => [
343243
'bootstrap/dist/modal.js' => [
344-
'url' => 'https://cdn.jsdelivr.net/npm/bootstrap.js@5.2.0/dist/modal.js+esm',
244+
'version' => '5.2.0',
345245
],
346246
],
347247
];

0 commit comments

Comments
 (0)