-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcypress.config.ts
74 lines (62 loc) · 1.79 KB
/
cypress.config.ts
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { defineConfig } from 'cypress';
import fs from 'fs';
import fm from 'front-matter';
import path from 'path';
// Cypress configuration options
interface returnObjectType {
name: string;
title: string;
slug: string;
subtitle: string;
}
interface FrontMatter {
attributes: {
title: string;
slug: string;
subtitle: string;
};
}
export default defineConfig({
e2e: {
baseUrl: `http://localhost:3000`,
supportFile: false,
setupNodeEvents: (on, _config) => {
on(`task`, {
async projectRootFolder() {
return new Promise((resolve, _reject) => {
resolve(fs.realpathSync(__dirname));
});
},
readFrontMatter(folderPath) {
return new Promise((resolve, _reject) => {
const combinePath = (rp: string, sp: string) => {
return `${rp}${process.platform === `win32` ? `\\` : `/`}${sp}`;
};
const filesObj = fs.readdirSync(folderPath, {
withFileTypes: true,
});
const filesArray: any = [];
filesObj.forEach(async (item) => {
const fileObject: returnObjectType = {
name: item.name,
title: ``,
slug: ``,
subtitle: ``,
};
const data = fs.readFileSync(
combinePath(folderPath, item.name),
`utf8`,
);
const content: FrontMatter = fm(data);
fileObject.title = content.attributes.title;
fileObject.slug = path.parse(item.name).name;
fileObject.subtitle = content.attributes.subtitle;
filesArray.push(fileObject);
});
resolve(filesArray);
});
},
});
},
},
});