snapshot.ts ×12

Frontier kind: Code frontier

unlabeled · c_a45915b4bc6e

100 tests · 5641 LOC · 28 files · introduces 0 tests · 37 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
12 ranges37 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
860 ranges5641 lines · 28 files · Browse complete extent
All tests (intent)
100 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 37 introduced LOC across 12 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/base/test/common/snapshot.ts 37 introduced LOC · 12 ranges

Open complete file

37
38 constructor(private readonly test: Mocha.Test | undefined) {
39 > if (!test) { snapshot.ts
40 throw new Error('assertSnapshot can only be used in a test');
41 }
43 > if (!test.file) {
44 throw new Error('currentTest.file is not set, please open an issue with the test you\'re trying to run');
45 }
47 > const src = URI.joinPath(FileAccess.asFileUri(''), '../src');
48 > const parts = test.file.split(/[/\\]/g);
49 >
50 > this.namePrefix = sanitizeName(test.fullTitle()) + '.';
51 > this.snapshotsDir = URI.joinPath(src, ...[...parts.slice(0, -1), '__snapshots__']);
52 > }
53
54 public async assert(value: unknown, options?: ISnapshotOptions) {
55 > const originalStack = new Error().stack!; // save to make the stack nicer on failure snapshot.ts
56 > const nameOrIndex = (options?.name ? sanitizeName(options.name) : this.nextIndex++);
57 > const fileName = this.namePrefix + nameOrIndex + '.' + (options?.extension || 'snap');
58 > this.usedNames.add(fileName);
59 >
60 > const fpath = URI.joinPath(this.snapshotsDir, fileName).fsPath;
61 > const actual = formatValue(value);
62 > let expected: string;
63 > try {
64 > expected = await __readFileInTests(fpath);
65 > } catch {
66 console.info(`Creating new snapshot in: ${fpath}`);
67 await __mkdirPInTests(this.snapshotsDir.fsPath);
69 return;
70 }
72 > if (normalizeCrlf(expected) !== normalizeCrlf(actual)) {
73 await __writeFileInTests(fpath + '.actual', actual);
74 const err: any = new Error(`Snapshot #${nameOrIndex} does not match expected output`);
84 throw err;
85 }
86 > } snapshot.ts
87
88 public async removeOldSnapshots() {
99 const debugDescriptionSymbol = Symbol.for('debug.description');
100
101 > function formatValue(value: unknown, level = 0, seen: unknown[] = []): string { snapshot.ts
102 > switch (typeof value) {
103 > case 'bigint':
104 > case 'boolean':
105 > case 'number':
106 > case 'symbol':
107 > case 'undefined':
108 return String(value);
109 > case 'string': snapshot.ts
110 return level === 0 ? value : JSON.stringify(value);
111 > case 'function': snapshot.ts
112 return `[Function ${value.name}]`;
113 > case 'object': { snapshot.ts
114 if (value === null) {
115 return 'null';
151 : `{ ${lines.join(',\n')} }`);
152 }
153 > default: snapshot.ts
154 throw new Error(`Unknown type ${value}`);
155 > } snapshot.ts
156 > }
157
158 setup(function () {