Skip to content

Commit dacd778

Browse files
committed
xxx
1 parent 4d9ab34 commit dacd778

10 files changed

Lines changed: 62 additions & 34 deletions

File tree

.github/workflows/nodejs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ jobs:
3131
uses: actions/setup-node@v1
3232
with:
3333
node-version: ${{ matrix.node-version }}
34-
- run: npm i
34+
- run: npm i && npm i mocha c8
3535
- run: npm run cover
36+
- run: npx c8 --reporter=lcov --reporter=text-summary mocha './src/**/*_test.js' --exit -p
3637
# run linter
3738
- run: |
3839
set -x;

src/ext/command_bar_test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,8 @@ module.exports = {
585585
tooltipVisibilityCheck(true);
586586
commandBarTooltip.detach();
587587
},
588-
"test: does not display if the tooltip does not fit into the screen": function() {
588+
"test: does not display if the tooltip does not fit into the screen": async function() {
589+
await lang.sleep(0);
589590
createTooltip();
590591

591592
var testString = "a".repeat(100) +

src/ext/diff/base_diff_view.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,13 +435,14 @@ class BaseDiffView {
435435
*/
436436
$initWidgets(editor) {
437437
var session = editor.session;
438+
if (!session) return;
438439
if (!session.widgetManager) {
439440
session.widgetManager = new LineWidgets(session);
440441
session.widgetManager.attach(editor);
441442
}
442-
editor.session.lineWidgets = [];
443-
editor.session.widgetManager.lineWidgets = [];
444-
editor.session.$resetRowCache(0);
443+
session.lineWidgets = [];
444+
session.widgetManager.lineWidgets = [];
445+
session.$resetRowCache(0);
445446
}
446447

447448
/**
@@ -598,7 +599,7 @@ class BaseDiffView {
598599
if (this.savedOptionsB &&this.savedOptionsB.customScrollbar) {
599600
this.$resetDecorators(this.editorB.renderer);
600601
}
601-
602+
clearTimeout(this.$onInputTimer);
602603
}
603604

604605
$removeLineWidgets(session) {

src/ext/diff/inline_diff_view.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class InlineDiffView extends BaseDiffView {
140140

141141
selectEditor(editor) {
142142
if (editor == this.activeEditor) {
143-
this.otherEditor.selection.clearSelection();
143+
this.otherEditor.selection?.clearSelection();
144144
this.activeEditor.textInput.setHost(this.activeEditor);
145145
this.activeEditor.setStyle("ace_diff_other", false);
146146
this.cursorLayer.element.remove();
@@ -174,7 +174,7 @@ class InlineDiffView extends BaseDiffView {
174174

175175
removeBracketHighlight(editor) {
176176
var session = editor.session;
177-
if (session.$bracketHighlight) {
177+
if (session && session.$bracketHighlight) {
178178
session.$bracketHighlight.markerIds.forEach(function(id) {
179179
session.removeMarker(id);
180180
});
@@ -312,10 +312,10 @@ class InlineDiffView extends BaseDiffView {
312312
}
313313

314314
$detachSessionHandlers(editor, marker) {
315-
editor.session.removeMarker(marker.id);
316-
editor.selection.off("changeCursor", this.onSelect);
317-
editor.selection.off("changeSelection", this.onSelect);
318-
editor.session.off("changeFold", this.onChangeFold);
315+
editor.session?.removeMarker(marker.id);
316+
editor.selection?.off("changeCursor", this.onSelect);
317+
editor.selection?.off("changeSelection", this.onSelect);
318+
editor.session?.off("changeFold", this.onChangeFold);
319319
}
320320

321321
$attachEventHandlers() {

src/ext/static_highlight_test.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ var config = require("../config");
1212
module.exports = {
1313
timeout: 10000,
1414

15-
"test loading in node": function() {
16-
require("../test/mockdom").unload();
17-
if (typeof process != "undefined")
18-
assert.equal(typeof window, "undefined");
19-
require("../ace");
15+
"test loading in node": function(done) {
16+
if (typeof process === "undefined") {
17+
return done();
18+
}
19+
var req = require;
20+
req("child_process").execFile(process.execPath, ["-p", "require('../ace').version"], function(err, stdout, stderr) {
21+
assert.ok(!err, "Failed to load ace in node: " + err);
22+
assert.equal(stdout.trim(), config.version);
23+
done();
24+
});
2025
},
2126

2227
"test simple snippet": function() {

src/mode/_test/highlight_rules_test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,17 @@ function checkBacktracking(tokenizer) {
346346
// cli
347347
var arg = process.argv[2];
348348
var RECHECK = process.argv.indexOf("--recheck") !== -1;
349-
if (!arg) {
349+
if (global.describe && global.it) {
350+
describe("check modes", function() {
351+
it("should check modes", function() {
352+
checkModes();
353+
});
354+
it("should test modes", function() {
355+
test();
356+
});
357+
});
358+
}
359+
else if (!arg) {
350360
test();
351361
checkModes();
352362
} else if (/--?g(en)?/.test(arg))

src/scrollbar_test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ module.exports = {
5050
editor.setOptions({
5151
customScrollbar: true
5252
});
53+
renderer.$loop._flush();
5354
},
5455
tearDown: function () {
5556
editor && editor.destroy();

src/test/mockdom.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -927,20 +927,25 @@ exports.load = function() {
927927
Object.keys(window).forEach(function(i) {
928928
var desc = Object.getOwnPropertyDescriptor(global, i);
929929
originalProperties[i] = desc;
930-
global.__defineGetter__(i, function() {
931-
return overriddenValues[i] || window[i];
932-
});
933-
global.__defineSetter__(i, function(value) {
934-
if (!overridableProperties.includes(i)) {
935-
console.log("attempt to set " + i);
936-
} else if (value === window[i]) {
937-
delete overriddenValues[i];
938-
if (!loaded) {
939-
unloadProperty(i);
930+
Object.defineProperty(global, i, {
931+
get: function() {
932+
return overriddenValues[i] || window[i];
933+
},
934+
set: function(value) {
935+
if (!overridableProperties.includes(i)) {
936+
console.trace("attempt to set " + i);
937+
} else if (value === window[i]) {
938+
delete overriddenValues[i];
939+
if (!loaded) {
940+
unloadProperty(i);
941+
}
942+
} else {
943+
overriddenValues[i] = value;
940944
}
941-
} else {
942-
overriddenValues[i] = value;
943-
}
945+
},
946+
// writable: true,
947+
enumerable: true,
948+
configurable: true,
944949
});
945950
});
946951
loaded = true;
@@ -954,6 +959,8 @@ exports.loadInBrowser = function(global, $setSize) {
954959
delete global.ResizeObserver;
955960
global.__origRoot__ = global.document.documentElement;
956961
global.__origBody__ = global.document.body;
962+
global.document.createElementOrig = global.document.createElement;
963+
global.document.createTextNodeOrig = global.document.createTextNode;
957964
Object.keys(window).forEach(function(i) {
958965
if (i != "document" && i != "window") {
959966
delete global[i];
@@ -964,7 +971,6 @@ exports.loadInBrowser = function(global, $setSize) {
964971
var val = window.document[i];
965972
if (typeof val == "function") {
966973
if (i == "createElement") {
967-
global.document.createElementOrig = global.document.createElement;
968974
val = function(n) {
969975
if (n == "script")
970976
return global.document.createElementOrig(n);

src/test/run.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ module.exports = function(testModule) {
44
if (testModule === require.main) {
55
require("asyncjs").test.testcase(testModule.exports).exec();
66
}
7-
else if (typeof global == "object" && global.describe && global.it) {
8-
global.describe("#: " + testModule.id, function() {
7+
else if (typeof global == "object" && global.describe && (global.it || global.test)) {
8+
if (!global.it) global.it = global.test;
9+
global.describe("# file: " + testModule.id, function() {
910
for (let i in testModule.exports) {
1011
if (/^test/.test(i)) {
1112
let fn = testModule.exports[i];

src/virtual_renderer_test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,8 @@ module.exports = {
481481
done();
482482
},
483483
"test: scroll cursor into view": function() {
484+
editor.renderer.$loop._flush();
485+
484486
function X(n) {
485487
return "X".repeat(n);
486488
}

0 commit comments

Comments
 (0)