forked from bitrix-tools/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.bootstrap.js
104 lines (87 loc) · 2.65 KB
/
test.bootstrap.js
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
import {JSDOM} from 'jsdom';
import mocha from 'mocha';
import assert from 'assert';
import * as sinon from 'sinon';
import {resolve, join} from 'path';
import {existsSync} from 'fs';
import resolvePackageModule from './utils/resolve-package-module';
global.sinon = sinon;
global.assert = assert;
global.describe = mocha.describe;
global.it = mocha.it;
global.xit = mocha.xit;
global.before = mocha.before;
global.beforeEach = mocha.beforeEach;
global.after = mocha.after;
global.afterEach = mocha.afterEach;
global.setup = mocha.setup;
global.suite = mocha.suite;
global.suiteSetup = mocha.suiteSetup;
global.suiteTeardown = mocha.suiteTeardown;
global.teardown = mocha.teardown;
global.test = mocha.test;
global.run = mocha.run;
const DOM = new JSDOM('', {
url: 'https://example.org/',
referrer: 'https://example.com/',
contentType: 'text/html',
includeNodeLocations: true,
storageQuota: 10000000,
});
global.window = DOM.window;
global.document = DOM.window.document;
global.Node = DOM.window.Node;
global.Element = DOM.window.Element;
global.DOMParser = DOM.window.DOMParser;
Object.keys(DOM.window).forEach((property) => {
if (typeof global[property] === 'undefined') {
global[property] = DOM.window[property];
}
});
global.navigator = {
userAgent: 'node.js',
};
require('../public/babel-regenerator-runtime');
require.extensions['.css'] = () => null;
require.extensions['.png'] = () => null;
require.extensions['.jpg'] = () => null;
function moduleResolver(sourcePath, currentFile) {
const exp = /(^\w+)\.(.*)/;
const root = currentFile.split('modules')[0];
if (exp.test(sourcePath)) {
const modulesPath = resolve(root, 'modules');
const splitedName = sourcePath.split('.');
const moduleName = splitedName.shift();
const moduleJsPath = resolve(modulesPath, moduleName, 'install', 'js', moduleName);
const extPath = resolve(moduleJsPath, join(...splitedName));
const configPath = resolve(extPath, 'bundle.config.js');
if (existsSync(configPath)) {
// eslint-disable-next-line
const config = require(configPath);
return resolve(extPath, config.input);
}
}
return '';
}
require('@babel/register')({
cwd: (() => {
const cwd = process.cwd();
if (cwd.includes('/modules')) {
return cwd.split('/modules')[0];
}
if (cwd.includes('/bitrix')) {
return cwd.split('/bitrix')[0];
}
return resolve(cwd, '../../../../../');
})(),
presets: [
resolvePackageModule('@babel/preset-env'),
],
plugins: [
[resolvePackageModule('babel-plugin-module-resolver'), {
resolvePath: moduleResolver,
}],
resolvePackageModule('@babel/plugin-transform-flow-strip-types'),
resolvePackageModule('@babel/plugin-proposal-class-properties'),
],
});