Skip to content

Commit 35143ed

Browse files
committed
test: predicable snapshots
1 parent 002a072 commit 35143ed

17 files changed

Lines changed: 582 additions & 581 deletions

crates/biome_module_graph/tests/snap/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ use biome_resolver::ResolvedPath;
1212
use biome_rowan::AstNode;
1313
use biome_test_utils::{dump_registered_module_types, dump_registered_types};
1414
use camino::Utf8PathBuf;
15-
use std::collections::BTreeSet;
15+
use std::collections::{BTreeMap, BTreeSet};
1616

1717
pub struct ModuleGraphSnapshot<'a> {
1818
module_db: &'a dyn ModuleDb,
19-
files: Vec<(String, String)>,
19+
files: BTreeMap<String, String>,
2020
resolver: Option<&'a ModuleResolver>,
2121
}
2222

@@ -43,7 +43,7 @@ impl<'a> ModuleGraphSnapshot<'a> {
4343
///
4444
/// Use this when the [`MemoryFileSystem`] has been moved into a
4545
/// [`WorkspaceServer`] and is no longer directly accessible.
46-
pub fn from_files(module_db: &'a dyn ModuleDb, files: Vec<(String, String)>) -> Self {
46+
pub fn from_files(module_db: &'a dyn ModuleDb, files: BTreeMap<String, String>) -> Self {
4747
Self {
4848
module_db,
4949
files,
@@ -60,7 +60,7 @@ impl<'a> ModuleGraphSnapshot<'a> {
6060

6161
pub fn assert_snapshot(&self, test_name: &str) {
6262
let mut content = String::new();
63-
let files: Vec<_> = self.files.clone();
63+
let files = self.files.clone();
6464
for (file_name, source_code) in &files {
6565
let file_name = Utf8PathBuf::from(file_name.as_str());
6666
let extension = file_name.extension().unwrap_or_default();

crates/biome_module_graph/tests/snapshots/test_astro_component_imports_snapshot.snap

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,6 @@ source: crates/biome_module_graph/tests/snap/mod.rs
33
expression: content
44
---
55

6-
# `/src/global.css`
7-
8-
## Source
9-
10-
```css
11-
.layout {
12-
display: flex;
13-
}
14-
.hero {
15-
font-size: 2rem;
16-
}
17-
```
18-
19-
## Module Info
20-
21-
```
22-
Classes {
23-
hero,
24-
layout,
25-
}
26-
Imports {
27-
No imports
28-
}
29-
```
30-
31-
326
# `/src/Hero.astro`
337

348
## Source
@@ -89,3 +63,29 @@ ScriptImports {
8963
No script imports
9064
}
9165
```
66+
67+
68+
# `/src/global.css`
69+
70+
## Source
71+
72+
```css
73+
.layout {
74+
display: flex;
75+
}
76+
.hero {
77+
font-size: 2rem;
78+
}
79+
```
80+
81+
## Module Info
82+
83+
```
84+
Classes {
85+
hero,
86+
layout,
87+
}
88+
Imports {
89+
No imports
90+
}
91+
```

crates/biome_module_graph/tests/snapshots/test_export_default_imported_binding.snap

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,93 +3,93 @@ source: crates/biome_module_graph/tests/snap/mod.rs
33
expression: content
44
---
55

6-
# `/src/index.ts` (Not imported by resolver)
6+
# `/src/foo.ts` (Module 1)
77

88
## Source
99

1010
```ts
11-
import { foo } from "./foo.ts";
12-
13-
export default foo;
11+
/**
12+
* @returns {number}
13+
*/
14+
export function foo(): number {
15+
return 42;
16+
}
1417
```
1518

1619
## Module Info
1720

1821
```
1922
Exports {
20-
"default" => {
21-
ExportOwnExport => JsOwnExport::Binding(22..25)
23+
"foo" => {
24+
ExportOwnExport => JsOwnExport::Binding(94..97)
2225
}
2326
}
2427
Imports {
25-
"foo" => {
26-
Specifier: "./foo.ts"
27-
Resolved path: "/src/foo.ts"
28-
Import Symbol: foo
29-
}
28+
No imports
3029
}
3130
```
3231

3332
## Exported Bindings
3433

3534
```
36-
foo => BindingTypeData {
37-
Types Import Symbol: foo from "/src/foo.ts",
35+
foo => BindingTypeData {
36+
Types Module(0) TypeId(1),
3837
}
3938
```
4039

4140
## Registered types
4241

4342
```
44-
Module TypeId(0) => Import Symbol: foo from "/src/foo.ts"
43+
Module TypeId(0) => number: 42
44+
45+
Module TypeId(1) => sync Function "foo" {
46+
accepts: {
47+
params: []
48+
type_args: []
49+
}
50+
returns: number
51+
}
4552
```
4653

47-
# `/src/foo.ts` (Module 1)
54+
# `/src/index.ts` (Not imported by resolver)
4855

4956
## Source
5057

5158
```ts
52-
/**
53-
* @returns {number}
54-
*/
55-
export function foo(): number {
56-
return 42;
57-
}
59+
import { foo } from "./foo.ts";
60+
61+
export default foo;
5862
```
5963

6064
## Module Info
6165

6266
```
6367
Exports {
64-
"foo" => {
65-
ExportOwnExport => JsOwnExport::Binding(94..97)
68+
"default" => {
69+
ExportOwnExport => JsOwnExport::Binding(22..25)
6670
}
6771
}
6872
Imports {
69-
No imports
73+
"foo" => {
74+
Specifier: "./foo.ts"
75+
Resolved path: "/src/foo.ts"
76+
Import Symbol: foo
77+
}
7078
}
7179
```
7280

7381
## Exported Bindings
7482

7583
```
76-
foo => BindingTypeData {
77-
Types Module(0) TypeId(1),
84+
foo => BindingTypeData {
85+
Types Import Symbol: foo from "/src/foo.ts",
7886
}
7987
```
8088

8189
## Registered types
8290

8391
```
84-
Module TypeId(0) => number: 42
85-
86-
Module TypeId(1) => sync Function "foo" {
87-
accepts: {
88-
params: []
89-
type_args: []
90-
}
91-
returns: number
92-
}
92+
Module TypeId(0) => Import Symbol: foo from "/src/foo.ts"
9393
```
9494

9595
# Module Resolver

crates/biome_module_graph/tests/snapshots/test_jsx_imports_css_file.snap

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,6 @@ source: crates/biome_module_graph/tests/snap/mod.rs
33
expression: content
44
---
55

6-
# `/src/styles.css`
7-
8-
## Source
9-
10-
```css
11-
.button {
12-
color: red;
13-
}
14-
.header {
15-
font-size: 24px;
16-
}
17-
```
18-
19-
## Module Info
20-
21-
```
22-
Classes {
23-
button,
24-
header,
25-
}
26-
Imports {
27-
No imports
28-
}
29-
```
30-
31-
326
# `/src/App.jsx`
337

348
## Source
@@ -74,3 +48,28 @@ App => BindingTypeData {
7448
```
7549
Module TypeId(0) => unknown
7650
```
51+
52+
# `/src/styles.css`
53+
54+
## Source
55+
56+
```css
57+
.button {
58+
color: red;
59+
}
60+
.header {
61+
font-size: 24px;
62+
}
63+
```
64+
65+
## Module Info
66+
67+
```
68+
Classes {
69+
button,
70+
header,
71+
}
72+
Imports {
73+
No imports
74+
}
75+
```

crates/biome_module_graph/tests/snapshots/test_namespace_reexport_type_inference.snap

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,36 @@ source: crates/biome_module_graph/tests/snap/mod.rs
33
expression: content
44
---
55

6+
# `/src/barrel.ts` (Module 1)
7+
8+
## Source
9+
10+
```ts
11+
export * as MyNs from "./source.ts";
12+
```
13+
14+
## Module Info
15+
16+
```
17+
Exports {
18+
"MyNs" => {
19+
ExportOwnExport => JsOwnExport::Namespace(Reexport(
20+
Specifier: "./source.ts"
21+
Resolved path: "/src/source.ts"
22+
Import Symbol: All
23+
Exported range: (0..36)
24+
))
25+
}
26+
}
27+
Imports {
28+
No imports
29+
}
30+
Side-effect imports: [
31+
"./source.ts" => /src/source.ts,
32+
]
33+
```
34+
35+
636
# `/src/index.ts` (Not imported by resolver)
737

838
## Source
@@ -38,36 +68,6 @@ Module TypeId(1) => Module(0) TypeId(0).alpha
3868
Module TypeId(2) => Call Module(0) TypeId(1)(No parameters)
3969
```
4070

41-
# `/src/barrel.ts` (Module 1)
42-
43-
## Source
44-
45-
```ts
46-
export * as MyNs from "./source.ts";
47-
```
48-
49-
## Module Info
50-
51-
```
52-
Exports {
53-
"MyNs" => {
54-
ExportOwnExport => JsOwnExport::Namespace(Reexport(
55-
Specifier: "./source.ts"
56-
Resolved path: "/src/source.ts"
57-
Import Symbol: All
58-
Exported range: (0..36)
59-
))
60-
}
61-
}
62-
Imports {
63-
No imports
64-
}
65-
Side-effect imports: [
66-
"./source.ts" => /src/source.ts,
67-
]
68-
```
69-
70-
7171
# `/src/source.ts` (Module 2)
7272

7373
## Source

0 commit comments

Comments
 (0)