Files
yarn/__tests__/util/path.js
Burak Yiğit Kaya 50fc0925d1 Chore: clear no-console warnings from lint (#4036)
**Summary**

After upgrading ESlint, we started seeing a bunch of `no-console`
lint warnings. This patch fixes these or supresses them if necessary.

**Test plan**

Lint should pass without any errors or warnings. All existing tests
should pass.
2017-08-02 12:13:37 +01:00

92 lines
2.4 KiB
JavaScript

/* @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 {expandPath, resolveWithHome} from '../../src/util/path.js';
describe('expandPath', () => {
const realPlatform = process.platform;
describe('!win32', () => {
beforeAll(() => {
process.platform = 'notWin32';
});
afterAll(() => {
process.platform = realPlatform;
});
test('Paths get expanded', () => {
expect(expandPath('~/bar/baz/q')).toEqual('/home/foo/bar/baz/q');
expect(expandPath(' ~/bar/baz')).toEqual('/home/foo/bar/baz');
expect(expandPath('./~/bar/baz')).toEqual('./~/bar/baz');
expect(expandPath('~/~/bar/baz')).toEqual('/home/foo/~/bar/baz');
});
});
describe('win32', () => {
beforeAll(() => {
process.platform = 'win32';
});
afterAll(() => {
process.platform = realPlatform;
});
test('Paths never get expanded', () => {
expect(expandPath('~/bar/baz/q')).toEqual('~/bar/baz/q');
expect(expandPath(' ~/bar/baz')).toEqual(' ~/bar/baz');
expect(expandPath('./~/bar/baz')).toEqual('./~/bar/baz');
expect(expandPath('~/~/bar/baz')).toEqual('~/~/bar/baz');
});
});
});
describe('resolveWithHome', () => {
const realPlatform = process.platform;
describe('!win32', () => {
beforeAll(() => {
process.platform = 'notWin32';
});
afterAll(() => {
process.platform = realPlatform;
});
test('Paths with home are resolved', () => {
expect(resolveWithHome('~/bar/baz/q')).toEqual('RESOLVED ["/home/foo","bar/baz/q"]');
});
});
describe('win32', () => {
beforeAll(() => {
process.platform = 'win32';
});
afterAll(() => {
process.platform = realPlatform;
});
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"]');
});
});