执行过npm install命令的vue-element-admin源码
康凯
2022-05-20 aa4c235a8ca67ea8b731f90c951a465e92c0a865
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
'use strict';
 
Object.defineProperty(exports, '__esModule', {
  value: true
});
exports.default = void 0;
 
function _path() {
  const data = _interopRequireDefault(require('path'));
 
  _path = function _path() {
    return data;
  };
 
  return data;
}
 
function _util() {
  const data = _interopRequireDefault(require('util'));
 
  _util = function _util() {
    return data;
  };
 
  return data;
}
 
function _exit() {
  const data = _interopRequireDefault(require('exit'));
 
  _exit = function _exit() {
    return data;
  };
 
  return data;
}
 
function _nodeNotifier() {
  const data = _interopRequireDefault(require('node-notifier'));
 
  _nodeNotifier = function _nodeNotifier() {
    return data;
  };
 
  return data;
}
 
var _base_reporter = _interopRequireDefault(require('./base_reporter'));
 
function _interopRequireDefault(obj) {
  return obj && obj.__esModule ? obj : {default: obj};
}
 
function _slicedToArray(arr, i) {
  return (
    _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest()
  );
}
 
function _nonIterableRest() {
  throw new TypeError('Invalid attempt to destructure non-iterable instance');
}
 
function _iterableToArrayLimit(arr, i) {
  var _arr = [];
  var _n = true;
  var _d = false;
  var _e = undefined;
  try {
    for (
      var _i = arr[Symbol.iterator](), _s;
      !(_n = (_s = _i.next()).done);
      _n = true
    ) {
      _arr.push(_s.value);
      if (i && _arr.length === i) break;
    }
  } catch (err) {
    _d = true;
    _e = err;
  } finally {
    try {
      if (!_n && _i['return'] != null) _i['return']();
    } finally {
      if (_d) throw _e;
    }
  }
  return _arr;
}
 
function _arrayWithHoles(arr) {
  if (Array.isArray(arr)) return arr;
}
 
function _defineProperty(obj, key, value) {
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true
    });
  } else {
    obj[key] = value;
  }
  return obj;
}
 
const isDarwin = process.platform === 'darwin';
 
const icon = _path().default.resolve(__dirname, '../assets/jest_logo.png');
 
class NotifyReporter extends _base_reporter.default {
  constructor(globalConfig, startRun, context) {
    super();
 
    _defineProperty(this, '_startRun', void 0);
 
    _defineProperty(this, '_globalConfig', void 0);
 
    _defineProperty(this, '_context', void 0);
 
    this._globalConfig = globalConfig;
    this._startRun = startRun;
    this._context = context;
  }
 
  onRunComplete(contexts, result) {
    const success =
      result.numFailedTests === 0 && result.numRuntimeErrorTestSuites === 0;
    const firstContext = contexts.values().next();
    const hasteFS =
      firstContext && firstContext.value && firstContext.value.hasteFS;
    let packageName;
 
    if (hasteFS != null) {
      // assuming root package.json is the first one
      const _hasteFS$matchFiles = hasteFS.matchFiles('package.json'),
        _hasteFS$matchFiles2 = _slicedToArray(_hasteFS$matchFiles, 1),
        filePath = _hasteFS$matchFiles2[0];
 
      packageName =
        filePath != null
          ? hasteFS.getModuleName(filePath)
          : this._globalConfig.rootDir;
    } else {
      packageName = this._globalConfig.rootDir;
    }
 
    packageName = packageName != null ? `${packageName} - ` : '';
    const notifyMode = this._globalConfig.notifyMode;
    const statusChanged =
      this._context.previousSuccess !== success || this._context.firstRun;
    const testsHaveRun = result.numTotalTests !== 0;
 
    if (
      testsHaveRun &&
      success &&
      (notifyMode === 'always' ||
        notifyMode === 'success' ||
        notifyMode === 'success-change' ||
        (notifyMode === 'change' && statusChanged) ||
        (notifyMode === 'failure-change' && statusChanged))
    ) {
      const title = _util().default.format('%s%d%% Passed', packageName, 100);
 
      const message = _util().default.format(
        (isDarwin ? '\u2705 ' : '') + '%d tests passed',
        result.numPassedTests
      );
 
      _nodeNotifier().default.notify({
        icon,
        message,
        title
      });
    } else if (
      testsHaveRun &&
      !success &&
      (notifyMode === 'always' ||
        notifyMode === 'failure' ||
        notifyMode === 'failure-change' ||
        (notifyMode === 'change' && statusChanged) ||
        (notifyMode === 'success-change' && statusChanged))
    ) {
      const failed = result.numFailedTests / result.numTotalTests;
 
      const title = _util().default.format(
        '%s%d%% Failed',
        packageName,
        Math.ceil(Number.isNaN(failed) ? 0 : failed * 100)
      );
 
      const message = _util().default.format(
        (isDarwin ? '\u26D4\uFE0F ' : '') + '%d of %d tests failed',
        result.numFailedTests,
        result.numTotalTests
      );
 
      const watchMode = this._globalConfig.watch || this._globalConfig.watchAll;
      const restartAnswer = 'Run again';
      const quitAnswer = 'Exit tests';
 
      if (!watchMode) {
        _nodeNotifier().default.notify({
          icon,
          message,
          title
        });
      } else {
        _nodeNotifier().default.notify(
          {
            actions: [restartAnswer, quitAnswer],
            closeLabel: 'Close',
            icon,
            message,
            timeout: 10,
            title
          },
          (err, _, metadata) => {
            if (err || !metadata) {
              return;
            }
 
            if (metadata.activationValue === quitAnswer) {
              (0, _exit().default)(0);
              return;
            }
 
            if (metadata.activationValue === restartAnswer) {
              this._startRun(this._globalConfig);
            }
          }
        );
      }
    }
 
    this._context.previousSuccess = success;
    this._context.firstRun = false;
  }
}
 
exports.default = NotifyReporter;