Skip to content

Commit c086395

Browse files
authored
Refactor msp to modules (#3214)
* feat: refactor everything to modules * fix: a lot of circular deps fixes * feat: use vitest instead of karma
1 parent 654dca2 commit c086395

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1662
-1378
lines changed

package.json

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"release:default": "NODE_ENV=production gulp release",
1515
"release:windows": "set NODE_ENV=production&& gulp release",
1616
"pretest": "yarn run lint",
17-
"test": "karma start test/karma.conf.js",
17+
"test": "vitest",
1818
"lint": "eslint --ext .js,.vue src gulpfile.js gulp-appdmg.js",
1919
"lint:fix": "eslint --fix src gulpfile.js gulp-appdmg.js",
2020
"storybook": "start-storybook -p 6006"
@@ -66,6 +66,7 @@
6666
"jquery-textcomplete": "^1.8.5",
6767
"jquery-touchswipe": "^1.6.19",
6868
"jquery-ui-npm": "^1.12.0",
69+
"jsdom": "^21.0.0",
6970
"lru_map": "^0.3.3",
7071
"marked": "^4.1.1",
7172
"multicast-dns": "^7.2.5",
@@ -92,7 +93,6 @@
9293
"@storybook/addon-links": "^6.5.12",
9394
"@storybook/vue": "^6.5.12",
9495
"babel-loader": "^8.2.5",
95-
"chai": "^4.3.6",
9696
"command-exists": "^1.2.9",
9797
"cordova-lib": "^11.0.0",
9898
"del": "^6.1.1",
@@ -114,17 +114,6 @@
114114
"gulp-yarn": "^3.0.0",
115115
"gulp-zip": "^5.1.0",
116116
"husky": "^4.3.0",
117-
"karma": "^6.4.1",
118-
"karma-chai": "^0.1.0",
119-
"karma-chrome-launcher": "^3.1.1",
120-
"karma-junit-reporter": "^2.0.1",
121-
"karma-mocha": "^2.0.1",
122-
"karma-rollup-preprocessor": "^7.0.8",
123-
"karma-sinon": "^1.0.5",
124-
"karma-sinon-chai": "^2.0.2",
125-
"karma-spec-reporter": "^0.0.34",
126-
"karma-tfs-reporter": "^1.0.2",
127-
"mocha": "^10.0.0",
128117
"nw-builder": "^3.8.6",
129118
"os": "^0.1.2",
130119
"postcss": "^8.4.17",
@@ -133,12 +122,12 @@
133122
"rpm-builder": "^1.2.1",
134123
"run-script-os": "^1.1.6",
135124
"simple-git": "^3.15.0",
136-
"sinon": "^14.0.0",
137-
"sinon-chai": "^3.7.0",
138125
"targz": "^1.0.1",
139126
"temp": "^0.9.4",
140127
"through2": "^4.0.2",
141128
"vinyl-source-stream": "^2.0.0",
129+
"vite": "^4.0.4",
130+
"vitest": "^0.27.1",
142131
"vue-loader": "^15.9.8",
143132
"vue-template-compiler": "^2.7.10",
144133
"yarn": "^1.22.19"

src/components/EscDshotDirection/EscDshotCommandQueue.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import MSP from '../../js/msp.js';
2+
13
class EscDshotCommandQueue
24
{
35
constructor (intervalMs)

src/components/EscDshotDirection/EscDshotDirectionComponent.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import GUI from "../../js/gui.js";
33
import semver from "semver";
44
import EscDshotDirectionMotorDriver from "./EscDshotDirectionMotorDriver.js";
55
import DshotCommand from "../../js/utils/DshotCommand.js";
6+
import FC from "../../js/fc.js";
7+
import { API_VERSION_1_44 } from '../../js/data_storage.js';
68

79
class EscDshotDirectionComponent
810
{

src/components/EscDshotDirection/EscDshotDirectionMotorDriver.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import EscDshotCommandQueue from './EscDshotCommandQueue.js';
22
import DshotCommand from '../../js/utils/DshotCommand.js';
3+
import MSPCodes from '../../js/msp/MSPCodes.js';
34

45
class EscDshotDirectionMotorDriver
56
{

src/components/MotorOutputReordering/MotorOutputReorderingComponent.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import MotorOutputReorderConfig from "./MotorOutputReorderingConfig";
22
import MotorOutputReorderCanvas from "./MotorOutputReorderingCanvas";
33
import { mspHelper } from "../../js/msp/MSPHelper";
44
import { reinitializeConnection } from "../../js/serial_backend";
5+
import MSP from "../../js/msp";
6+
import MSPCodes from "../../js/msp/MSPCodes";
7+
import FC from "../../js/fc";
8+
import { gui_log } from "../../js/gui_log";
59

610
export default class MotorOutputReorderComponent
711
{
@@ -94,7 +98,7 @@ export default class MotorOutputReorderComponent
9498

9599
function reboot()
96100
{
97-
GUI.log(i18n.getMessage('configurationEepromSaved'));
101+
gui_log(i18n.getMessage('configurationEepromSaved'));
98102
GUI.tab_switch_cleanup(() => MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitializeConnection(TABS.motors)));
99103
}
100104

src/components/init.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import BetaflightLogo from "./betaflight-logo/BetaflightLogo.vue";
1212
import StatusBar from "./status-bar/StatusBar.vue";
1313
import BatteryIcon from "./quad-status/BatteryIcon.vue";
1414
import FC from '../js/fc.js';
15+
import MSP from '../js/msp.js';
16+
import PortUsage from '../js/port_usage.js';
17+
import CONFIGURATOR from '../js/data_storage.js';
1518

1619
// Most of the global objects can go here at first.
1720
// It's a bit of overkill for simple components,

src/js/Beepers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { bit_check, bit_clear, bit_set } from './serial_backend';
1+
import { bit_check, bit_clear, bit_set } from './bit';
22

33
class Beepers {
44
constructor(config, supportedConditions) {

src/js/BuildApi.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import GUI from "./gui";
1+
import { gui_log } from './gui_log';
22
import { i18n } from "./localization";
33
import { get as getStorage, set as setStorage } from "./SessionStorage";
44

@@ -21,7 +21,7 @@ export default class BuildApi {
2121

2222
const cachedCallback = () => {
2323
if (cachedData) {
24-
GUI.log(i18n.getMessage('buildServerUsingCached', [url]));
24+
gui_log(i18n.getMessage('buildServerUsingCached', [url]));
2525
}
2626

2727
onSuccess(cachedData);
@@ -36,7 +36,7 @@ export default class BuildApi {
3636
setStorage(object);
3737
onSuccess(info);
3838
}).fail(xhr => {
39-
GUI.log(i18n.getMessage('buildServerFailure', [url, `HTTP ${xhr.status}`]));
39+
gui_log(i18n.getMessage('buildServerFailure', [url, `HTTP ${xhr.status}`]));
4040
if (onFailure !== undefined) {
4141
onFailure();
4242
} else {
@@ -70,10 +70,10 @@ export default class BuildApi {
7070

7171
const url = `${this._url}${path}`;
7272
$.get(url, function (data) {
73-
GUI.log(i18n.getMessage('buildServerSuccess', [path]));
73+
gui_log(i18n.getMessage('buildServerSuccess', [path]));
7474
onSuccess(data);
7575
}).fail(xhr => {
76-
GUI.log(i18n.getMessage('buildServerFailure', [path, `HTTP ${xhr.status}`]));
76+
gui_log(i18n.getMessage('buildServerFailure', [path, `HTTP ${xhr.status}`]));
7777
if (onFailure !== undefined) {
7878
onFailure();
7979
}
@@ -86,7 +86,7 @@ export default class BuildApi {
8686
$.get(url, function (data) {
8787
onSuccess(data);
8888
}).fail(xhr => {
89-
GUI.log(i18n.getMessage('buildServerFailure', [url, `HTTP ${xhr.status}`]));
89+
gui_log(i18n.getMessage('buildServerFailure', [url, `HTTP ${xhr.status}`]));
9090
if (onFailure !== undefined) {
9191
onFailure();
9292
}
@@ -107,7 +107,7 @@ export default class BuildApi {
107107
onSuccess(response);
108108
},
109109
}).fail(xhr => {
110-
GUI.log(i18n.getMessage('buildServerFailure', [`HTTP ${xhr.status}`]));
110+
gui_log(i18n.getMessage('buildServerFailure', [`HTTP ${xhr.status}`]));
111111
if (onFailure !== undefined) {
112112
onFailure();
113113
}
@@ -128,7 +128,7 @@ export default class BuildApi {
128128
onSuccess(response);
129129
},
130130
}).fail(xhr => {
131-
GUI.log(i18n.getMessage('buildServerFailure', [url, `HTTP ${xhr.status}`]));
131+
gui_log(i18n.getMessage('buildServerFailure', [url, `HTTP ${xhr.status}`]));
132132
if (onFailure !== undefined) {
133133
onFailure();
134134
}
@@ -139,10 +139,10 @@ export default class BuildApi {
139139

140140
const url = `${this._url}/api/builds/${key}/status`;
141141
$.get(url, function (data) {
142-
GUI.log(i18n.getMessage('buildServerSuccess', [url]));
142+
gui_log(i18n.getMessage('buildServerSuccess', [url]));
143143
onSuccess(data);
144144
}).fail(xhr => {
145-
GUI.log(i18n.getMessage('buildServerFailure', [url, `HTTP ${xhr.status}`]));
145+
gui_log(i18n.getMessage('buildServerFailure', [url, `HTTP ${xhr.status}`]));
146146
if (onFailure !== undefined) {
147147
onFailure();
148148
}

src/js/CliAutoComplete.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
'use strict';
1+
import GUI from './gui';
2+
import CONFIGURATOR from './data_storage';
3+
import FC from './fc';
24

35
/**
46
* Encapsulates the AutoComplete logic
@@ -575,3 +577,6 @@ CliAutoComplete._initTextcomplete = function() {
575577
}),
576578
]);
577579
};
580+
581+
window.CliAutoComplete = CliAutoComplete;
582+
export default CliAutoComplete;

src/js/DarkTheme.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
'use strict';
1+
import GUI from "./gui";
2+
import windowWatcherUtil from "./utils/window_watchers";
23

34
const css_dark = [
45
'./css/dark-theme.css',
@@ -63,3 +64,5 @@ DarkTheme.applyDark = function () {
6364
DarkTheme.applyNormal = function () {
6465
css_dark.forEach((el) => $(`link[href="${el}"]`).prop('disabled', true));
6566
};
67+
68+
export default DarkTheme;

0 commit comments

Comments
 (0)