Skip to content

Commit fd3f216

Browse files
authored
Use markdown_samples.md in generated test profile package. (#8647)
1 parent 6cfec76 commit fd3f216

File tree

9 files changed

+201
-26
lines changed

9 files changed

+201
-26
lines changed

app/lib/tool/test_profile/import_source.dart

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ import 'package:meta/meta.dart';
1414
import 'package:path/path.dart' as p;
1515
import 'package:tar/tar.dart';
1616

17-
import '../../fake/backend/fake_pana_runner.dart';
1817
import '../../shared/urls.dart' as urls;
1918

2019
import 'models.dart';
2120
import 'resolver.dart' as resolver;
2221

22+
final _markdownSamples =
23+
File(p.join('lib', 'tool', 'test_profile', 'markdown_samples.md'))
24+
.readAsStringSync();
25+
2326
/// Utility class for resolving and getting data for profiles.
2427
class ImportSource {
2528
final _client = Client();
@@ -103,26 +106,24 @@ class ImportSource {
103106
TestArchiveTemplate? template,
104107
) async {
105108
final key = '$package/$version';
106-
final hasher = createHasher(key);
107109
if (_archives.containsKey(key)) {
108110
return _archives[key]!;
109111
}
110112
final archive = ArchiveBuilder();
111-
final hasHomepage = !version.contains('nohomepage');
112-
final hasRepository = hasher('hasRepository', max: 20) > 0;
113-
final isLegacy = version.contains('legacy');
114113

115-
final sdkConstraint =
116-
template?.sdkConstraint ?? (isLegacy ? '>=1.12.0 <2.0.0' : '^3.0.0');
114+
final homepage = template?.homepage ?? 'https://$package.example.com/';
115+
final repository =
116+
template?.repository ?? 'https://github.com/example/$package';
117+
final sdkConstraint = template?.sdkConstraint ?? '^3.0.0';
117118

118119
final isFlutter = package.startsWith('flutter_');
119120
final screenshot = TestScreenshot.success();
120121
final pubspec = json.encode({
121122
'name': package,
122123
'version': version,
123124
'description': '$package is awesome',
124-
if (hasHomepage) 'homepage': 'https://$package.example.com/',
125-
if (hasRepository) 'repository': 'https://github.com/example/$package',
125+
if (homepage.isNotEmpty) 'homepage': homepage,
126+
if (repository.isNotEmpty) 'repository': repository,
126127
'environment': {
127128
'sdk': '$sdkConstraint',
128129
},
@@ -141,8 +142,13 @@ class ImportSource {
141142
'topics': ['chemical-element'],
142143
});
143144

145+
final readmeContent = [
146+
'# $package\n\nAwesome package.',
147+
if (template?.markdownSamples ?? false) _markdownSamples,
148+
].join('\n\n');
149+
144150
archive.addFile('pubspec.yaml', pubspec);
145-
archive.addFile('README.md', '# $package\n\nAwesome package.');
151+
archive.addFile('README.md', readmeContent);
146152
archive.addFile('CHANGELOG.md', '## $version\n\n- updated');
147153
archive.addFile('lib/$package.dart', '''library;
148154
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Header 1
2+
3+
Paragraph with `inline code block`. Overall, the text content here should be
4+
long enough that it will be displayed as multiple lines. It demonstrates the
5+
line height and we may also use it to track subtle changes in the layout
6+
(maybe enable hyphens?).
7+
8+
## Header 2 - also a longer block of text that should be breaking into multiple lines even in desktop view
9+
10+
Paragraph with **bold text**.
11+
12+
***
13+
14+
Separated by a line, also using *italic formatting*.
15+
16+
### Header 3
17+
18+
Paragraph with [link and `inline code`](https://pub.dev/).
19+
20+
#### Header 4
21+
##### Header 5
22+
###### Header6
23+
24+
> Blockquote with unordered list:
25+
> - item 1
26+
> - item 2
27+
28+
Ordered list and list nesting:
29+
1. item 1.
30+
1. item 2.
31+
1. item 2.1.
32+
1. item 2.2.
33+
1. item 3.
34+
on multiple lines
35+
36+
```dart
37+
void main() {}
38+
```
39+
40+
![image](https://pub.dev/static/img/pub-dev-logo.svg)
41+
42+
> [!NOTE]
43+
> Highlights information that users should take into account, even when skimming.
44+
45+
> [!TIP]
46+
> Optional information to help a user be more successful.
47+
48+
> [!IMPORTANT]
49+
> Crucial information necessary for users to succeed.
50+
51+
> [!WARNING]
52+
> Critical content demanding immediate user attention due to potential risks.
53+
54+
> [!CAUTION]
55+
> Negative potential consequences of an action.

app/lib/tool/test_profile/models.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,16 @@ class GeneratedTestVersion extends TestVersion {
184184

185185
@JsonSerializable(explicitToJson: true, includeIfNull: false)
186186
class TestArchiveTemplate {
187+
final String? homepage;
188+
final String? repository;
187189
final String? sdkConstraint;
190+
final bool? markdownSamples;
188191

189192
TestArchiveTemplate({
193+
this.homepage,
194+
this.repository,
190195
this.sdkConstraint,
196+
this.markdownSamples,
191197
});
192198

193199
factory TestArchiveTemplate.fromJson(Map<String, dynamic> json) =>
@@ -196,7 +202,10 @@ class TestArchiveTemplate {
196202
TestArchiveTemplate overrideWith(TestArchiveTemplate? other) {
197203
if (other == null) return this;
198204
return TestArchiveTemplate(
205+
homepage: other.homepage ?? homepage,
206+
repository: other.repository ?? repository,
199207
sdkConstraint: other.sdkConstraint ?? sdkConstraint,
208+
markdownSamples: other.markdownSamples ?? markdownSamples,
200209
);
201210
}
202211

app/lib/tool/test_profile/models.g.dart

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/test/frontend/golden/pkg_show_page.html

Lines changed: 85 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,6 @@ <h1 class="title pub-monochrome-icon-hoverable">
132132
<span>
133133
<a class="-x-ago" href="" title="%%published-date%%" role="button" data-timestamp="%%millis%%">%%x-ago%%</a>
134134
</span>
135-
• Latest:
136-
<span>
137-
<a href="/packages/oxygen" title="View the latest version of oxygen">1.2.0</a>
138-
</span>
139-
/
140-
<span>
141-
Prerelease:
142-
<a href="/packages/oxygen/versions/2.0.0-dev" title="Visit oxygen 2.0.0-dev page">2.0.0-dev</a>
143-
</span>
144135
</div>
145136
<div class="detail-tags-and-like">
146137
<div class="detail-tags">
@@ -223,6 +214,90 @@ <h1 id="oxygen" class="hash-header">
223214
<a href="#oxygen" class="hash-link">#</a>
224215
</h1>
225216
<p>Awesome package.</p>
217+
<h1 id="header-1" class="hash-header">
218+
Header 1
219+
<a href="#header-1" class="hash-link">#</a>
220+
</h1>
221+
<p>
222+
Paragraph with
223+
<code>inline code block</code>
224+
. Overall, the text content here should be long enough that it will be displayed as multiple lines. It demonstrates the line height and we may also use it to track subtle changes in the layout (maybe enable hyphens?).
225+
</p>
226+
<h2 id="header-2---also-a-longer-block-of-text-that-should-be-breaking-into-multiple-lines-even-in-desktop-view" class="hash-header">
227+
Header 2 - also a longer block of text that should be breaking into multiple lines even in desktop view
228+
<a href="#header-2---also-a-longer-block-of-text-that-should-be-breaking-into-multiple-lines-even-in-desktop-view" class="hash-link">#</a>
229+
</h2>
230+
<p>
231+
Paragraph with
232+
<strong>bold text</strong>
233+
.
234+
</p>
235+
<hr/>
236+
<p>
237+
Separated by a line, also using
238+
<em>italic formatting</em>
239+
.
240+
</p>
241+
<h3 id="header-3" class="hash-header">
242+
Header 3
243+
<a href="#header-3" class="hash-link">#</a>
244+
</h3>
245+
<p>
246+
Paragraph with
247+
<a href="https://pub.dev/">
248+
link and
249+
<code>inline code</code>
250+
</a>
251+
.
252+
</p>
253+
<h4 id="header-4">Header 4</h4>
254+
<h5 id="header-5">Header 5</h5>
255+
<h6 id="header6">Header6</h6>
256+
<blockquote>
257+
<p>Blockquote with unordered list:</p>
258+
<ul>
259+
<li>item 1</li>
260+
<li>item 2</li>
261+
</ul>
262+
</blockquote>
263+
<p>Ordered list and list nesting:</p>
264+
<ol>
265+
<li>item 1.</li>
266+
<li>
267+
item 2.
268+
<ol>
269+
<li>item 2.1.</li>
270+
<li>item 2.2.</li>
271+
</ol>
272+
</li>
273+
<li>item 3. on multiple lines</li>
274+
</ol>
275+
<pre>
276+
<code class="language-dart">void main() {}</code>
277+
</pre>
278+
<p>
279+
<img src="https://pub.dev/static/img/pub-dev-logo.svg" alt="image"/>
280+
</p>
281+
<div class="markdown-alert markdown-alert-note">
282+
<p class="markdown-alert-title">Note</p>
283+
<p>Highlights information that users should take into account, even when skimming.</p>
284+
</div>
285+
<div class="markdown-alert markdown-alert-tip">
286+
<p class="markdown-alert-title">Tip</p>
287+
<p>Optional information to help a user be more successful.</p>
288+
</div>
289+
<div class="markdown-alert markdown-alert-important">
290+
<p class="markdown-alert-title">Important</p>
291+
<p>Crucial information necessary for users to succeed.</p>
292+
</div>
293+
<div class="markdown-alert markdown-alert-warning">
294+
<p class="markdown-alert-title">Warning</p>
295+
<p>Critical content demanding immediate user attention due to potential risks.</p>
296+
</div>
297+
<div class="markdown-alert markdown-alert-caution">
298+
<p class="markdown-alert-title">Caution</p>
299+
<p>Negative potential consequences of an action.</p>
300+
</div>
226301
</section>
227302
</div>
228303
</div>
@@ -297,7 +372,7 @@ <h3 class="title">More</h3>
297372
</p>
298373
</aside>
299374
</div>
300-
<script type="application/ld+json">{"@context":"http\u003a\u002f\u002fschema.org","@type":"SoftwareSourceCode","name":"oxygen","version":"1.2.0","description":"oxygen - oxygen is awesome","url":"https\u003a\u002f\u002fpub.dev\u002fpackages\u002foxygen","dateCreated":"%%published-escaped-timestamp%%","dateModified":"%%updated-escaped-timestamp%%","programmingLanguage":"Dart","image":"https\u003a\u002f\u002fpub.dev\u002fstatic\u002fimg\u002fpub-dev-icon-cover-image.png","license":"https\u003a\u002f\u002fpub.dev\u002fpackages\u002foxygen\u002flicense"}</script>
375+
<script type="application/ld+json">{"@context":"http\u003a\u002f\u002fschema.org","@type":"SoftwareSourceCode","name":"oxygen","version":"1.2.0","description":"oxygen - oxygen is awesome","url":"https\u003a\u002f\u002fpub.dev\u002fpackages\u002foxygen","dateCreated":"%%published-escaped-timestamp%%","dateModified":"%%published-escaped-timestamp%%","programmingLanguage":"Dart","image":"https\u003a\u002f\u002fpub.dev\u002fstatic\u002fimg\u002fpub-dev-icon-cover-image.png","license":"https\u003a\u002f\u002fpub.dev\u002fpackages\u002foxygen\u002flicense"}</script>
301376
</div>
302377
<div class="detail-metadata">
303378
<h3 class="detail-metadata-title">

app/test/frontend/handlers/package_test.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,12 @@ void main() {
125125
'package pages without homepage',
126126
testProfile: TestProfile(
127127
generatedPackages: [
128-
GeneratedTestPackage(
129-
name: 'pkg',
130-
versions: [GeneratedTestVersion(version: '1.0.0-nohomepage')]),
128+
GeneratedTestPackage(name: 'pkg', versions: [
129+
GeneratedTestVersion(
130+
version: '1.0.0',
131+
template: TestArchiveTemplate(homepage: ''),
132+
),
133+
]),
131134
],
132135
defaultUser: '[email protected]',
133136
),

app/test/frontend/templates_test.dart

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,24 @@ void main() {
142142
);
143143

144144
testWithProfile(
145-
'package show page',
145+
'package readme page with markdown',
146146
processJobsWithFakeRunners: true,
147+
testProfile: TestProfile(
148+
defaultUser: '[email protected]',
149+
generatedPackages: [
150+
GeneratedTestPackage(
151+
name: 'oxygen',
152+
versions: [
153+
GeneratedTestVersion(
154+
version: '1.2.0',
155+
template: TestArchiveTemplate(
156+
markdownSamples: true,
157+
),
158+
),
159+
],
160+
),
161+
],
162+
),
147163
fn: () async {
148164
final data = await withFakeAuthRequestContext(
149165
adminAtPubDevEmail,

pkg/pub_integration/lib/src/test_browser.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,13 @@ class TestBrowserSession {
250250
}
251251
}
252252

253-
if (!rs.url.startsWith('data:')) {
253+
if (!rs.url.startsWith('data:') &&
254+
// exempt the image URL from markdown_samples.md
255+
rs.url != 'https://pub.dev/static/img/pub-dev-logo.svg') {
254256
final uri = Uri.parse(rs.url);
255257
if (uri.pathSegments.length > 1 && uri.pathSegments.first == 'static') {
256258
if (!uri.pathSegments[1].startsWith('hash-')) {
257-
serverErrors.add('Static ${rs.url} is without hash URL.');
259+
serverErrors.add('Static URL ${rs.url} is without hash segment.');
258260
}
259261

260262
final cacheHeader = rs.headers[HttpHeaders.cacheControlHeader];

pkg/pub_integration/test/browser_test.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ void main() {
3737
{
3838
'name': 'retry',
3939
'versions': ['3.1.0'],
40+
'template': {
41+
'markdownSamples': true,
42+
},
4043
},
4144
{'name': '_dummy_pkg'},
4245
],

0 commit comments

Comments
 (0)