Skip to content

Commit 2f0c88b

Browse files
committed
xxx
1 parent 4d9ab34 commit 2f0c88b

11 files changed

Lines changed: 70 additions & 40 deletions

.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: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function modeList() {
2828
function checkModes() {
2929
var snippets = {};
3030
modeList().forEach(function(modeName, i) {
31-
console.log(padNumber(i+1, 3) + ") check: \u001b[33m" + modeName + "\u001b[0m");
31+
silent || console.log(padNumber(i+1, 3) + ") check: \u001b[33m" + modeName + "\u001b[0m");
3232
try {
3333
var Mode = require("../" + modeName).Mode;
3434
} catch(e) {
@@ -145,7 +145,7 @@ function checkModes() {
145145
editor.setSession(session);
146146
editor.execCommand("insertstring", "(");
147147
if (editor.getValue() != "()")
148-
return console.log("() not paired in " + modeName);
148+
return silent || console.log("() not paired in " + modeName);
149149
editor.execCommand("insertstring", "(");
150150
if (editor.getValue() != "(())")
151151
die("(()) not paired in " + modeName);
@@ -211,7 +211,7 @@ function generateTestData(names, force) {
211211
console.warn("Can't load mode :" + modeName, p, e);
212212
return;
213213
}
214-
console.log(modeName);
214+
silent || console.log(modeName);
215215
var tokenizer = new Mode().getTokenizer();
216216

217217
var state = "start";
@@ -247,7 +247,7 @@ function test(startAt) {
247247
for (var i = Math.max(0, startAt||0); i < modes.length; i++)
248248
testMode(modes[i], i);
249249

250-
console.log("\u001b[32m" + "all ok" + "\u001b[0m");
250+
silent || console.log("\u001b[32m" + "all ok" + "\u001b[0m");
251251
}
252252
function testMode(modeName, i) {
253253
console.log(padNumber(i+1, 3) + ") testing: \u001b[33m" + modeName + "\u001b[0m");
@@ -344,9 +344,21 @@ function checkBacktracking(tokenizer) {
344344
}
345345

346346
// cli
347+
var silent = false;
347348
var arg = process.argv[2];
348349
var RECHECK = process.argv.indexOf("--recheck") !== -1;
349-
if (!arg) {
350+
if (global.describe && global.it) {
351+
silent = true;
352+
global.describe("check modes", function() {
353+
global.it("should check modes", function() {
354+
checkModes();
355+
});
356+
global.it("should test modes", function() {
357+
test();
358+
});
359+
});
360+
}
361+
else if (!arg) {
350362
test();
351363
checkModes();
352364
} 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/test/update_test_list.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ if (testFiles.length === 0) {
1616
process.exit(1);
1717
}
1818

19-
var testListFilePath = __dirname + "/test_list.js";
20-
var data = `module.exports = [\n "${testFiles.join('",\n "')}"\n];`
19+
var testListFilePath = __dirname + "/test_list.js";
20+
var data = `module.exports = [\n "${testFiles.join('",\n "')}"\n];`;
2121

2222
// Write the updated content back to the file
2323
fs.writeFileSync(testListFilePath, data, "utf8");

0 commit comments

Comments
 (0)