atom-paths-spec.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /** @babel */
  2. import { remote } from 'electron';
  3. import atomPaths from '../src/atom-paths';
  4. import fs from 'fs-plus';
  5. import path from 'path';
  6. const app = remote.app;
  7. const temp = require('temp').track();
  8. describe('AtomPaths', () => {
  9. const portableAtomHomePath = path.join(
  10. atomPaths.getAppDirectory(),
  11. '..',
  12. '.atom'
  13. );
  14. afterEach(() => {
  15. atomPaths.setAtomHome(app.getPath('home'));
  16. });
  17. describe('SetAtomHomePath', () => {
  18. describe('when a portable .atom folder exists', () => {
  19. beforeEach(() => {
  20. delete process.env.ATOM_HOME;
  21. if (!fs.existsSync(portableAtomHomePath)) {
  22. fs.mkdirSync(portableAtomHomePath);
  23. }
  24. });
  25. afterEach(() => {
  26. delete process.env.ATOM_HOME;
  27. fs.removeSync(portableAtomHomePath);
  28. });
  29. /**
  30. * TODO: FAILING TEST - This test fails with the following output:
  31. * Expected '/home/runner/.pulsar' to equal '/home/runner/work/pulsar/pulsar/node_modules/electron/.atom'
  32. */
  33. xit('sets ATOM_HOME to the portable .atom folder if it has permission', () => {
  34. atomPaths.setAtomHome(app.getPath('home'));
  35. expect(process.env.ATOM_HOME).toEqual(portableAtomHomePath);
  36. });
  37. it('uses ATOM_HOME if no write access to portable .atom folder', () => {
  38. if (process.platform === 'win32') return;
  39. const readOnlyPath = temp.mkdirSync('atom-path-spec-no-write-access');
  40. process.env.ATOM_HOME = readOnlyPath;
  41. fs.chmodSync(portableAtomHomePath, 444);
  42. atomPaths.setAtomHome(app.getPath('home'));
  43. expect(process.env.ATOM_HOME).toEqual(readOnlyPath);
  44. });
  45. });
  46. describe('when a portable folder does not exist', () => {
  47. beforeEach(() => {
  48. delete process.env.ATOM_HOME;
  49. fs.removeSync(portableAtomHomePath);
  50. });
  51. afterEach(() => {
  52. delete process.env.ATOM_HOME;
  53. });
  54. it('leaves ATOM_HOME unmodified if it was already set', () => {
  55. const temporaryHome = temp.mkdirSync('atom-spec-setatomhomepath');
  56. process.env.ATOM_HOME = temporaryHome;
  57. atomPaths.setAtomHome(app.getPath('home'));
  58. expect(process.env.ATOM_HOME).toEqual(temporaryHome);
  59. });
  60. /**
  61. * TODO: FAILING TEST - This test fails with the following output:
  62. * Expected '/home/runner/.pulsar' to equal '/home/runner/work/pulsar/pulsar/node_modules/electron/.atom'
  63. */
  64. xit('sets ATOM_HOME to a default location if not yet set', () => {
  65. const expectedPath = path.join(app.getPath('home'), '.atom');
  66. atomPaths.setAtomHome(app.getPath('home'));
  67. expect(process.env.ATOM_HOME).toEqual(expectedPath);
  68. });
  69. });
  70. });
  71. describe('setUserData', () => {
  72. let tempAtomConfigPath = null;
  73. let tempAtomHomePath = null;
  74. let electronUserDataPath = null;
  75. let defaultElectronUserDataPath = null;
  76. beforeEach(() => {
  77. defaultElectronUserDataPath = app.getPath('userData');
  78. delete process.env.ATOM_HOME;
  79. tempAtomHomePath = temp.mkdirSync('atom-paths-specs-userdata-home');
  80. tempAtomConfigPath = path.join(tempAtomHomePath, '.atom');
  81. fs.mkdirSync(tempAtomConfigPath);
  82. electronUserDataPath = path.join(tempAtomConfigPath, 'electronUserData');
  83. atomPaths.setAtomHome(tempAtomHomePath);
  84. });
  85. afterEach(() => {
  86. delete process.env.ATOM_HOME;
  87. fs.removeSync(electronUserDataPath);
  88. try {
  89. temp.cleanupSync();
  90. } catch (e) {
  91. // Ignore
  92. }
  93. app.setPath('userData', defaultElectronUserDataPath);
  94. });
  95. describe('when an electronUserData folder exists', () => {
  96. /**
  97. * TODO: FAILING TEST - This test fails with the following output:
  98. * Expected '/tmp/atom-test-data2022824-26037-orl5og.n4n0b' to equal '/tmp/atom-paths-specs-userdata-home2022824-26084-14syl0h.bmd6/.atom/electronUserData'.
  99. */
  100. xit('sets userData path to the folder if it has permission', () => {
  101. fs.mkdirSync(electronUserDataPath);
  102. atomPaths.setUserData(app);
  103. expect(app.getPath('userData')).toEqual(electronUserDataPath);
  104. });
  105. it('leaves userData unchanged if no write access to electronUserData folder', () => {
  106. if (process.platform === 'win32') return;
  107. fs.mkdirSync(electronUserDataPath);
  108. fs.chmodSync(electronUserDataPath, 444);
  109. atomPaths.setUserData(app);
  110. fs.chmodSync(electronUserDataPath, 666);
  111. expect(app.getPath('userData')).toEqual(defaultElectronUserDataPath);
  112. });
  113. });
  114. describe('when an electronUserDataPath folder does not exist', () => {
  115. it('leaves userData app path unchanged', () => {
  116. atomPaths.setUserData(app);
  117. expect(app.getPath('userData')).toEqual(defaultElectronUserDataPath);
  118. });
  119. });
  120. });
  121. });