spec-helper-platform.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const path = require('path');
  2. const fs = require('fs-plus');
  3. // # Platform specific helpers
  4. module.exports = {
  5. // Public: Returns true if being run from within Windows
  6. isWindows() {
  7. return !!process.platform.match(/^win/);
  8. },
  9. // Public: Some files can not exist on Windows filesystems, so we have to
  10. // selectively generate our fixtures.
  11. //
  12. // Returns nothing.
  13. generateEvilFiles() {
  14. let filenames;
  15. const evilFilesPath = path.join(__dirname, 'fixtures', 'evil-files');
  16. if (fs.existsSync(evilFilesPath)) {
  17. fs.removeSync(evilFilesPath);
  18. }
  19. fs.mkdirSync(evilFilesPath);
  20. if (this.isWindows()) {
  21. filenames = [
  22. 'a_file_with_utf8.txt',
  23. 'file with spaces.txt',
  24. 'utfa\u0306.md'
  25. ];
  26. } else {
  27. filenames = [
  28. 'a_file_with_utf8.txt',
  29. 'file with spaces.txt',
  30. 'goddam\nnewlines',
  31. 'quote".txt',
  32. 'utfa\u0306.md'
  33. ];
  34. }
  35. filenames.map(filename =>
  36. fs.writeFileSync(path.join(evilFilesPath, filename), 'evil file!', {
  37. flag: 'w'
  38. })
  39. );
  40. }
  41. };