flock-import.js 894 B

12345678910111213141516171819202122
  1. /** A separate process keeps unsupported-platform simulation away from other tests. */
  2. import assert from 'node:assert/strict';
  3. const platform = process.argv[2];
  4. const descriptor = Object.getOwnPropertyDescriptor(process, 'platform');
  5. try {
  6. if (platform) Object.defineProperty(process, 'platform', { value: platform });
  7. const { tryLockExclusive } = await import('../../packages/entry/lib/flock.js');
  8. assert.equal(typeof tryLockExclusive, 'function');
  9. if (platform || (process.platform !== 'linux' && process.platform !== 'darwin')) {
  10. await assert.rejects(tryLockExclusive(-1), {
  11. code: 'ERR_FLOCK_UNSUPPORTED_PLATFORM',
  12. syscall: 'flock',
  13. });
  14. }
  15. } finally {
  16. Object.defineProperty(process, 'platform', descriptor);
  17. }
  18. await new Promise((resolve, reject) => {
  19. process.send({ type: 'ready' }, (error) => error ? reject(error) : resolve());
  20. });
  21. process.disconnect();