-
Notifications
You must be signed in to change notification settings - Fork 682
Expand file tree
/
Copy pathvalidateSnapshots.ts
More file actions
37 lines (34 loc) · 1.53 KB
/
validateSnapshots.ts
File metadata and controls
37 lines (34 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
/// <reference types="node" />
import * as fs from 'node:fs';
import * as path from 'node:path';
export function getScssFiles(): string[] {
const srcFolder: string = path.join(__dirname, '../../src');
const sourceFiles: string[] = fs
.readdirSync(srcFolder, { withFileTypes: true })
.filter((file: fs.Dirent) => {
const { name } = file;
return file.isFile() && !name.startsWith('_') && (name.endsWith('.sass') || name.endsWith('.scss'));
})
.map((dirent) => dirent.name);
return sourceFiles;
}
export function validateSnapshots(dir: string, fileName: string): void {
const originalExt: string = path.extname(fileName);
const basename: string = path.basename(fileName, originalExt) + '.';
const files: fs.Dirent[] = fs.readdirSync(dir, { withFileTypes: true });
const filteredFiles: fs.Dirent[] = files.filter((file: fs.Dirent) => {
return file.isFile() && file.name.startsWith(basename);
});
expect(filteredFiles.map((x) => x.name)).toMatchSnapshot(`files`);
filteredFiles.forEach((file: fs.Dirent) => {
if (!file.isFile() || !file.name.startsWith(basename)) {
return;
}
const filePath: string = path.join(dir, file.name);
const fileContents: string = fs.readFileSync(filePath, 'utf8');
const normalizedFileContents: string = fileContents.replace(/\r/gm, '');
expect(normalizedFileContents).toMatchSnapshot(`${file.name}`);
});
}