UNPKG

2.2 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6exports.default = relativePath;
7
8function path() {
9 const data = _interopRequireWildcard(require('path'));
10
11 path = function () {
12 return data;
13 };
14
15 return data;
16}
17
18function _getRequireWildcardCache(nodeInterop) {
19 if (typeof WeakMap !== 'function') return null;
20 var cacheBabelInterop = new WeakMap();
21 var cacheNodeInterop = new WeakMap();
22 return (_getRequireWildcardCache = function (nodeInterop) {
23 return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
24 })(nodeInterop);
25}
26
27function _interopRequireWildcard(obj, nodeInterop) {
28 if (!nodeInterop && obj && obj.__esModule) {
29 return obj;
30 }
31 if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
32 return {default: obj};
33 }
34 var cache = _getRequireWildcardCache(nodeInterop);
35 if (cache && cache.has(obj)) {
36 return cache.get(obj);
37 }
38 var newObj = {};
39 var hasPropertyDescriptor =
40 Object.defineProperty && Object.getOwnPropertyDescriptor;
41 for (var key in obj) {
42 if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) {
43 var desc = hasPropertyDescriptor
44 ? Object.getOwnPropertyDescriptor(obj, key)
45 : null;
46 if (desc && (desc.get || desc.set)) {
47 Object.defineProperty(newObj, key, desc);
48 } else {
49 newObj[key] = obj[key];
50 }
51 }
52 }
53 newObj.default = obj;
54 if (cache) {
55 cache.set(obj, newObj);
56 }
57 return newObj;
58}
59
60/**
61 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
62 *
63 * This source code is licensed under the MIT license found in the
64 * LICENSE file in the root directory of this source tree.
65 */
66function relativePath(config, testPath) {
67 // this function can be called with ProjectConfigs or GlobalConfigs. GlobalConfigs
68 // do not have config.cwd, only config.rootDir. Try using config.cwd, fallback
69 // to config.rootDir. (Also, some unit just use config.rootDir, which is ok)
70 testPath = path().relative(config.cwd || config.rootDir, testPath);
71 const dirname = path().dirname(testPath);
72 const basename = path().basename(testPath);
73 return {
74 basename,
75 dirname
76 };
77}