File: path.js

package info (click to toggle)
node-yarnpkg 1.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 92,980 kB
  • sloc: sh: 323; makefile: 19
file content (43 lines) | stat: -rw-r--r-- 1,329 bytes parent folder | download | duplicates (3)
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
/* @flow */

jest.mock('../../src/util/user-home-dir.js', () => ({
  default: '/home/foo',
}));

jest.mock('path', () => {
  const path = jest.genMockFromModule('fs');
  path.resolve = function(): string {
    return 'RESOLVED ' + JSON.stringify(Array.prototype.slice.call(arguments));
  };
  return path;
});

import {resolveWithHome} from '../../src/util/path.js';

describe('resolveWithHome', () => {
  describe('!win32', () => {
    beforeAll(() => {
      Object.defineProperty(process, 'platform', {configurable: true, value: 'notWin32'});
    });

    test('Paths with home are resolved', () => {
      expect(resolveWithHome('~/bar/baz/q')).toEqual('RESOLVED ["/home/foo","bar/baz/q"]');
    });
  });

  describe('win32', () => {
    beforeAll(() => {
      Object.defineProperty(process, 'platform', {configurable: true, value: 'win32'});
    });

    test('Paths with home are resolved', () => {
      expect(resolveWithHome('~/bar/baz/q')).toEqual('RESOLVED ["/home/foo","bar/baz/q"]');
      expect(resolveWithHome('~\\bar\\baz\\q')).toEqual('RESOLVED ["/home/foo","bar\\\\baz\\\\q"]');
    });
  });

  test('Paths without home are resolved', () => {
    expect(resolveWithHome('bar/baz/q')).toEqual('RESOLVED ["bar/baz/q"]');
    expect(resolveWithHome('/bar/baz/q')).toEqual('RESOLVED ["/bar/baz/q"]');
  });
});