-
-
Notifications
You must be signed in to change notification settings - Fork 131
/
spec-helper-platform.js
45 lines (41 loc) · 1.07 KB
/
spec-helper-platform.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
const path = require('path');
const fs = require('fs-plus');
// # Platform specific helpers
module.exports = {
// Public: Returns true if being run from within Windows
isWindows() {
return !!process.platform.match(/^win/);
},
// Public: Some files can not exist on Windows filesystems, so we have to
// selectively generate our fixtures.
//
// Returns nothing.
generateEvilFiles() {
let filenames;
const evilFilesPath = path.join(__dirname, 'fixtures', 'evil-files');
if (fs.existsSync(evilFilesPath)) {
fs.removeSync(evilFilesPath);
}
fs.mkdirSync(evilFilesPath);
if (this.isWindows()) {
filenames = [
'a_file_with_utf8.txt',
'file with spaces.txt',
'utfa\u0306.md'
];
} else {
filenames = [
'a_file_with_utf8.txt',
'file with spaces.txt',
'goddam\nnewlines',
'quote".txt',
'utfa\u0306.md'
];
}
filenames.map(filename =>
fs.writeFileSync(path.join(evilFilesPath, filename), 'evil file!', {
flag: 'w'
})
);
}
};