1 | 'use strict';
|
2 |
|
3 | var _process$env$BEEMO_TE;
|
4 |
|
5 | function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
6 |
|
7 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
8 |
|
9 | 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; }
|
10 |
|
11 | Object.defineProperty(exports, '__esModule', {
|
12 | value: true
|
13 | });
|
14 |
|
15 | const common = require('@boost/common');
|
16 |
|
17 | const test = require('@boost/debug/test');
|
18 |
|
19 | require('./index.js');
|
20 |
|
21 | const Driver = require('./Driver.js');
|
22 |
|
23 | const Script = require('./Script.js');
|
24 |
|
25 | const Tool = require('./Tool.js');
|
26 |
|
27 | const ConfigContext = require('./contexts/ConfigContext.js');
|
28 |
|
29 | const DriverContext = require('./contexts/DriverContext.js');
|
30 |
|
31 | const ScriptContext = require('./contexts/ScriptContext.js');
|
32 |
|
33 | const ScaffoldContext = require('./contexts/ScaffoldContext.js');
|
34 |
|
35 | const TEST_ROOT = new common.Path((_process$env$BEEMO_TE = process.env.BEEMO_TEST_ROOT) !== null && _process$env$BEEMO_TE !== void 0 ? _process$env$BEEMO_TE : process.cwd());
|
36 |
|
37 | class TestDriver extends Driver.Driver {
|
38 | constructor(...args) {
|
39 | super(...args);
|
40 | this.name = 'test-driver';
|
41 | }
|
42 |
|
43 | }
|
44 |
|
45 | class TestScript extends Script.Script {
|
46 | constructor(...args) {
|
47 | super(...args);
|
48 | this.name = 'test-script';
|
49 | }
|
50 |
|
51 | execute() {
|
52 | return Promise.resolve();
|
53 | }
|
54 |
|
55 | }
|
56 |
|
57 | function mockConsole(name) {
|
58 | return jest.spyOn(console, name).mockImplementation(() => {});
|
59 | }
|
60 |
|
61 | function mockToolConfig() {
|
62 | return {
|
63 | configure: {
|
64 | cleanup: false,
|
65 | parallel: true
|
66 | },
|
67 | debug: false,
|
68 | drivers: [],
|
69 | execute: {
|
70 | concurrency: 1,
|
71 | graph: true,
|
72 | output: ''
|
73 | },
|
74 | module: '@local',
|
75 | scripts: [],
|
76 | settings: {}
|
77 | };
|
78 | }
|
79 |
|
80 | function mockTool(argv = []) {
|
81 | const tool = new Tool.Tool({
|
82 | argv,
|
83 | cwd: TEST_ROOT
|
84 | });
|
85 |
|
86 | tool.debug = test.mockDebugger();
|
87 | tool.config = mockToolConfig();
|
88 | return tool;
|
89 | }
|
90 |
|
91 | function mockDriver(name, tool = null, metadata = {}) {
|
92 | const driver = new TestDriver();
|
93 |
|
94 | driver.name = name;
|
95 | driver.tool = tool !== null && tool !== void 0 ? tool : mockTool();
|
96 | driver.setMetadata(_objectSpread({
|
97 | bin: name.toLowerCase(),
|
98 | configName: `${name}.json`,
|
99 | title: name
|
100 | }, metadata));
|
101 | return driver;
|
102 | }
|
103 |
|
104 | function mockScript(name, tool = null) {
|
105 | const script = new TestScript();
|
106 |
|
107 | script.name = name;
|
108 | script.tool = tool !== null && tool !== void 0 ? tool : mockTool();
|
109 | return script;
|
110 | }
|
111 |
|
112 | function stubArgs(options, params = []) {
|
113 | return {
|
114 | command: [],
|
115 | errors: [],
|
116 | options,
|
117 | params,
|
118 | rest: [],
|
119 | unknown: {}
|
120 | };
|
121 | }
|
122 |
|
123 | function stubConfigArgs() {
|
124 | return stubArgs({});
|
125 | }
|
126 |
|
127 | function stubDriverArgs(fields) {
|
128 | return stubArgs(_objectSpread({
|
129 | concurrency: 1,
|
130 | graph: false,
|
131 | workspaces: ''
|
132 | }, fields));
|
133 | }
|
134 |
|
135 | function stubScaffoldArgs(fields) {
|
136 | return stubArgs(_objectSpread({
|
137 | dry: false
|
138 | }, fields));
|
139 | }
|
140 |
|
141 | function stubScriptArgs(fields) {
|
142 | return stubArgs(_objectSpread({
|
143 | concurrency: 1,
|
144 | graph: false,
|
145 | workspaces: ''
|
146 | }, fields));
|
147 | }
|
148 |
|
149 | function applyContext(context) {
|
150 | context.args = stubArgs({
|
151 | a: true,
|
152 | foo: 'bar'
|
153 | }, ['baz']);
|
154 | context.argv = ['-a', '--foo', 'bar', 'baz'];
|
155 | context.cwd = TEST_ROOT;
|
156 | context.configModuleRoot = TEST_ROOT;
|
157 | context.workspaceRoot = TEST_ROOT;
|
158 | context.workspaces = [];
|
159 | return context;
|
160 | }
|
161 |
|
162 | function stubConfigContext() {
|
163 | return applyContext(new ConfigContext.ConfigContext(stubArgs({})));
|
164 | }
|
165 |
|
166 | function stubDriverContext(driver) {
|
167 | return applyContext(new DriverContext.DriverContext(stubDriverArgs(), driver !== null && driver !== void 0 ? driver : new TestDriver()));
|
168 | }
|
169 |
|
170 | function stubScriptContext(script) {
|
171 | const context = applyContext(new ScriptContext.ScriptContext(stubScriptArgs(), 'script'));
|
172 |
|
173 | if (script) {
|
174 | context.setScript(script);
|
175 | }
|
176 |
|
177 | return context;
|
178 | }
|
179 |
|
180 | function stubScaffoldContext(generator = 'generator', action = 'action', name = '') {
|
181 | return applyContext(new ScaffoldContext.ScaffoldContext(stubScaffoldArgs(), generator, action, name));
|
182 | }
|
183 |
|
184 | function prependRoot(part) {
|
185 | return TEST_ROOT.append(part);
|
186 | }
|
187 |
|
188 | function getRoot() {
|
189 | return TEST_ROOT;
|
190 | }
|
191 |
|
192 | function stubExecResult(fields) {
|
193 | return _objectSpread({
|
194 | all: '',
|
195 | command: '',
|
196 | escapedCommand: '',
|
197 | exitCode: 0,
|
198 | failed: false,
|
199 | isCanceled: false,
|
200 | killed: false,
|
201 | signal: undefined,
|
202 | stderr: '',
|
203 | stdout: '',
|
204 | timedOut: false
|
205 | }, fields);
|
206 | }
|
207 |
|
208 | Object.defineProperty(exports, 'mockDebugger', {
|
209 | enumerable: true,
|
210 | get: function () {
|
211 | return test.mockDebugger;
|
212 | }
|
213 | });
|
214 | exports.TestDriver = TestDriver;
|
215 | exports.TestScript = TestScript;
|
216 | exports.applyContext = applyContext;
|
217 | exports.getRoot = getRoot;
|
218 | exports.mockConsole = mockConsole;
|
219 | exports.mockDriver = mockDriver;
|
220 | exports.mockScript = mockScript;
|
221 | exports.mockTool = mockTool;
|
222 | exports.mockToolConfig = mockToolConfig;
|
223 | exports.prependRoot = prependRoot;
|
224 | exports.stubArgs = stubArgs;
|
225 | exports.stubConfigArgs = stubConfigArgs;
|
226 | exports.stubConfigContext = stubConfigContext;
|
227 | exports.stubDriverArgs = stubDriverArgs;
|
228 | exports.stubDriverContext = stubDriverContext;
|
229 | exports.stubExecResult = stubExecResult;
|
230 | exports.stubScaffoldArgs = stubScaffoldArgs;
|
231 | exports.stubScaffoldContext = stubScaffoldContext;
|
232 | exports.stubScriptArgs = stubScriptArgs;
|
233 | exports.stubScriptContext = stubScriptContext;
|
234 |
|