File: rc.js

package info (click to toggle)
node-yarnpkg 1.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 92,980 kB
  • sloc: sh: 323; makefile: 19
file content (56 lines) | stat: -rw-r--r-- 1,925 bytes parent folder | download
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
44
45
46
47
48
49
50
51
52
53
54
55
56
/* @flow */

import {getRcArgs} from '../src/rc.js';
import * as path from 'path';

const fixturesLoc = path.join(__dirname, 'fixtures', 'rc');

test('resolve .yarnrc args and use --cwd if present', () => {
  const args = getRcArgs('install', ['--cwd', path.join(fixturesLoc, 'empty')]);
  expect(args.indexOf('--foo') !== -1).toBe(true);
});

test("don't resolve .yarnrc args from the default locations when using --no-default-rc", () => {
  const args = getRcArgs('install', ['--cwd', path.join(fixturesLoc, 'empty'), '--no-default-rc']);
  expect(args.indexOf('--foo') !== -1).toBe(false);
});

test('resolve .yarnrc args from the extraneous locations when using --use-yarnrc', () => {
  const args = getRcArgs('install', [
    '--cwd',
    path.join(fixturesLoc, 'empty'),
    '--no-default-rc',
    '--use-yarnrc',
    path.join(fixturesLoc, 'empty', '.yarnrc'),
  ]);
  expect(args.indexOf('--foo') !== -1).toBe(true);
});

test('resolve .yarnrc args and use process.cwd() if no --cwd present', () => {
  const cwd = process.cwd();
  process.chdir(path.join(fixturesLoc, 'empty'));

  try {
    const args = getRcArgs('install', []);
    expect(args.indexOf('--foo') !== -1).toBe(true);
  } finally {
    process.chdir(cwd);
  }
});

test('resolve .yarnrc args and handle --cwd arg inside .yarnrc', () => {
  const args = getRcArgs('install', ['--cwd', path.join(fixturesLoc, 'inside')]);
  expect(args.indexOf('--foo') !== -1).toBe(true);
});

test('resolve .yarnrc args and bail out of recursive --cwd args inside of .yarnrc', () => {
  expect(() => {
    getRcArgs('install', ['--cwd', path.join(fixturesLoc, 'recursive')]);
  }).toThrowError();
});

test('resolve .yarnrc args and adds command name prefixed arguments', () => {
  const args = getRcArgs('add', ['--cwd', path.join(fixturesLoc, 'prefixed')]);
  expect(args.indexOf('--foo') !== -1).toBe(true);
  expect(args.indexOf('--bar') !== -1).toBe(false);
});