Skip to content

Commit 15d367a

Browse files
committed
test(linter/plugins): avoid using scope constructor names in test snapshot (#15906)
Contents of this test snapshot depends on the constructor names of scope class instances. This is a little fragile, as they can change depending on how the code is bundled (see #15861 (comment)). At some point, we'll full minify the bundle, at which point class names will be come random gibberish like `e`, `t`, `aZ`, etc. Avoid this problem by outputting `type` field of scope objects instead.
1 parent 6d14c8b commit 15d367a

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

apps/oxlint/test/fixtures/scope_manager/output.snap.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,19 @@
33

44
# stdout
55
```
6-
x scope-manager-plugin(scope): File has 12 scopes: <GlobalScope>, <ModuleScope>, topLevelFunction, <BlockScope>, TopLevelModule, GenericInterface, TestClass, <ClassStaticBlockScope>,
7-
| <FunctionScope>, <FunctionScope>, <BlockScope>, <BlockScope>
6+
x scope-manager-plugin(scope): File has 12 scopes:
7+
| - global
8+
| - module
9+
| - function(topLevelFunction)
10+
| - block
11+
| - tsModule(TopLevelModule)
12+
| - type(GenericInterface)
13+
| - class(TestClass)
14+
| - class-static-block
15+
| - function
16+
| - function
17+
| - block
18+
| - block
819
,-[files/index.ts:1:1]
920
1 | const { a, b, c } = {};
1021
: ^

apps/oxlint/test/fixtures/scope_manager/plugin.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ const rule: Rule = {
2424
assert.equal(moduleScope.upper, scopeManager.globalScope);
2525

2626
context.report({
27-
message: `File has ${scopeManager.scopes.length} scopes: ${scopeManager.scopes
28-
.map((s: any) => s.block?.id?.name ?? '<' + s.constructor.name + '>')
29-
.join(', ')}`,
27+
message:
28+
`File has ${scopeManager.scopes.length} scopes:\n- ` +
29+
scopeManager.scopes
30+
.map((s: any) => {
31+
const name = s.block?.id?.name;
32+
return name ? `${s.type}(${name})` : `${s.type}`;
33+
})
34+
.join('\n- '),
3035
node: SPAN,
3136
});
3237

0 commit comments

Comments
 (0)