Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce complexity #85

Merged
merged 2 commits into from
Aug 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 9 additions & 55 deletions cli/rootsuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const chrome = require('sinon-chrome');
const chai = require('chai');
const argv = require('yargs').argv;
const texts = require('./texts').xtTest;
const enableWatch = argv.watch;

/**
* Create sinon sandbox
Expand Down Expand Up @@ -49,9 +50,7 @@ before(function () {
* After each test -
* reset chrome and sandbox
*/
// eslint-disable-next-line no-undef
afterEach(function () {
// noinspection JSUnresolvedFunction
chrome.flush();
sandbox.restore();
});
Expand All @@ -60,11 +59,9 @@ afterEach(function () {
* After all tests -
* Clean up everything that was initially set up
*/
// eslint-disable-next-line no-undef
after(function () {
// important!
// do not clean when running in watch mode
if (argv.watch) return;
// important! do not clean when running in watch mode
if (enableWatch) return;

delete global.jsdom;
delete global.sinon;
Expand All @@ -83,54 +80,14 @@ after(function () {
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent}
*
* @param {String} type - event type
* @param {number} sx - screen X coordinate
* @param {number} sy - screen Y coordinate
* @param {number} cx - client X coordinate
* @param {number} cy - client Y coordinate
* @param {Object} props - optional properties
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent}
* @return {Event} - the event
*/
global.mouseEvent = function (type, sx, sy, cx, cy) {
let _event;

const e = {
bubbles: true,
cancelable: (type !== 'mousemove'),
view: window,
detail: 0,
screenX: sx,
screenY: sy,
clientX: cx,
clientY: cy,
ctrlKey: false,
altKey: false,
shiftKey: false,
metaKey: false,
button: 0,
relatedTarget: undefined
};

if (typeof (document.createEvent) === 'function') {
_event = document.createEvent('MouseEvents');
_event.initMouseEvent(type,
e.bubbles, e.cancelable, e.view, e.detail,
e.screenX, e.screenY, e.clientX, e.clientY,
e.ctrlKey, e.altKey, e.shiftKey, e.metaKey,
e.button, document.body.parentNode);
} else {
// noinspection JSUnresolvedVariable
if (document.createEventObject) {
_event = document.createEventObject();
for (const prop in e) {
_event[prop] = e[prop];
}
_event.button = {0: 1, 1: 4, 2: 2}[_event.button] ||
_event.button;
}
}
return _event;
global.mouseEvent = function (type, props) {
return new MouseEvent(type, {...props});
};

// noinspection JSValidateTypes
/**
* Enable dispatching an event on some DOM element during unit testing
*
Expand All @@ -141,11 +98,8 @@ global.mouseEvent = function (type, sx, sy, cx, cy) {
global.dispatchEvent = function (target, event) {
if (target.dispatchEvent) {
target.dispatchEvent(event);
} else {
// noinspection JSUnresolvedVariable
if (target.fireEvent) {
target.fireEvent('on' + event.type, event);
}
} else if (target.fireEvent) {
target.fireEvent('on' + event.type, event);
}
return event;
};
34 changes: 24 additions & 10 deletions cli/xt-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,50 @@ program
.parse(process.argv);

const {watch, env: programEnv, config, platform: platformEnv} = program.opts();
const spinner = new Spinner(' %s ');

spinner.start();

const proc = exec([

const args = [
// run either watch or default
watch ? 'gulp watch' : 'gulp',

// path to gulpfile (in current dir)
util.format('--gulpfile "%s"', gulpfile),

// path to build configuration file
util.format('--config "%s"', path.resolve(process.cwd(), config || './.xtbuild.json')),

// path to project's package.json
util.format('--pkg', path.resolve(process.cwd(), './package.json')),

// explicitly tell gulp to use cwd (necessary)
util.format('--cwd', path.resolve(process.cwd())),

// ENV is either "--dev" or "--prod"
util.format('--%s', programEnv),
util.format('--%s', platformEnv),
'--colors'
].join(' ');

const spinner = new Spinner(' %s ');
// target platform is "--chrome" or "--firefox"
util.format('--%s', platformEnv),

spinner.start();
// use colors in terminal output
'--colors'

const bat = exec(args);
].join(' '));

bat.stdout.on('data', (data) => {
proc.stdout.on('data', (data) => {
if (data && data.indexOf('Using gulpfile') === 0) return;
spinner.stop(true);
process.stdout.write(data.toString());
});

bat.stderr.on('data', (data) => {
proc.stderr.on('data', (data) => {
spinner.stop(true);
process.stdout.write(data.toString());
});

bat.on('exit', (err) => {
proc.on('exit', (err) => {
spinner.stop(true);
console.log(!err ?
texts.onBuildSuccess() :
Expand Down
4 changes: 1 addition & 3 deletions cli/xt-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ const options = [{
name: 'options',
message: texts.instructions,
choices: Object.entries(files).map(
([key, value]) => (
{title: value.title, value: key}
))
([key, {title}]) => ({title, value: key}))
}];

program
Expand Down