diff options
Diffstat (limited to 'packages/main/src/infrastructure/config/impl')
-rw-r--r-- | packages/main/src/infrastructure/config/impl/__tests__/ConfigFile.integ.test.ts | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/packages/main/src/infrastructure/config/impl/__tests__/ConfigFile.integ.test.ts b/packages/main/src/infrastructure/config/impl/__tests__/ConfigFile.integ.test.ts index dd4aaaa..c443d99 100644 --- a/packages/main/src/infrastructure/config/impl/__tests__/ConfigFile.integ.test.ts +++ b/packages/main/src/infrastructure/config/impl/__tests__/ConfigFile.integ.test.ts | |||
@@ -29,10 +29,11 @@ import { | |||
29 | utimes, | 29 | utimes, |
30 | writeFile, | 30 | writeFile, |
31 | } from 'node:fs/promises'; | 31 | } from 'node:fs/promises'; |
32 | import { tmpdir } from 'node:os'; | 32 | import { platform, tmpdir, userInfo } from 'node:os'; |
33 | import path from 'node:path'; | 33 | import path from 'node:path'; |
34 | 34 | ||
35 | import { jest } from '@jest/globals'; | 35 | import { jest } from '@jest/globals'; |
36 | import { testIf } from '@sophie/test-utils'; | ||
36 | import { mocked } from 'jest-mock'; | 37 | import { mocked } from 'jest-mock'; |
37 | 38 | ||
38 | import Disposer from '../../../../utils/Disposer.js'; | 39 | import Disposer from '../../../../utils/Disposer.js'; |
@@ -249,19 +250,24 @@ describe('watchConfig', () => { | |||
249 | expect(callback).toHaveBeenCalled(); | 250 | expect(callback).toHaveBeenCalled(); |
250 | }); | 251 | }); |
251 | 252 | ||
252 | test('handles other filesystem errors', async () => { | 253 | // We can only cause a filesystem error by changing permissions if we run on a POSIX-like |
253 | const { mode } = await stat(userDataDir!); | 254 | // system and we aren't root (i.e., not in CI). |
254 | await writeFile(configFilePath, 'Hi Mars!', 'utf8'); | 255 | testIf(platform() !== 'win32' && userInfo().uid !== 0)( |
255 | // Remove permission to force a filesystem error. | 256 | 'handles other filesystem errors', |
256 | // eslint-disable-next-line no-bitwise -- Compute reduced permissions. | 257 | async () => { |
257 | await chmod(userDataDir!, mode & 0o666); | 258 | const { mode } = await stat(userDataDir!); |
258 | try { | 259 | await writeFile(configFilePath, 'Hi Mars!', 'utf8'); |
259 | await catchUpWithFilesystem(); | 260 | // Remove permission to force a filesystem error. |
260 | expect(callback).not.toHaveBeenCalled(); | 261 | // eslint-disable-next-line no-bitwise -- Compute reduced permissions. |
261 | } finally { | 262 | await chmod(userDataDir!, mode & 0o666); |
262 | await chmod(userDataDir!, mode); | 263 | try { |
263 | } | 264 | await catchUpWithFilesystem(); |
264 | }); | 265 | expect(callback).not.toHaveBeenCalled(); |
266 | } finally { | ||
267 | await chmod(userDataDir!, mode); | ||
268 | } | ||
269 | }, | ||
270 | ); | ||
265 | 271 | ||
266 | test('does not notify when the modification date is prior to the last write', async () => { | 272 | test('does not notify when the modification date is prior to the last write', async () => { |
267 | await repository.writeConfig('Hello World!'); | 273 | await repository.writeConfig('Hello World!'); |