forked from olton/Metro-UI-CSS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-tests.js
54 lines (48 loc) · 1.27 KB
/
generate-tests.js
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
import fs from "fs";
import * as path from "path";
const readFiles = (dirname, onFile, onError = () => {}) => {
fs.readdir(dirname, function(err, filenames) {
if (err) {
onError(err);
return;
}
filenames.forEach(function(filename) {
fs.readFile(dirname + filename, 'utf-8', function(err, content) {
if (err) {
onError(err);
return;
}
onFile(filename, content);
});
});
});
}
const sourceDir = './tests/'
const targetDir = './cypress/e2e/'
const test = `
describe('Test $file', () => {
it('passes', () => {
cy.visit('tests/$file')
})
})
`
fs.readdir(targetDir, (err, files) => {
if (err) throw err;
for (const file of files) {
fs.unlink(path.join(targetDir, file), (err) => {
if (err) throw err;
});
}
});
readFiles(sourceDir, (filename, content) => {
const [name, _] = filename.split(".")
fs.writeFile(`${targetDir}/${name}.cy.js`, `${test.replaceAll('$file', filename)}`, function (error) {
if (error) {
throw error;
} else {
console.log(`File ${filename} created`);
}
});
}, (e) => {
console.log(e)
})