hterm: convert test suite to mocha
Mocha is a commonly used test framework in the wider world.
It provides all the functionality we need, and is usable in
the browser and command line. It's also a bit more flexible
and expressive than our current framework.
Change-Id: I080f3ec52567f82a97716346d7a93fc19a5b5dd0
Reviewed-on: https://chromium-review.googlesource.com/c/apps/libapps/+/1646588
Reviewed-by: Vitaliy Shipitsyn <vsh@google.com>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/hterm/js/hterm_accessibility_reader_tests.js b/hterm/js/hterm_accessibility_reader_tests.js
index 20b3309..7ab8715 100644
--- a/hterm/js/hterm_accessibility_reader_tests.js
+++ b/hterm/js/hterm_accessibility_reader_tests.js
@@ -7,26 +7,25 @@
/**
* @fileoverview hterm.AccessibilityReader unit tests.
*/
-hterm.AccessibilityReader.Tests = new lib.TestManager.Suite(
- 'hterm.AccessibilityReader.Tests');
+
+describe('hterm_accessibility_reader_tests.js', () => {
/**
* Set up state for all the tests in this suite.
*/
-hterm.AccessibilityReader.Tests.prototype.setup = function(cx) {
+before(() => {
// Stub out the delay loops. We don't have to worry about waiting for input
// from the user to accumulate as we don't do that.
hterm.AccessibilityReader.DELAY = 0;
-};
+});
-/**
- * Clear out the current document and create a new hterm.AccessibilityReader
- * object for testing.
+/*
+ * Create a new hterm.AccessibilityReader object for testing.
*
* Called before each test case in this suite.
*/
-hterm.AccessibilityReader.Tests.prototype.preamble = function(result, cx) {
- const document = cx.window.document;
+beforeEach(function() {
+ const document = window.document;
const div = this.div = document.createElement('div');
div.style.position = 'absolute';
@@ -39,22 +38,21 @@
this.assertiveLiveElement = this.liveElement.nextSibling;
document.body.appendChild(div);
-};
+});
/**
* Clean up the hterm.AccessibilityReader object.
*/
-hterm.AccessibilityReader.Tests.prototype.postamble = function(result, cx) {
+afterEach(function() {
window.document.body.removeChild(this.div);
-};
+});
/**
* Test that printing text to the terminal will cause nodes to be added to the
* live region for accessibility purposes. This shouldn't happen until after a
* small delay has passed.
*/
-hterm.AccessibilityReader.Tests.addTest(
- 'a11y-live-region-single-delay', function(result, cx) {
+it('a11y-live-region-single-delay', function(done) {
this.accessibilityReader.announce('Some test output');
this.accessibilityReader.announce('Some other test output');
this.accessibilityReader.newLine();
@@ -66,13 +64,10 @@
assert.equal('Some test output Some other test output\nMore output',
this.liveElement.getAttribute('aria-label'));
observer.disconnect();
- result.pass();
+ done();
});
observer.observe(this.liveElement, {attributes: true});
- // This should only need to be 2x the initial delay but we wait longer to
- // avoid flakiness.
- result.requestTime(500);
});
@@ -80,8 +75,7 @@
* Test that after text has been added to the live region, there is again a
* delay before adding more text.
*/
-hterm.AccessibilityReader.Tests.addTest(
- 'a11y-live-region-double-delay', function(result, cx) {
+it('a11y-live-region-double-delay', function(done) {
this.accessibilityReader.announce('Some test output');
this.accessibilityReader.announce('Some other test output');
this.accessibilityReader.newLine();
@@ -114,22 +108,18 @@
if (checksToComplete.length == 0) {
observer.disconnect();
- result.pass();
+ done();
}
});
observer.observe(this.liveElement, {attributes: true});
- // This should only need to be 2x the initial delay but we wait longer to
- // avoid flakiness.
- result.requestTime(500);
});
/**
* Test that adding the same text twice to the live region gets slightly
* modified to trigger an attribute change.
*/
-hterm.AccessibilityReader.Tests.addTest(
- 'a11y-live-region-duplicate-text', function(result, cx) {
+it('a11y-live-region-duplicate-text', function(done) {
this.accessibilityReader.announce('Some test output');
assert.equal('', this.liveElement.getAttribute('aria-label'));
@@ -157,50 +147,42 @@
if (checksToComplete.length == 0) {
observer.disconnect();
- result.pass();
+ done();
}
});
observer.observe(this.liveElement, {attributes: true});
- // This should only need to be 2x the initial delay but we wait longer to
- // avoid flakiness.
- result.requestTime(500);
});
/**
* Test that adding text to the assertive live region works correctly.
*/
-hterm.AccessibilityReader.Tests.addTest(
- 'a11y-assertive-live-region', function(result, cx) {
+it('a11y-assertive-live-region', function() {
this.accessibilityReader.assertiveAnnounce('Some test output');
assert.equal(this.assertiveLiveElement.getAttribute('aria-label'),
'Some test output');
this.accessibilityReader.clear();
assert.equal(this.assertiveLiveElement.getAttribute('aria-label'), '');
- result.pass();
});
/**
* Test that adding the same text twice to the assertive live region gets
* slightly modified to trigger an attribute change.
*/
-hterm.AccessibilityReader.Tests.addTest(
- 'a11y-assertive-live-region-duplicate-text', function(result, cx) {
+it('a11y-assertive-live-region-duplicate-text', function() {
this.accessibilityReader.assertiveAnnounce('Some test output');
assert.equal(this.assertiveLiveElement.getAttribute('aria-label'),
'Some test output');
this.accessibilityReader.assertiveAnnounce('Some test output');
assert.equal(this.assertiveLiveElement.getAttribute('aria-label'),
'\nSome test output');
- result.pass();
});
/**
* Test that adding text to the assertive live region interrupts polite
* announcements.
*/
-hterm.AccessibilityReader.Tests.addTest(
- 'a11y-assertive-live-region-interrupts-polite', function(result, cx) {
+it('a11y-assertive-live-region-interrupts-polite', function(done) {
this.accessibilityReader.announce('Some test output');
this.accessibilityReader.announce('Some other test output');
this.accessibilityReader.newLine();
@@ -213,7 +195,7 @@
// announce the 'PASS' string which comes after all the output above.
const observer = new MutationObserver(() => {
if (this.liveElement.getAttribute('aria-label') == 'PASS') {
- result.pass();
+ done();
} else {
assert.equal(this.liveElement.getAttribute('aria-label'), '');
}
@@ -225,16 +207,12 @@
'Some test output');
this.accessibilityReader.announce('PASS');
-
- // Wait a time to ensure that nothing is announced from liveElement.
- result.requestTime(250);
});
/**
* Test that nothing is announced when accessibility is disabled.
*/
-hterm.AccessibilityReader.Tests.addTest(
- 'a11y-disabled-enabled', function(result, cx) {
+it('a11y-disabled-enabled', function(done) {
this.accessibilityReader.setAccessibilityEnabled(false);
this.accessibilityReader.announce('Some test output');
this.accessibilityReader.announce('Some other test output');
@@ -249,21 +227,18 @@
const observer = new MutationObserver(() => {
if (this.liveElement.getAttribute('aria-label') == 'Other output') {
- result.pass();
+ done();
} else {
assert.equal(this.liveElement.getAttribute('aria-label'), '');
}
});
observer.observe(this.liveElement, {attributes: true});
-
- result.requestTime(250);
});
/**
* Test that when accessibility is disabled, nothing else will be announced.
*/
-hterm.AccessibilityReader.Tests.addTest(
- 'a11y-enabled-disabled', function(result, cx) {
+it('a11y-enabled-disabled', function(done) {
this.accessibilityReader.announce('Some test output');
this.accessibilityReader.announce('Some other test output');
this.accessibilityReader.newLine();
@@ -276,7 +251,7 @@
// above.
const observer = new MutationObserver(() => {
if (this.liveElement.getAttribute('aria-label') == 'PASS') {
- result.pass();
+ done();
} else {
assert.equal(this.liveElement.getAttribute('aria-label'), '');
}
@@ -287,9 +262,6 @@
this.accessibilityReader.setAccessibilityEnabled(true);
this.accessibilityReader.announce('PASS');
-
- // Wait a time to ensure that nothing is announced from liveElement.
- result.requestTime(250);
});
/**
@@ -297,8 +269,7 @@
* These are not performance sensitive so they don't need to be gated on the
* flag.
*/
-hterm.AccessibilityReader.Tests.addTest(
- 'a11y-assertive-disabled-enabled', function(result, cx) {
+it('a11y-assertive-disabled-enabled', function() {
this.accessibilityReader.setAccessibilityEnabled(false);
this.accessibilityReader.assertiveAnnounce('Some test output');
@@ -310,29 +281,23 @@
this.accessibilityReader.assertiveAnnounce('More test output');
assert.equal(this.assertiveLiveElement.getAttribute('aria-label'),
'More test output');
-
- result.pass();
});
/**
* Regression test for a bug that is caused by adding 2 newlines and then
* calling announce. In this case an exception was thrown.
*/
-hterm.AccessibilityReader.Tests.addTest(
- 'a11y-newlines-then-announce', function(result, cx) {
+it('a11y-newlines-then-announce', function() {
this.accessibilityReader.newLine();
this.accessibilityReader.newLine();
this.accessibilityReader.announce('Some test output');
-
- result.pass();
});
/**
* Test that moving the cursor left/right through output will cause the output
* to get assertively announced.
*/
-hterm.AccessibilityReader.Tests.addTest(
- 'a11y-selection-change-left-right', function(result, cx) {
+it('a11y-selection-change-left-right', function() {
// Move the cursor right 1 character.
// Simulatue a user gesture.
this.accessibilityReader.hasUserGesture = true;
@@ -402,16 +367,13 @@
this.accessibilityReader.beforeCursorChange('abc', 0, 0);
this.accessibilityReader.afterCursorChange('abc', 1, 1);
assert.equal(this.assertiveLiveElement.getAttribute('aria-label'), '');
-
- result.pass();
});
/**
* Test that other announcements are properly ignored or spoken when navigating
* left and right through output.
*/
-hterm.AccessibilityReader.Tests.addTest(
- 'a11y-selection-change-left-right-with-announce', function(result, cx) {
+it('a11y-selection-change-left-right-with-announce', function(done) {
// Move the cursor 1 character. In the process of doing this, a space
// character is printed somewhere in the terminal. It should get consumed and
// not announced as it may just be a side effect of the cursor change.
@@ -433,20 +395,17 @@
// still gets announced.
const observer = new MutationObserver(() => {
if (this.liveElement.getAttribute('aria-label') == 'foo bar') {
- result.pass();
+ done();
}
});
observer.observe(this.liveElement, {attributes: true});
-
- result.requestTime(250);
});
/**
* Test that changes to the cursor due to backspace and deletion are properly
* announced.
*/
-hterm.AccessibilityReader.Tests.addTest(
- 'a11y-selection-change-backspace-delete', function(result, cx) {
+it('a11y-selection-change-backspace-delete', function() {
// Backspace a character at the start of the string.
this.accessibilityReader.hasUserGesture = true;
this.accessibilityReader.beforeCursorChange('abc', 0, 1);
@@ -534,16 +493,13 @@
this.accessibilityReader.beforeCursorChange('abc', 0, 1);
this.accessibilityReader.afterCursorChange('bc', 0, 0);
assert.equal(this.assertiveLiveElement.getAttribute('aria-label'), '');
-
- result.pass();
});
/**
* Test that other output isn't announced during a backspace/deletion selection
* change.
*/
-hterm.AccessibilityReader.Tests.addTest(
- 'a11y-selection-change-backspace-with-announce', function(result, cx) {
+it('a11y-selection-change-backspace-with-announce', function(done) {
// Backspace a character. If other text is announced to the terminal in the
// process, we ignore it. This is because lots of updates can happen during a
// backspace (e.g. all the characers after the deleted character need to be
@@ -560,19 +516,16 @@
const observer = new MutationObserver(() => {
if (this.liveElement.getAttribute('aria-label') == 'foo') {
- result.pass();
+ done();
}
});
observer.observe(this.liveElement, {attributes: true});
-
- result.requestTime(250);
});
/**
* Test that entering a space character triggers 'Space' to be spoken.
*/
-hterm.AccessibilityReader.Tests.addTest(
- 'a11y-selection-space', function(result, cx) {
+it('a11y-selection-space', function() {
this.accessibilityReader.hasUserGesture = true;
this.accessibilityReader.beforeCursorChange('abc', 0, 3);
this.accessibilityReader.announce(' ');
@@ -601,6 +554,6 @@
this.accessibilityReader.announce(' ');
this.accessibilityReader.afterCursorChange('abc ', 0, 4);
assert.equal(this.assertiveLiveElement.getAttribute('aria-label'), '');
+});
- result.pass();
});
diff --git a/hterm/js/hterm_contextmenu_tests.js b/hterm/js/hterm_contextmenu_tests.js
index 6d4226b..05008e6 100644
--- a/hterm/js/hterm_contextmenu_tests.js
+++ b/hterm/js/hterm_contextmenu_tests.js
@@ -7,26 +7,25 @@
/**
* @fileoverview hterm.ContextMenu unit tests.
*/
-hterm.ContextMenu.Tests = new lib.TestManager.Suite('hterm.ContextMenu.Tests');
+
+describe('hterm_contextmenu_tests.js', () => {
/**
* Verify we can show/hide an empty menu.
*/
-hterm.ContextMenu.Tests.addTest('contextmenu-stub', function(result, cx) {
+it('contextmenu-stub', () => {
const menu = new hterm.ContextMenu();
// Show/hide this stub menu. It should be fine.
menu.show();
menu.hide();
-
- result.pass();
});
/**
* Verify we can show/hide a simple menu.
*/
-hterm.ContextMenu.Tests.addTest('contextmenu-simple', function(result, cx) {
- const document = cx.window.document;
+it('contextmenu-simple', () => {
+ const document = window.document;
const menu = new hterm.ContextMenu();
menu.setDocument(document);
@@ -36,15 +35,13 @@
// Show/hide this menu.
menu.show({clientX: 0, clientY: 0});
menu.hide();
-
- result.pass();
});
/**
* Check separator handling.
*/
-hterm.ContextMenu.Tests.addTest('contextmenu-separator', function(result, cx) {
- const document = cx.window.document;
+it('contextmenu-separator', () => {
+ const document = window.document;
const menu = new hterm.ContextMenu();
menu.setDocument(document);
@@ -57,6 +54,6 @@
// Show/hide this menu.
menu.show({clientX: 0, clientY: 0});
menu.hide();
+});
- result.pass();
});
diff --git a/hterm/js/hterm_parser_tests.js b/hterm/js/hterm_parser_tests.js
index ad2296b..7d7316d 100644
--- a/hterm/js/hterm_parser_tests.js
+++ b/hterm/js/hterm_parser_tests.js
@@ -8,8 +8,7 @@
* @fileoverview hterm.Parser unit tests.
*/
-hterm.Parser.Tests =
- new lib.TestManager.Suite('hterm.Parser.Tests');
+describe('hterm_parser_tests.js', () => {
/**
* Helper to check parseKeySequence failing behavior.
@@ -31,7 +30,7 @@
assert.fail(`Expected failure for: ${input}`);
};
-hterm.Parser.Tests.addTest('sequence-identifiers', function(result) {
+it('sequence-identifiers', () => {
var p = new hterm.Parser();
var checkResult = function(input, output) {
@@ -51,11 +50,9 @@
checkResult('esc', 27);
negKeySeq('FOO', /Unknown key: FOO/);
-
- result.pass();
});
-hterm.Parser.Tests.addTest('modifiers', function(result) {
+it('modifiers', () => {
var p = new hterm.Parser();
var checkResult = function(input, shift, ctrl, alt, meta) {
@@ -102,11 +99,9 @@
negKeySeq('Ctrl-', /Missing target key$/);
negKeySeq('Ctrl-X-Alt', /Extra definition after target key$/);
negKeySeq('toString-X', /Unknown key: toString$/);
-
- result.pass();
});
-hterm.Parser.Tests.addTest('keycodes', function(result) {
+it('keycodes', () => {
var p = new hterm.Parser();
var checkResult = function(input, target, shift, ctrl, alt, meta) {
@@ -138,11 +133,9 @@
checkResult('0xff', 255, false, false, false, false);
checkResult('Ctrl-0xff', 255, false, true, false, false);
checkResult('Ctrl-Alt-0xff', 255, false, true, true, false);
-
- result.pass();
});
-hterm.Parser.Tests.addTest('actions', function(result) {
+it('actions', () => {
var p = new hterm.Parser();
var checkResult = function(input, output) {
@@ -157,6 +150,6 @@
checkResult('DEFAULT', hterm.Keyboard.KeyActions.DEFAULT);
checkResult('"123"', '123');
+});
- result.pass();
});
diff --git a/hterm/js/hterm_preference_manager_tests.js b/hterm/js/hterm_preference_manager_tests.js
index 4462e07..1664aab 100644
--- a/hterm/js/hterm_preference_manager_tests.js
+++ b/hterm/js/hterm_preference_manager_tests.js
@@ -8,12 +8,12 @@
* @fileoverview Preference manager tests.
*/
-hterm.PreferenceManager.Tests = new lib.TestManager.Suite('hterm.PreferenceManager.Tests');
+describe('hterm_preference_manager_tests.js', () => {
/**
* Make sure hterm translations are kept in sync with nassh.
*/
-hterm.PreferenceManager.Tests.addTest('pref-messages-sync', function(result, cx) {
+it('pref-messages-sync', () => {
const toMsgId = (id) => id.replace(/-/g, '_').toUpperCase();
const fromMsgId = (id) => id.replace(/_/g, '-').toLowerCase();
const helpIdToMsgId = (id) => `PREF_${toMsgId(id)}`;
@@ -75,6 +75,6 @@
const nasshMsg = hterm.msg(msgId);
assert.equal(htermMsg, nasshMsg, msgId);
});
+});
- result.pass();
});
diff --git a/hterm/js/hterm_pubsub_tests.js b/hterm/js/hterm_pubsub_tests.js
index 798b856..54700a3 100644
--- a/hterm/js/hterm_pubsub_tests.js
+++ b/hterm/js/hterm_pubsub_tests.js
@@ -4,29 +4,31 @@
'use strict';
-hterm.PubSub.Tests = new lib.TestManager.Suite('hterm.PubSub.Tests');
+/**
+ * @fileoverview hterm.Pubsub unit tests.
+ */
+
+describe('hterm_pubsub_tests.js', () => {
/**
* Test that the appropriate methods are added to a hterm.PubSub target object.
*/
-hterm.PubSub.Tests.addTest('methods', function(result, cx) {
+it('methods', () => {
var obj = {};
hterm.PubSub.addBehavior(obj);
assert.hasAllKeys(obj, ['subscribe', 'unsubscribe', 'publish']);
-
- result.pass();
});
/**
* Test that subscribers are notified in the proper order.
*/
-hterm.PubSub.Tests.addTest('publish-order', function(result, cx) {
+it('publish-order', (done) => {
var callbackCount = 0;
function one() { assert.equal(1, ++callbackCount); }
function two() { assert.equal(2, ++callbackCount); }
function three() { assert.equal(3, ++callbackCount); }
- function last() { assert.equal(4, ++callbackCount); result.pass(); }
+ function last() { assert.equal(4, ++callbackCount); done(); }
var obj = {};
hterm.PubSub.addBehavior(obj);
@@ -36,20 +38,18 @@
obj.subscribe('test', three);
obj.publish('test', null, last);
-
- result.requestTime(100);
});
/**
* Test that a published parameter is handed off to all subscribers.
*/
-hterm.PubSub.Tests.addTest('parameter', function(result, cx) {
+it('parameter', (done) => {
var expected = {};
function one(param) { assert.deepStrictEqual(expected, param); }
function two(param) { assert.deepStrictEqual(expected, param); }
function three(param) { assert.deepStrictEqual(expected, param); }
- function last(param) { assert.deepStrictEqual(expected, param); result.pass(); }
+ function last(param) { assert.deepStrictEqual(expected, param); done(); }
var obj = {};
hterm.PubSub.addBehavior(obj);
@@ -59,14 +59,12 @@
obj.subscribe('test', three);
obj.publish('test', expected, last);
-
- result.requestTime(100);
});
/**
* Test that the final callback is invoked, even if nobody has subscribed.
*/
-hterm.PubSub.Tests.addTest('forever-alone', function(result, cx) {
+it('forever-alone', (done) => {
var calledLast = false;
function last(param) { calledLast = true; }
@@ -78,21 +76,24 @@
const check = () => {
if (calledLast) {
- result.pass();
+ done();
} else {
setTimeout(check, 1);
}
};
check();
-
- result.requestTime(200);
});
/**
* Test that an exception raised by a subscriber does not stop the remaining
* notifications.
*/
-hterm.PubSub.Tests.addTest('exception', function(result, cx) {
+it('exception', function(done) {
+ // We need to manually disable this.
+ // https://github.com/mochajs/mocha/issues/1985
+ const oldUncaught = Mocha.Runner.prototype.uncaught;
+ Mocha.Runner.prototype.uncaught = () => {};
+
var calledFoo = false;
var calledBar = false;
var calledLast = false;
@@ -109,19 +110,18 @@
obj.publish('test', null, last);
- result.expectErrorMessage('EXPECTED_EXCEPTION');
-
const check = () => {
if (calledLast) {
assert.isFalse(calledFoo);
assert.isTrue(calledBar);
assert.isTrue(calledLast);
- result.pass();
+ Mocha.Runner.prototype.uncaught = oldUncaught;
+ done();
} else {
setTimeout(check, 1);
}
};
check();
-
- result.requestTime(200);
});
+
+});
diff --git a/hterm/js/hterm_screen_tests.js b/hterm/js/hterm_screen_tests.js
index 933044b..bbe7fcd 100644
--- a/hterm/js/hterm_screen_tests.js
+++ b/hterm/js/hterm_screen_tests.js
@@ -7,7 +7,8 @@
/**
* @fileoverview Unit tests for the hterm.Screen class.
*/
-hterm.Screen.Tests = new lib.TestManager.Suite('hterm.Screen.Tests');
+
+describe('hterm_screen_tests.js', () => {
/**
* Clear out the current document and create a new hterm.Screen object for
@@ -15,15 +16,15 @@
*
* Called before each test case in this suite.
*/
-hterm.Screen.Tests.prototype.preamble = function(result, cx) {
+beforeEach(function() {
this.screen = new hterm.Screen();
this.screen.setColumnCount(80);
-};
+});
/**
* Test the push and pop functionality of the hterm.Screen.
*/
-hterm.Screen.Tests.addTest('push-pop', function(result, cx) {
+it('push-pop', function() {
// Push one at a time.
var ary = [];
for (var i = 0; i < 10; i++) {
@@ -60,14 +61,12 @@
for (var i = 0; i < 5; i++) {
assert.equal(ary[i + 5], popary[i], 'i:' + i);
}
-
- result.pass();
});
/**
* Test the unshift and shift functionality of the hterm.Screen.
*/
-hterm.Screen.Tests.addTest('unshift-shift', function(result, cx) {
+it('unshift-shift', function() {
// Unshift one at a time.
var ary = [];
for (var i = 0; i < 10; i++) {
@@ -104,14 +103,12 @@
for (var i = 0; i < 5; i++) {
assert.equal(ary[i], shiftary[i], 'i:' + i);
}
-
- result.pass();
});
/**
* Test cursor positioning functionality.
*/
-hterm.Screen.Tests.addTest('cursor-movement', function(result, cx) {
+it('cursor-movement', function() {
var ary = [];
for (var i = 0; i < 3; i++) {
@@ -201,14 +198,12 @@
assert.strictEqual(this.screen.cursorRowNode_, ary[2]);
assert.strictEqual(this.screen.cursorNode_, ary[2].childNodes[4]);
assert.equal(this.screen.cursorOffset_, 10);
-
- result.pass();
});
/**
* Test character removal.
*/
-hterm.Screen.Tests.addTest('delete-chars', function(result, cx) {
+it('delete-chars', function() {
var row = document.createElement('div');
row.innerHTML = 'hello<div id="1"> </div><div id="2">world</div>';
this.screen.pushRow(row);
@@ -246,15 +241,13 @@
this.screen.deleteChars(6);
assert.equal(wc_row.innerHTML, '');
-
- result.pass();
});
/**
* Test replacing the start of a wide character with a narrow char.
* https://crbug.com/577691
*/
-hterm.Screen.Tests.addTest('wide-to-narrow-char-start', function(result, cx) {
+it('wide-to-narrow-char-start', function() {
const row = document.createElement('div');
this.screen.pushRow(row);
@@ -273,15 +266,13 @@
this.screen.setCursorPosition(0, 2);
this.screen.overwriteString('x');
assert.equal('abx ef', row.textContent);
-
- result.pass();
});
/**
* Test replacing the end of a wide character with a narrow char.
* https://crbug.com/577691
*/
-hterm.Screen.Tests.addTest('wide-to-narrow-char-end', function(result, cx) {
+it('wide-to-narrow-char-end', function() {
const row = document.createElement('div');
this.screen.pushRow(row);
@@ -300,14 +291,12 @@
this.screen.setCursorPosition(0, 3);
this.screen.overwriteString('x');
assert.equal('ab xef', row.textContent);
-
- result.pass();
});
/**
* Test the ability to insert text in a line.
*/
-hterm.Screen.Tests.addTest('insert', function(result, cx) {
+it('insert', function() {
// Sample rows. Row 0 is a simple, empty row. Row 1 simulates rows with
// mixed text attributes.
var ary = [document.createElement('div'), document.createElement('div'),
@@ -403,14 +392,12 @@
'<span class="wc-node">\u6587</span>' +
'<span class="wc-node">\u5B57</span>' +
'<span class="wc-node">\u4E32</span>XX');
-
- result.pass();
});
/**
* Test the ability to overwrite test.
*/
-hterm.Screen.Tests.addTest('overwrite', function(result, cx) {
+it('overwrite', function() {
var ary = [];
ary[0] = document.createElement('div');
ary[0].innerHTML = 'hello<div id="1"> </div><div id="2">world</div>';
@@ -505,14 +492,12 @@
' ' +
'<span class="wc-node">\u5B57</span>' +
'<span class="wc-node">\u4E32</span>');
-
- result.pass();
});
/**
* Check whitespace insertion handling.
*/
-hterm.Screen.Tests.addTest('whitespace-fill', function(result, cx) {
+it('whitespace-fill', function() {
const ta = this.screen.textAttributes;
const row = document.createElement('div');
this.screen.pushRow(row);
@@ -593,15 +578,13 @@
'style: wavy; text-decoration-line: underline;">bye</span>');
ta.reset();
this.screen.clearCursorRow();
-
- result.pass();
});
/**
* Test expanding strings when selecting.
*/
-hterm.Screen.Tests.addTest('expand-selection', function(result, cx) {
- const document = cx.window.document;
+it('expand-selection', function() {
+ const document = window.document;
const row = document.createElement('x-row');
document.body.appendChild(row);
@@ -635,6 +618,6 @@
assert.equal('https://www.google.com/', selection.toString());
document.body.removeChild(row);
+});
- result.pass();
});
diff --git a/hterm/js/hterm_scrollport_tests.js b/hterm/js/hterm_scrollport_tests.js
index cb893ca..4c3f4e5 100644
--- a/hterm/js/hterm_scrollport_tests.js
+++ b/hterm/js/hterm_scrollport_tests.js
@@ -4,6 +4,10 @@
'use strict';
+describe('hterm_scrollport_tests.js', () => {
+
+describe('scrollport', () => {
+
/**
* A mock accessibility reader which will simply record the last string passed
* to assertiveAnnounce.
@@ -23,17 +27,15 @@
this.lastStringAnnounced = str;
};
-hterm.ScrollPort.Tests = new lib.TestManager.Suite('hterm.ScrollPort.Tests');
-
/**
* Set up some common state.
*/
-hterm.ScrollPort.Tests.prototype.setup = function(cx) {
+before(function() {
this.visibleColumnCount = 80;
this.visibleRowCount = 25;
this.totalRowCount = 10000;
- var document = cx.window.document;
+ const document = window.document;
this.rowProvider = new MockRowProvider(document, this.totalRowCount);
@@ -44,14 +46,21 @@
div.style.height = '100%';
div.style.width = '100%';
document.body.appendChild(div);
-};
+});
+
+/**
+ * Remove the scrollport we added earlier.
+ */
+after(function() {
+ document.body.removeChild(this.div);
+});
/**
* Ensure the selection is collapsed, row caching is on, and we've got a fresh
* scrollport to test on.
*/
-hterm.ScrollPort.Tests.prototype.preamble = function(result, cx, done) {
- var selection = cx.window.getSelection();
+beforeEach(function(done) {
+ const selection = window.getSelection();
if (!selection.isCollapsed)
selection.collapseToStart();
@@ -64,22 +73,22 @@
this.scrollPort.resize();
done();
});
-};
+});
/**
* Delete the scrollport we created for the test.
*/
-hterm.ScrollPort.Tests.prototype.postamble = function(result, cx) {
+afterEach(function() {
while (this.div.firstChild) {
this.div.removeChild(this.div.firstChild);
}
-};
+});
/**
* Basic test to make sure that the viewport contains the right number of
* rows at the right places after some scrolling.
*/
-hterm.ScrollPort.Tests.addTest('basic-scroll', function(result, cx) {
+it('basic-scroll', function() {
var topRow = this.scrollPort.getTopRowIndex();
assert.equal(topRow, 0);
assert.equal(this.scrollPort.getBottomRowIndex(topRow),
@@ -90,14 +99,12 @@
assert.equal(topRow, this.totalRowCount - this.visibleRowCount);
assert.equal(this.scrollPort.getBottomRowIndex(topRow),
this.totalRowCount - 1);
-
- result.pass();
});
/**
* Do not scroll for prevented, or non-cancelable wheel events.
*/
-hterm.ScrollPort.Tests.addTest('scroll-cancelable', function(result, cx) {
+it('scroll-cancelable', function() {
assert.equal(this.scrollPort.getTopRowIndex(), 0);
const rowsToScroll = 10;
const rowAfterEvent = (options) => {
@@ -116,14 +123,12 @@
// Scroll if not prevented, and cancelable.
assert.equal(rowAfterEvent({cancelable: true}), rowsToScroll);
-
- result.pass();
});
/**
* Make sure the hterm.ScrollPort is reusing the same row nodes when it can.
*/
-hterm.ScrollPort.Tests.addTest('node-recycler', function(result, cx) {
+it('node-recycler', function() {
// Force a sync redraw before we get started so we know we're done
// calling getRowNode.
this.scrollPort.redraw_();
@@ -138,14 +143,12 @@
// Scrolling from 0 to 1 should result in only one call to getRowNode.
assert.equal(count, 1);
-
- result.pass();
});
/**
* Make sure the selection is maintained even after scrolling off screen.
*/
-hterm.ScrollPort.Tests.addTest('scroll-selection', function(result, cx) {
+it('scroll-selection', function() {
var doc = this.scrollPort.getDocument();
var s = doc.getSelection();
@@ -153,7 +156,7 @@
// an approximation using addRange, but it automatically merges sibling
// ranges and selects the parent node. Ignore this test on IE for now.
if (!s.extend) {
- result.pass();
+ return;
}
// Scroll into a part of the buffer that can be scrolled off the top
@@ -190,15 +193,12 @@
assert.strictEqual(anchorNode, s.anchorNode);
assert.strictEqual(focusNode, s.focusNode);
}
-
- result.pass();
});
/**
* Make sure the selection is maintained for a collapsed selection.
*/
-hterm.ScrollPort.Tests.addTest(
- 'scroll-selection-collapsed', function(result, cx) {
+it('scroll-selection-collapsed', function() {
const doc = this.scrollPort.getDocument();
const s = doc.getSelection();
@@ -260,26 +260,23 @@
assert.notStrictEqual(anchorNode, s.anchorNode);
assert.notStrictEqual(anchorNode, s.focusNode);
-
- result.pass();
});
/**
* Test the select-all function.
*/
-hterm.ScrollPort.Tests.addTest('select-all', function(result, cx) {
+it('select-all', function() {
this.scrollPort.selectAll();
assert.equal(0, this.scrollPort.selection.startRow.rowIndex);
assert.equal(this.totalRowCount - 1,
this.scrollPort.selection.endRow.rowIndex);
- result.pass();
});
/**
* Test that the page up/down buttons are onscreen when selected but offscreen
* otherwise.
*/
-hterm.ScrollPort.Tests.addTest('page-up-down-visible', function(result, cx) {
+it('page-up-down-visible', function() {
const doc = this.scrollPort.getDocument();
this.scrollPort.allowScrollButtonsToDisplay_ = true;
@@ -312,8 +309,6 @@
assert.isAtMost(pageDown.getBoundingClientRect().bottom,
this.scrollPort.getScreenHeight());
-
- result.pass();
});
/**
@@ -321,7 +316,7 @@
* isn't enabled.
*
*/
-hterm.ScrollPort.Tests.addTest('page-up-down-hidden', function(result, cx) {
+it('page-up-down-hidden', function() {
const doc = this.scrollPort.getDocument();
this.scrollPort.allowScrollButtonsToDisplay_ = true;
@@ -354,14 +349,12 @@
assert.isAtLeast(pageDown.getBoundingClientRect().top,
this.scrollPort.getScreenHeight());
-
- result.pass();
});
/**
* Test that clicking page up/down causes the viewport to scroll up/down.
*/
-hterm.ScrollPort.Tests.addTest('page-up-down-scroll', function(result, cx) {
+it('page-up-down-scroll', function() {
const doc = this.scrollPort.getDocument();
const topRow = 50;
@@ -375,15 +368,13 @@
const pageUp = doc.getElementById('hterm:a11y:page-up');
pageUp.dispatchEvent(new Event('click'));
assert.equal(this.scrollPort.getTopRowIndex(), topRow);
-
- result.pass();
});
/**
* Test that the page up/down buttons are enabled/disabled correctly at the top
* and bottom of the scrollport.
*/
-hterm.ScrollPort.Tests.addTest('page-up-down-state', function(result, cx) {
+it('page-up-down-state', function() {
const doc = this.scrollPort.getDocument();
const pageUp = doc.getElementById('hterm:a11y:page-up');
const pageDown = doc.getElementById('hterm:a11y:page-down');
@@ -402,15 +393,13 @@
this.scrollPort.redraw_();
assert.equal(pageUp.getAttribute('aria-disabled'), 'false');
assert.equal(pageDown.getAttribute('aria-disabled'), 'true');
-
- result.pass();
});
/**
* Test that paging up/down causes the screen contents to be announced
* correctly.
*/
-hterm.ScrollPort.Tests.addTest('page-up-down-announce', function(result, cx) {
+it('page-up-down-announce', function() {
const doc = this.scrollPort.getDocument();
this.scrollPort.scrollRowToTop(0);
@@ -514,16 +503,13 @@
'This is line 2046 red green yellow blue magenta cyan\n' +
'This is line 2047 red green yellow blue magenta cyan\n' +
'This is line 2048 red green yellow blue magenta cyan\n');
-
- result.pass();
});
/**
* Test that paging up/down when at the top/bottom of the screen doesn't trigger
* any announcement.
*/
-hterm.ScrollPort.Tests.addTest(
- 'page-up-down-dont-announce', function(result, cx) {
+it('page-up-down-dont-announce', function() {
const doc = this.scrollPort.getDocument();
this.scrollPort.scrollRowToTop(0);
@@ -538,14 +524,12 @@
const pageDown = doc.getElementById('hterm:a11y:page-down');
pageDown.dispatchEvent(new Event('click'));
assert.equal(mockAccessibilityReader.lastStringAnnounced, '');
-
- result.pass();
});
/**
* Make sure that offscreen elements are marked aria-hidden.
*/
-hterm.ScrollPort.Tests.addTest('scroll-selection-hidden', function(result, cx) {
+it('scroll-selection-hidden', function() {
const doc = this.scrollPort.getDocument();
const s = doc.getSelection();
@@ -553,7 +537,6 @@
// an approximation using addRange, but it automatically merges sibling
// ranges and selects the parent node. Ignore this test on IE for now.
if (!s.extend) {
- result.pass();
return;
}
@@ -598,8 +581,6 @@
assert.equal(anchorRow.getAttribute('aria-hidden'), 'true');
assert.equal(focusRow.getAttribute('aria-hidden'), 'true');
-
- result.pass();
});
/**
@@ -609,8 +590,8 @@
* This should always be the last test of the suite, since it leaves the user
* with a full page scrollPort to poke at.
*/
-hterm.ScrollPort.Tests.addTest('fullscreen', function(result, cx) {
- var document = cx.window.document;
+it('fullscreen', function() {
+ const document = window.document;
const rowProvider = new MockRowProvider(document, this.totalRowCount);
@@ -630,12 +611,11 @@
assert.equal(divSize.height, hterm.getClientHeight(scrollPort.iframe_));
document.body.removeChild(div);
-
- result.pass();
});
-hterm.ScrollPort.DragAndDropTests =
- new lib.TestManager.Suite('hterm.ScrollPort.DragAndDrop.Tests');
+});
+
+describe('DragAndDrop', () => {
/**
* We can't generate useful DragEvents as the dataTransfer member is forced
@@ -648,100 +628,90 @@
this.preventDefault = () => {};
};
-hterm.ScrollPort.DragAndDropTests.prototype.preamble = function(cx) {
+beforeEach(function() {
// Create a new port since so the subscribe event doesn't stick to
// this.scrollPort across multiple tests.
this.scrollPort = new hterm.ScrollPort();
-};
+});
/**
* A single text/plain element.
*/
-hterm.ScrollPort.DragAndDropTests.addTest('drag-drop-text', function(result, cx) {
+it('drag-drop-text', function(done) {
const e = new MockDragEvent();
e.dataTransfer.setData('text/plain', 'plain');
this.scrollPort.subscribe('paste', (e) => {
assert.equal('plain', e.text);
- result.pass();
+ done();
});
this.scrollPort.onDragAndDrop_(e);
-
- result.requestTime(200);
});
/**
* Pick between text & html based on shift key not pressed.
*/
-hterm.ScrollPort.DragAndDropTests.addTest('drag-drop-text-no-shift', function(result, cx) {
+it('drag-drop-text-no-shift', function(done) {
const e = new MockDragEvent();
e.dataTransfer.setData('text/html', 'html');
e.dataTransfer.setData('text/plain', 'plain');
this.scrollPort.subscribe('paste', (e) => {
assert.equal('plain', e.text);
- result.pass();
+ done();
});
this.scrollPort.onDragAndDrop_(e);
-
- result.requestTime(200);
});
/**
* Pick between text & html based on shift key pressed.
*/
-hterm.ScrollPort.DragAndDropTests.addTest('drag-drop-text-shift', function(result, cx) {
+it('drag-drop-text-shift', function(done) {
const e = new MockDragEvent(true /* shift */);
e.dataTransfer.setData('text/html', 'html');
e.dataTransfer.setData('text/plain', 'plain');
this.scrollPort.subscribe('paste', (e) => {
assert.equal('html', e.text);
- result.pass();
+ done();
});
this.scrollPort.onDragAndDrop_(e);
-
- result.requestTime(200);
});
/**
* Verify fallback when first source is empty & shift key is not pressed.
*/
-hterm.ScrollPort.DragAndDropTests.addTest('drag-drop-text-fallback-no-shift', function(result, cx) {
+it('drag-drop-text-fallback-no-shift', function(done) {
const e = new MockDragEvent();
e.dataTransfer.setData('text/html', '');
e.dataTransfer.setData('text/plain', 'plain');
this.scrollPort.subscribe('paste', (e) => {
assert.equal('plain', e.text);
- result.pass();
+ done();
});
this.scrollPort.onDragAndDrop_(e);
-
- result.requestTime(200);
});
/**
* Verify fallback when first source is empty & shift key is pressed.
*/
-hterm.ScrollPort.DragAndDropTests.addTest('drag-drop-text-fallback-shift', function(result, cx) {
+it('drag-drop-text-fallback-shift', function(done) {
const e = new MockDragEvent(true /* shift */);
e.dataTransfer.setData('text/html', '');
e.dataTransfer.setData('text/plain', 'plain');
this.scrollPort.subscribe('paste', (e) => {
assert.equal('plain', e.text);
- result.pass();
+ done();
});
this.scrollPort.onDragAndDrop_(e);
-
- result.requestTime(200);
});
/**
* Verify paste doesn't happen if it's disabled.
*/
-hterm.ScrollPort.DragAndDropTests.addTest('drag-drop-disabled', function(result, cx) {
+it('drag-drop-disabled', function() {
const e = new MockDragEvent();
this.scrollPort.subscribe('paste', assert.fail);
@@ -749,15 +719,12 @@
e.dataTransfer.setData('text/plain', 'plain');
this.scrollPort.onDragAndDrop_(e);
-
- result.requestTime(1000);
- setTimeout(() => result.pass(), 100);
});
/**
* Verify bad sources don't trigger paste events.
*/
-hterm.ScrollPort.DragAndDropTests.addTest('drag-drop-unusable', function(result, cx) {
+it('drag-drop-unusable', function() {
const e = new MockDragEvent();
this.scrollPort.subscribe('paste', assert.fail);
@@ -768,7 +735,8 @@
// Neither should empty text.
e.dataTransfer.setData('text/plain', '');
this.scrollPort.onDragAndDrop_(e);
+});
- result.requestTime(1000);
- setTimeout(() => result.pass(), 100);
+});
+
});
diff --git a/hterm/js/hterm_terminal_io_tests.js b/hterm/js/hterm_terminal_io_tests.js
index 8de2c15..8654829 100644
--- a/hterm/js/hterm_terminal_io_tests.js
+++ b/hterm/js/hterm_terminal_io_tests.js
@@ -8,7 +8,7 @@
* @fileoverview hterm.Terminal.IO unit tests.
*/
-hterm.Terminal.IO.Tests = new lib.TestManager.Suite('hterm.Terminal.IO.Tests');
+describe('hterm_terminal_io_tests.js', () => {
/**
* Simple mock Terminal object for an IO object's needs.
@@ -45,15 +45,15 @@
*
* Called before each test case in this suite.
*/
-hterm.Terminal.IO.Tests.prototype.preamble = function(result, cx) {
+beforeEach(function() {
this.mockTerm = new MockTerminalForIO();
this.io = this.mockTerm.io.push();
-};
+});
/**
* Check print functionality.
*/
-hterm.Terminal.IO.Tests.addTest('print', function(result, cx) {
+it('print', function() {
this.io.print('');
assert.equal('', this.mockTerm.buffer);
@@ -65,14 +65,12 @@
this.io.print('bc');
assert.equal('abc', this.mockTerm.buffer);
-
- result.pass();
});
/**
* Check println functionality.
*/
-hterm.Terminal.IO.Tests.addTest('println', function(result, cx) {
+it('println', function() {
this.io.println('a');
assert.equal('a\r\n', this.mockTerm.buffer);
@@ -81,14 +79,12 @@
this.io.println('');
assert.equal('a\r\nbc\r\n', this.mockTerm.buffer);
-
- result.pass();
});
/**
* Verify pushing/popping works.
*/
-hterm.Terminal.IO.Tests.addTest('push-pop', function(result, cx) {
+it('push-pop', function() {
const io1 = this.io.push();
io1.print('Hello');
assert.equal('Hello', this.mockTerm.buffer);
@@ -104,26 +100,22 @@
this.io.print('Bye');
assert.equal('HelloWorldItsMeBye', this.mockTerm.buffer);
-
- result.pass();
});
/**
* Verify profile selection.
*/
-hterm.Terminal.IO.Tests.addTest('profile-selection', function(result, cx) {
+it('profile-selection', function() {
assert.equal('', this.mockTerm.profileName);
this.io.setTerminalProfile('foo');
assert.equal('foo', this.mockTerm.profileName);
-
- result.pass();
});
/**
* Check overlay display.
*/
-hterm.Terminal.IO.Tests.addTest('overlay', function(result, cx) {
+it('overlay', function() {
// Start with default timeout.
this.io.showOverlay('msg');
assert.equal(1, this.mockTerm.showCount);
@@ -147,14 +139,12 @@
assert.equal(3, this.mockTerm.showCount);
assert.isFalse(this.mockTerm.overlayVisible);
assert.equal('hi', this.mockTerm.overlayMessage);
-
- result.pass();
});
/**
* Check background IO objects.
*/
-hterm.Terminal.IO.Tests.addTest('buffer-background', function(result, cx) {
+it('buffer-background', function() {
// Create a new foreground IO and show some stuff.
const io = this.io.push();
io.print('Fore');
@@ -171,6 +161,6 @@
// And we should resume OK.
this.io.print('Done');
assert.equal('ForeBackDone', this.mockTerm.buffer);
+});
- result.pass();
});
diff --git a/hterm/js/hterm_terminal_tests.js b/hterm/js/hterm_terminal_tests.js
index 643e43c..d2e7cd6 100644
--- a/hterm/js/hterm_terminal_tests.js
+++ b/hterm/js/hterm_terminal_tests.js
@@ -8,9 +8,9 @@
* @fileoverview hterm.Terminal unit tests.
*/
-hterm.Terminal.Tests = new lib.TestManager.Suite('hterm.Terminal.Tests');
+describe('hterm_terminal_tests.js', () => {
-hterm.Terminal.Tests.prototype.setup = function(cx) {
+before(function() {
this.visibleColumnCount = 80;
this.visibleRowCount = 24;
@@ -20,7 +20,7 @@
this.imageArrayBuffer = lib.codec.stringToCodeUnitArray(
this.imageBase64, Uint8Array).buffer;
this.imageBlob = new Blob([this.imageArrayBuffer]);
-};
+});
/**
* Clear out the current document and create a new hterm.Terminal object for
@@ -28,8 +28,8 @@
*
* Called before each test case in this suite.
*/
-hterm.Terminal.Tests.prototype.preamble = function(result, cx, done) {
- var document = cx.window.document;
+beforeEach(function(done) {
+ const document = window.document;
var div = this.div = document.createElement('div');
div.style.position = 'absolute';
@@ -38,7 +38,7 @@
document.body.appendChild(div);
- cx.window.terminal = this.terminal = new hterm.Terminal();
+ this.terminal = new hterm.Terminal();
this.terminal.decorate(div);
this.terminal.setHeight(this.visibleRowCount);
@@ -49,18 +49,17 @@
};
MockNotification.start();
-};
+});
/**
* Restore any mocked out objects.
*
* Called after each test case in this suite.
*/
-hterm.Terminal.Tests.prototype.postamble = function(result, cx) {
+afterEach(function() {
MockNotification.stop();
-
document.body.removeChild(this.div);
-};
+});
/**
* How long to wait for image display tests to timeout.
@@ -69,13 +68,13 @@
* running in the background (e.g. the window/tab isn't focused), then Chrome
* will deprioritize it causing JS/image loading/etc... to take longer.
*/
-hterm.Terminal.Tests.DISPLAY_IMAGE_TIMEOUT = 5000;
+const DISPLAY_IMAGE_TIMEOUT = 5000;
/**
* Checks that the dimensions of the scrollport match the dimensions of the
* values that the Terminal was constructed with.
*/
-hterm.Terminal.Tests.addTest('dimensions', function(result, cx) {
+it('dimensions', function() {
var divSize = hterm.getClientSize(this.div);
var scrollPort = this.terminal.scrollPort_;
var innerWidth = Math.round(
@@ -93,24 +92,19 @@
assert.equal(this.terminal.screen_.getWidth(), this.visibleColumnCount);
assert.equal(this.terminal.screen_.getHeight(), this.visibleRowCount);
-
- result.pass();
});
/**
* Fill the screen with 'X' characters one character at a time, in a way
* that should stress the cursor positioning code.
*/
-hterm.Terminal.Tests.addTest('plaintext-stress-cursor-ltr',
- function(result, cx) {
+it('plaintext-stress-cursor-ltr', function() {
for (var col = 0; col < this.visibleColumnCount; col++) {
for (var row = 0; row < this.visibleRowCount; row++) {
this.terminal.screen_.setCursorPosition(row, col);
this.terminal.screen_.insertString('X');
}
}
-
- result.pass();
});
/**
@@ -118,16 +112,13 @@
* that should stress the cursor positioning code and the overwriteString()
* code.
*/
-hterm.Terminal.Tests.addTest('plaintext-stress-cursor-rtl',
- function(result, cx) {
+it('plaintext-stress-cursor-rtl', function() {
for (var col = this.visibleColumnCount - 1; col >= 0; col--) {
for (var row = 0; row < this.visibleRowCount; row++) {
this.terminal.screen_.setCursorPosition(row, col);
this.terminal.screen_.overwriteString('X');
}
}
-
- result.pass();
});
/**
@@ -136,8 +127,7 @@
* This test doesn't actually assert anything, but the timing data in the test
* log is useful.
*/
-hterm.Terminal.Tests.addTest('plaintext-stress-insert',
- function(result, cx) {
+it('plaintext-stress-insert', function(done) {
var chunkSize = 1000;
var testCount = 10;
var self = this;
@@ -151,9 +141,8 @@
}
if (count + 1 >= testCount) {
- result.pass();
+ done();
} else {
- result.requestTime(200);
setTimeout(test, 0, count + 1);
}
}
@@ -165,8 +154,7 @@
* Test that accounting of desktop notifications works, and that they are
* closed under the right circumstances.
*/
-hterm.Terminal.Tests.addTest('desktop-notification-bell-test',
- function(result, cx) {
+it('desktop-notification-bell-test', function() {
this.terminal.desktopNotificationBell_ = true;
// If we have focus, then no notifications should show.
@@ -206,14 +194,12 @@
this.terminal.bellNotificationList_[0].onclick(null);
assert.equal(0, this.terminal.bellNotificationList_.length);
assert.equal(0, Notification.count);
-
- result.pass();
});
/**
* Verify showing an overlay will also announce the message.
*/
-hterm.Terminal.Tests.addTest('show-overlay-announce', function(result, cx) {
+it('show-overlay-announce', function() {
const liveElement = this.terminal.accessibilityReader_.assertiveLiveElement_;
this.terminal.showOverlay('test');
@@ -221,14 +207,12 @@
this.terminal.showOverlay('hello');
assert.equal('hello', liveElement.getAttribute('aria-label'));
-
- result.pass();
});
/**
* Selection should be sync'd to the cursor when the selection is collapsed.
*/
-hterm.Terminal.Tests.addTest('sync-collapsed-selection', function(result, cx) {
+it('sync-collapsed-selection', function(done) {
this.terminal.print('foo');
this.terminal.newLine();
this.terminal.print('bar');
@@ -238,21 +222,19 @@
const selection = this.terminal.document_.getSelection();
assert.equal('bar', selection.anchorNode.textContent);
assert.equal(3, selection.anchorOffset);
- result.pass();
+ done();
});
-
- result.requestTime(500);
});
/**
* Selection should not be sync'd to the cursor when the selection is not
* collapsed. This avoids clearing selection that has been set by the user.
*/
-hterm.Terminal.Tests.addTest('sync-uncollapsed-selection', function(result, cx) {
+it('sync-uncollapsed-selection', function(done) {
this.terminal.print('foo');
this.terminal.newLine();
// Select the text 'foo'
- const firstRow = terminal.getRowNode(0).firstChild;
+ const firstRow = this.terminal.getRowNode(0).firstChild;
this.terminal.document_.getSelection().setBaseAndExtent(
firstRow, 0, firstRow, 3);
this.terminal.print('bar');
@@ -264,25 +246,22 @@
assert.equal(0, selection.anchorOffset);
assert.equal('foo', selection.focusNode.textContent);
assert.equal(3, selection.focusOffset);
- result.pass();
+ done();
});
-
- result.requestTime(500);
});
/**
* With accessibility enabled, selection should be sync'd to the cursor even
* when the selection is not collapsed, as long as there is a user gesture.
*/
-hterm.Terminal.Tests.addTest('sync-uncollapsed-selection-a11y',
- function(result, cx) {
+it('sync-uncollapsed-selection-a11y', function(done) {
this.terminal.setAccessibilityEnabled(true);
this.terminal.accessibilityReader_.hasUserGesture = true;
this.terminal.print('foo');
this.terminal.newLine();
// Select the text 'foo'
- const firstRow = terminal.getRowNode(0).firstChild;
+ const firstRow = this.terminal.getRowNode(0).firstChild;
this.terminal.document_.getSelection().setBaseAndExtent(
firstRow, 0, firstRow, 3);
this.terminal.print('bar');
@@ -292,17 +271,15 @@
const selection = this.terminal.document_.getSelection();
assert.equal('bar', selection.anchorNode.textContent);
assert.equal(3, selection.anchorOffset);
- result.pass();
+ done();
});
-
- result.requestTime(500);
});
/**
* Ensure that focussing the scrollPort will cause the selection to sync to the
* caret.
*/
-hterm.Terminal.Tests.addTest('scrollport-focus-cursor', function(result, cx) {
+it('scrollport-focus-cursor', function(done) {
this.terminal.print('foo');
this.terminal.newLine();
this.terminal.print('bar');
@@ -310,24 +287,23 @@
// Wait for selection to sync to the caret.
setTimeout(() => {
// Manually change the selection and trigger focus.
- this.terminal.document_.getSelection().collapse(terminal.getRowNode(0), 0);
+ this.terminal.document_.getSelection().collapse(
+ this.terminal.getRowNode(0), 0);
this.terminal.scrollPort_.focus();
setTimeout(() => {
const selection = this.terminal.document_.getSelection();
assert.equal('bar', selection.anchorNode.textContent);
assert.equal(3, selection.anchorOffset);
- result.pass();
+ done();
});
});
-
- result.requestTime(1000);
});
/**
* Test that focus sequences are passed as expected when focus reporting is
* turned on, and nothing is passed when reporting is off.
*/
-hterm.Terminal.Tests.addTest('focus-reporting', function(result, cx) {
+it('focus-reporting', function() {
var resultString = '';
this.terminal.io.sendString = (str) => resultString = str;
@@ -345,14 +321,12 @@
assert.equal(resultString, '');
this.terminal.onFocusChange_(true);
assert.equal(resultString, '');
-
- result.pass();
});
/**
* Verify saved cursors have per-screen state.
*/
-hterm.Terminal.Tests.addTest('per-screen-cursor-state', function(result, cx) {
+it('per-screen-cursor-state', function() {
const terminal = this.terminal;
const vt = terminal.vt;
@@ -420,27 +394,23 @@
assert.equal(8, terminal.getCursorColumn());
assert.equal('G2', vt.GL);
assert.equal('G3', vt.GR);
-
- result.pass();
});
/**
* Check image display handling when disabled.
*/
-hterm.Terminal.Tests.addTest('display-img-disabled', function(result, cx) {
+it('display-img-disabled', function() {
this.terminal.allowImagesInline = false;
this.terminal.displayImage({uri: ''});
const text = this.terminal.getRowsText(0, 1);
assert.equal('Inline Images Disabled', text);
-
- result.pass();
});
/**
* Check image display handling when not yet decided.
*/
-hterm.Terminal.Tests.addTest('display-img-prompt', function(result, cx) {
+it('display-img-prompt', function() {
this.terminal.allowImagesInline = null;
// Search for the block & allow buttons.
@@ -448,14 +418,12 @@
const text = this.terminal.getRowsText(0, 1);
assert.include(text.toLowerCase(), 'block');
assert.include(text.toLowerCase(), 'allow');
-
- result.pass();
});
/**
* Check simple image display handling.
*/
-hterm.Terminal.Tests.addTest('display-img-normal', function(result, cx) {
+it('display-img-normal', function(done) {
this.terminal.allowImagesInline = true;
// Callback when loading finishes.
@@ -468,7 +436,7 @@
assert.equal('center', container.style.textAlign);
assert.equal(2, img.clientHeight);
- result.pass();
+ done();
};
// Display an image that only takes up one row.
@@ -478,14 +446,12 @@
align: 'center',
uri: `data:application/octet-stream;base64,${this.imageBase64}`,
}, onLoad, assert.fail);
-
- result.requestTime(hterm.Terminal.Tests.DISPLAY_IMAGE_TIMEOUT);
-});
+}).timeout(DISPLAY_IMAGE_TIMEOUT);
/**
* Check handling of image dimensions.
*/
-hterm.Terminal.Tests.addTest('display-img-dimensions', function(result, cx) {
+it('display-img-dimensions', function(done) {
this.terminal.allowImagesInline = true;
// Callback when loading finishes.
@@ -504,7 +470,7 @@
assert.isAbove(img.clientWidth, bodyWidth * 0.70);
assert.isBelow(img.clientWidth, bodyWidth * 0.80);
- result.pass();
+ done();
};
// Display an image that only takes up one row.
@@ -514,14 +480,12 @@
inline: true,
uri: `data:application/octet-stream;base64,${this.imageBase64}`,
}, onLoad, assert.fail);
-
- result.requestTime(hterm.Terminal.Tests.DISPLAY_IMAGE_TIMEOUT);
-});
+}).timeout(DISPLAY_IMAGE_TIMEOUT);
/**
* Check handling of max image dimensions.
*/
-hterm.Terminal.Tests.addTest('display-img-max-dimensions', function(result, cx) {
+it('display-img-max-dimensions', function(done) {
this.terminal.allowImagesInline = true;
// Callback when loading finishes.
@@ -537,7 +501,7 @@
assert.equal(img.clientHeight, body.clientHeight);
assert.equal(img.clientWidth, body.clientWidth);
- result.pass();
+ done();
};
// Display an image that only takes up one row.
@@ -547,21 +511,19 @@
inline: true,
uri: `data:application/octet-stream;base64,${this.imageBase64}`,
}, onLoad, assert.fail);
-
- result.requestTime(hterm.Terminal.Tests.DISPLAY_IMAGE_TIMEOUT);
-});
+}).timeout(DISPLAY_IMAGE_TIMEOUT);
/**
* Check loading of invalid images doesn't wedge the terminal.
*/
-hterm.Terminal.Tests.addTest('display-img-invalid', function(result, cx) {
+it('display-img-invalid', function(done) {
this.terminal.allowImagesInline = true;
// Callback when loading finishes (i.e. failure triggers).
const onError = () => {
// The cursor should not have advanced.
assert.equal(0, this.terminal.getCursorRow());
- result.pass();
+ done();
};
// The data is invalid image content.
@@ -574,9 +536,7 @@
// TODO(vapier): Should figure this out.
setTimeout(onError, 0);
});
-
- result.requestTime(hterm.Terminal.Tests.DISPLAY_IMAGE_TIMEOUT);
-});
+}).timeout(DISPLAY_IMAGE_TIMEOUT);
/**
* Verify turning text blink on/off works.
@@ -584,7 +544,7 @@
* This test isn't great. Since we use CSS animations for everything, we
* assume that part is working, so we just check the stored timing values.
*/
-hterm.Terminal.Tests.addTest('text-blink', function(result, cx) {
+it('text-blink', function() {
// Default blink state is enabled.
this.terminal.setTextBlink();
assert.notEqual('0', this.terminal.getCssVar('blink-node-duration'));
@@ -596,14 +556,12 @@
// Explicitly turn it back on.
this.terminal.setTextBlink(true);
assert.notEqual('0', this.terminal.getCssVar('blink-node-duration'));
-
- result.pass();
});
/**
* Check mouse wheel emulation of arrow keys.
*/
-hterm.Terminal.Tests.addTest('mouse-wheel-arrow-keys', function(result, cx) {
+it('mouse-wheel-arrow-keys', function() {
const terminal = this.terminal;
let e;
@@ -645,14 +603,12 @@
e = MockTerminalMouseEvent('wheel', {deltaY: 2, deltaX: 2, deltaMode: 1});
terminal.onMouse_(e);
assert.equal('\x1bOB\x1bOB\x1bOC\x1bOC', resultString);
-
- result.pass();
});
/**
* Check mouse wheel emulation of arrow keys are disabled on primary screen.
*/
-hterm.Terminal.Tests.addTest('mouse-wheel-arrow-keys-primary', function(result, cx) {
+it('mouse-wheel-arrow-keys-primary', function() {
const terminal = this.terminal;
let e;
@@ -678,6 +634,6 @@
e = MockTerminalMouseEvent('wheel', {deltaY: 1, deltaMode: 1});
terminal.onMouse_(e);
assert.isUndefined(resultString);
+});
- result.pass();
});
diff --git a/hterm/js/hterm_test.js b/hterm/js/hterm_test.js
index 754cb53..59a8ca4 100644
--- a/hterm/js/hterm_test.js
+++ b/hterm/js/hterm_test.js
@@ -4,76 +4,32 @@
'use strict';
-var testManager;
-var testRun;
+/**
+ * @fileoverview Test framework setup when run inside the browser.
+ */
+// Setup the mocha framework.
+mocha.setup('bdd');
+mocha.checkLeaks();
+
+// Add a global shortcut to the assert API.
+const assert = chai.assert;
+
+// Catch any random errors before the test runner runs.
+let earlyError = null;
+window.onerror = function() {
+ earlyError = Array.from(arguments);
+};
+
+// Run the test framework once everything is finished.
window.onload = function() {
hterm.defaultStorage = new lib.Storage.Memory();
- lib.init(function() {
- testManager = new lib.TestManager();
- testManager.log.save = true;
+ lib.init(() => {
+ mocha.run();
- testManager.onTestRunComplete = (testRun) => {
- var document = testRun.cx.window.document;
- document.body.innerHTML = '';
-
- var results = document.createElement('div');
- var p, pre;
-
- p = document.createElement('p');
- p.innerText = 'Check JavaScript console for test log/status.';
- results.appendChild(p);
-
- p = document.createElement('p');
- p.id = 'status';
- p.innerText = 'Finished.';
- p.className = (testRun.failures.length == 0) ? 'good' : 'bad';
- results.appendChild(p);
-
- p = document.createElement('p');
- p.id = 'passed';
- p.className = 'good';
- document.title = p.innerText = testRun.passes.length + ' tests passed.';
- results.appendChild(p);
-
- p = document.createElement('p');
- p.id = 'failed';
- p.className = 'bad';
- if (testRun.failures.length != 0)
- document.title = p.innerText =
- 'ERROR: ' + testRun.failures.length + ' tests failed!';
- results.appendChild(p);
-
- pre = document.createElement('pre');
- pre.id = 'log';
- pre.innerText = testRun.testManager.log.data;
- results.appendChild(pre);
-
- // Only clear the body if everything passed in case the current rendering
- // is useful to debugging. Insert our log/results above it.
- if (testRun.failures.length == 0)
- document.body.innerText = '';
- document.body.insertBefore(results, document.body.firstChild);
- };
-
- testManager.testPreamble = (result, cx) => {
- var testRun = result.testRun;
- cx.window.document.title =
- '[' + (testRun.passes.length + testRun.failures.length) + '] ' +
- result.test.fullName;
- };
-
- testRun = testManager.createTestRun({window: window});
-
- // Stop after the first failure to make it easier to debug in the
- // JS console.
- testRun.maxFailures = 1;
-
- const params = new URLSearchParams(document.location.search);
- const pattern = params.get('pattern');
- testRun.selectPattern(new RegExp(pattern ? pattern : '.'));
- testRun.run();
-
- }, console.log.bind(console));
+ if (earlyError !== null) {
+ assert.fail(`uncaught exception detected:\n${earlyError.join('\n')}\n`);
+ }
+ });
};
diff --git a/hterm/js/hterm_tests.js b/hterm/js/hterm_tests.js
index adc62ef..337a5e5 100644
--- a/hterm/js/hterm_tests.js
+++ b/hterm/js/hterm_tests.js
@@ -8,32 +8,30 @@
* @fileoverview hterm unit tests. Specifically for core/high-level functions.
*/
-hterm.Tests = new lib.TestManager.Suite('hterm.Tests');
-
-hterm.notify.Tests = new lib.TestManager.Suite('hterm.notify.Tests');
+describe('hterm_tests.js', () => {
/**
* Mock out notifications.
*
* Called before each test case in this suite.
*/
-hterm.notify.Tests.prototype.preamble = function(result, cx) {
+beforeEach(() => {
MockNotification.start();
-};
+});
/**
* Restore any mocked out objects.
*
* Called after each test case in this suite.
*/
-hterm.notify.Tests.prototype.postamble = function(result, cx) {
+afterEach(() => {
MockNotification.stop();
-};
+});
/**
* Test that basic notifications work.
*/
-hterm.notify.Tests.addTest('default-notification', function(result, cx) {
+it('default-notification', () => {
var n;
// Create a default notification.
@@ -45,14 +43,12 @@
assert.equal(typeof n.title, 'string');
assert.notEqual(n.title, '');
assert.equal(n.body, '');
-
- result.pass();
});
/**
* Test that various notifications arguments work.
*/
-hterm.notify.Tests.addTest('notification-fields', function(result, cx) {
+it('notification-fields', () => {
var n;
// Create the notification.
@@ -63,15 +59,13 @@
// Check the parameters.
assert.include(n.title, 'title');
assert.equal(n.body, 'body');
-
- result.pass();
});
/**
* Test copying content via execCommand.
*/
-hterm.notify.Tests.addTest('copy-execCommand', function(result, cx) {
- const doc = cx.window.document;
+it('copy-execCommand', (done) => {
+ const doc = window.document;
// Mock out newer clipboard API to make sure we don't use it.
let oldClipboardWrite;
@@ -92,9 +86,13 @@
const s = doc.getSelection();
assert.equal('copypasta!', s.toString());
- result.pass();
+ done();
};
+ // Mock the newer API too.
+ navigator.clipboard.writeText = undefined;
+
hterm.copySelectionToClipboard(doc, 'copypasta!');
- result.requestTime(500);
+});
+
});
diff --git a/hterm/js/hterm_text_attributes_tests.js b/hterm/js/hterm_text_attributes_tests.js
index bae6f03..afc0c83 100644
--- a/hterm/js/hterm_text_attributes_tests.js
+++ b/hterm/js/hterm_text_attributes_tests.js
@@ -7,13 +7,13 @@
/**
* @fileoverview Unit tests for hterm.TextAttributes.
*/
-hterm.TextAttributes.Tests =
- new lib.TestManager.Suite('hterm.TextAttributes.Tests');
+
+describe('hterm_text_attributes_tests.js', () => {
/**
* Make sure isDefault works sanely.
*/
-hterm.TextAttributes.Tests.addTest('isDefault', function(result, cx) {
+it('isDefault', () => {
var tattrs = new hterm.TextAttributes();
// We should be in the default state initially.
@@ -26,15 +26,13 @@
// But resetting it gets us back.
tattrs.reset();
assert.isTrue(tattrs.isDefault());
-
- result.pass();
});
/**
* Make sure createContainer works sanely.
*/
-hterm.TextAttributes.Tests.addTest('createContainer', function(result, cx) {
- var tattrs = new hterm.TextAttributes(cx.window.document);
+it('createContainer', () => {
+ const tattrs = new hterm.TextAttributes(window.document);
var node;
// We don't check all the fields currently. Not clear it's worth the effort.
@@ -54,15 +52,13 @@
assert.equal(Node.ELEMENT_NODE, node.nodeType);
assert.isTrue(node.blinkNode);
assert.isTrue(node.asciiNode);
-
- result.pass();
});
/**
* Make sure matchesContainer works correctly.
*/
-hterm.TextAttributes.Tests.addTest('matchesContainer', function(result, cx) {
- var tattrs = new hterm.TextAttributes(cx.window.document);
+it('matchesContainer', () => {
+ const tattrs = new hterm.TextAttributes(window.document);
var node;
// For plain string, this is just isDefault.
@@ -78,15 +74,13 @@
node = tattrs.createContainer('asdf');
assert.equal(Node.ELEMENT_NODE, node.nodeType);
assert.isTrue(tattrs.matchesContainer(node));
-
- result.pass();
});
/**
* Check combination of text decorations.
*/
-hterm.TextAttributes.Tests.addTest('decoration-combos', function(result, cx) {
- const tattrs = new hterm.TextAttributes(cx.window.document);
+it('decoration-combos', () => {
+ const tattrs = new hterm.TextAttributes(window.document);
let node;
// Underline.
@@ -123,15 +117,13 @@
node = tattrs.createContainer('asdf');
assert.equal('underline line-through', node.style.textDecorationLine);
assert.equal('double', node.style.textDecorationStyle);
-
- result.pass();
});
/**
* Underline colors.
*/
-hterm.TextAttributes.Tests.addTest('underline-colors', function(result, cx) {
- const tattrs = new hterm.TextAttributes(cx.window.document);
+it('underline-colors', () => {
+ const tattrs = new hterm.TextAttributes(window.document);
let node;
tattrs.underline = 'solid';
@@ -157,15 +149,13 @@
assert.equal('underline', node.style.textDecorationLine);
assert.equal('solid', node.style.textDecorationStyle);
assert.equal('rgb(1, 2, 3)', node.style.textDecorationColor);
-
- result.pass();
});
/**
* Inverse color processing.
*/
-hterm.TextAttributes.Tests.addTest('inverse-colors', function(result, cx) {
- const tattrs = new hterm.TextAttributes(cx.window.document);
+it('inverse-colors', () => {
+ const tattrs = new hterm.TextAttributes(window.document);
let node;
// Set an attribute to force a container (rather than a text node),
@@ -215,15 +205,13 @@
node = tattrs.createContainer('asdf');
assert.equal(tattrs.backgroundSource, node.style.color);
assert.equal(tattrs.foregroundSource, node.style.backgroundColor);
-
- result.pass();
});
/**
* Handling of invisible tags.
*/
-hterm.TextAttributes.Tests.addTest('invisible', function(result, cx) {
- const tattrs = new hterm.TextAttributes(cx.window.document);
+it('invisible', () => {
+ const tattrs = new hterm.TextAttributes(window.document);
let node;
// Set an attribute to force a container (rather than a text node),
@@ -241,15 +229,13 @@
node = tattrs.createContainer('asdf');
assert.equal(tattrs.backgroundSource, node.style.color);
assert.equal(tattrs.backgroundSource, node.style.backgroundColor);
-
- result.pass();
});
/**
* Check color palette reset.
*/
-hterm.TextAttributes.Tests.addTest('reset-color-palette', function(result, cx) {
- const tattrs = new hterm.TextAttributes(cx.window.document);
+it('reset-color-palette', () => {
+ const tattrs = new hterm.TextAttributes(window.document);
// The color entries we'll test.
const indices = [0, 7, 15, 31, 63, 127, 255];
@@ -268,15 +254,13 @@
indices.forEach((index) => {
assert.isTrue(tattrs.colorPalette[index] != custom);
});
-
- result.pass();
});
/**
* Check individual color reset.
*/
-hterm.TextAttributes.Tests.addTest('reset-color', function(result, cx) {
- const tattrs = new hterm.TextAttributes(cx.window.document);
+it('reset-color', () => {
+ const tattrs = new hterm.TextAttributes(window.document);
// The color entries we'll test.
const indices = [0, 7, 15, 31, 63, 127, 255];
@@ -303,11 +287,9 @@
// Shouldn't do anything.
tattrs.resetColor('alskdjf');
-
- result.pass();
});
-hterm.TextAttributes.Tests.addTest('splitWidecharString-ascii', function(result, cx) {
+it('splitWidecharString-ascii', () => {
var text = 'abcdefghijklmn';
var actual = hterm.TextAttributes.splitWidecharString(text);
@@ -315,11 +297,9 @@
assert.equal(actual[0].str, text,
"The text doesn't have enough content.");
assert.isTrue(!actual[0].wcNode, "The text shouldn't be wide.");
-
- result.pass();
});
-hterm.TextAttributes.Tests.addTest('splitWidecharString-wide', function(result, cx) {
+it('splitWidecharString-wide', () => {
var text = 'abcd\u3041\u3042def\u3043ghi';
var actual = hterm.TextAttributes.splitWidecharString(text);
@@ -342,11 +322,9 @@
assert.equal(actual[5].str, 'ghi',
'Failed to obtain the sixth segment');
assert.isTrue(!actual[5].wcNode, "Sixth segment shouldn't be wide");
-
- result.pass();
});
-hterm.TextAttributes.Tests.addTest('splitWidecharString-surrogates', function(result, cx) {
+it('splitWidecharString-surrogates', () => {
var text = 'abc\uD834\uDD00\uD842\uDD9D';
var actual = hterm.TextAttributes.splitWidecharString(text);
@@ -358,16 +336,14 @@
'The second segment should be a wide character built by ' +
'a surrogate pair');
assert.isTrue(actual[1].wcNode, 'The second segment should be wide');
-
- result.pass();
});
-hterm.TextAttributes.Tests.addTest('splitWidecharString-ccs', function(result, cx) {
+it('splitWidecharString-ccs', () => {
var text = 'xA\u030Ax';
var actual = hterm.TextAttributes.splitWidecharString(text);
assert.equal(actual.length, 1, 'Failed to split combining sequences.');
assert.equal(actual[0].str, text);
+});
- result.pass();
});
diff --git a/hterm/js/hterm_vt_canned_tests.js b/hterm/js/hterm_vt_canned_tests.js
index 4af4cb5..5fab53c 100644
--- a/hterm/js/hterm_vt_canned_tests.js
+++ b/hterm/js/hterm_vt_canned_tests.js
@@ -59,12 +59,12 @@
* ignored.
*/
-hterm.VT.CannedTests = new lib.TestManager.Suite('hterm.VT.CannedTests');
+describe('hterm_vt_canned_tests.js', () => {
-hterm.VT.CannedTests.prototype.setup = function(cx) {
+before(function() {
this.visibleColumnCount = 80;
this.visibleRowCount = 25;
-};
+});
/**
* Clear out the current document and create a new hterm.Terminal object for
@@ -72,8 +72,8 @@
*
* Called before each test case in this suite.
*/
-hterm.VT.CannedTests.prototype.preamble = function(result, cx, done) {
- var document = cx.window.document;
+beforeEach(function(done) {
+ const document = window.document;
var div = document.createElement('div');
div.style.position = 'absolute';
@@ -81,7 +81,7 @@
this.div = div;
- cx.window.terminal = this.terminal = new hterm.Terminal();
+ this.terminal = new hterm.Terminal();
// Allow column width changes by default so the canned data can request a
// known terminal width.
@@ -100,18 +100,17 @@
done();
};
-};
+});
/**
* Ensure that blink is off after the test so we don't have runaway timeouts.
*
* Called after each test case in this suite.
*/
-hterm.VT.CannedTests.prototype.postamble = function(result, cx) {
+afterEach(function() {
this.terminal.setCursorBlink(false);
-
document.body.removeChild(this.div);
-};
+});
/**
* Test a can of data.
@@ -120,7 +119,7 @@
* test.
* @param {string} name The name of canned test.
*/
-hterm.VT.CannedTests.prototype.testCannedData = function(result, name) {
+const testData = function(terminal, name) {
let data = lib.resource.getData(`hterm/test/canned/${name}`);
var m = data.match(/^(#[^\n]*\n)*@@ HEADER_START/);
@@ -151,19 +150,19 @@
assert.isTrue(!!ary, 'header line: ' + line);
var endOffset = Number(ary[1]);
- result.println('Playing to offset: ' + endOffset);
- this.terminal.interpret(data.substring(startOffset, endOffset));
+ //console.log(`Playing to offset: ${endOffset}`);
+ terminal.interpret(data.substring(startOffset, endOffset));
var lineCount = Number(ary[2]);
for (var rowIndex = 0; rowIndex < lineCount; rowIndex++) {
headerIndex++;
- assert.equal(this.terminal.getRowText(rowIndex),
+ assert.equal(terminal.getRowText(rowIndex),
headerLines[headerIndex],
'row:' + rowIndex);
}
- assert.equal(this.terminal.getCursorRow(), Number(ary[3]), 'cursor row');
- assert.equal(this.terminal.getCursorColumn(), Number(ary[4]),
+ assert.equal(terminal.getCursorRow(), Number(ary[3]), 'cursor row');
+ assert.equal(terminal.getCursorColumn(), Number(ary[4]),
'cursor column');
startOffset = endOffset;
@@ -171,20 +170,17 @@
terminal.setWidth(null);
terminal.setHeight(null);
- result.pass();
};
-/**
- * A pre-recorded session of vttest menu option 1, 'Test of cursor movements'.
- */
-hterm.VT.CannedTests.addTest('vttest-01', function(result) {
- this.testCannedData(result, 'vttest-01');
+[
+ // A pre-recorded session of vttest menu option 1, 'Test of cursor movements'.
+ 'vttest-01',
+ 'vttest-02',
+ 'charsets',
+].forEach((name) => {
+ it(name, function() {
+ testData(this.terminal, name);
+ }).timeout(5000);
});
-hterm.VT.CannedTests.addTest('vttest-02', function(result) {
- this.testCannedData(result, 'vttest-02');
-});
-
-hterm.VT.CannedTests.addTest('charsets', function(result) {
- this.testCannedData(result, 'charsets');
});
diff --git a/hterm/js/hterm_vt_character_map_tests.js b/hterm/js/hterm_vt_character_map_tests.js
index 5065350..adea0fa 100644
--- a/hterm/js/hterm_vt_character_map_tests.js
+++ b/hterm/js/hterm_vt_character_map_tests.js
@@ -7,50 +7,44 @@
/**
* @fileoverview Unit tests for hterm.VT.CharacterMap and friends.
*/
-hterm.VT.CharacterMap.Tests =
- new lib.TestManager.Suite('hterm.VT.CharacterMap.Tests');
+
+describe('hterm_vt_character_map_tests.js', () => {
/**
* Verify null maps work sanely.
*/
-hterm.VT.CharacterMap.Tests.addTest('null-map', function(result, cx) {
+it('null-map', () => {
var map = new hterm.VT.CharacterMap('foo', null);
assert.equal(map.description, 'foo');
assert.isNull(map.GL);
-
- result.pass();
});
/**
* Verify empty maps work sanely.
*/
-hterm.VT.CharacterMap.Tests.addTest('empty-map', function(result, cx) {
+it('empty-map', () => {
var map = new hterm.VT.CharacterMap('foo bar', {});
assert.equal(map.description, 'foo bar');
assert.equal(typeof map.GL, 'function');
-
- result.pass();
});
/**
* Verify GL map works.
*/
-hterm.VT.CharacterMap.Tests.addTest('gl-translate', function(result, cx) {
+it('gl-translate', () => {
var map = new hterm.VT.CharacterMap('test', {'a': 'b'});
assert.equal(map.GL('a'), 'b');
assert.equal(map.GL('b'), 'b');
assert.equal(map.GL('c'), 'c');
-
- result.pass();
});
/**
* Verify handling of overrides.
*/
-hterm.VT.CharacterMap.Tests.addTest('overrides', function(result, cx) {
+it('overrides', () => {
var map = new hterm.VT.CharacterMap('test', {'a': 'A', 'b': 'B'});
// Verify things start off sane.
@@ -72,14 +66,12 @@
assert.equal(map.GL('b'), 'B');
assert.equal(map.GL('c'), 'c');
assert.equal(map.GL('d'), 'D');
-
- result.pass();
});
/**
* Verify handling of resets.
*/
-hterm.VT.CharacterMap.Tests.addTest('resets', function(result, cx) {
+it('resets', () => {
var map = new hterm.VT.CharacterMap('test', {'a': 'A', 'b': 'B'});
// Verify things start off sane.
@@ -101,14 +93,12 @@
assert.equal(map.GL('b'), 'B');
assert.equal(map.GL('c'), 'c');
assert.strictEqual(map.glmap_, map.glmapBase_);
-
- result.pass();
});
/**
* Verify map clones work.
*/
-hterm.VT.CharacterMap.Tests.addTest('clone', function(result, cx) {
+it('clone', () => {
var map = new hterm.VT.CharacterMap('test', {'a': 'A', 'b': 'B'});
var dup = map.clone();
@@ -122,17 +112,12 @@
assert.equal(dup.GL('b'), 'C');
assert.equal(map.GL('x'), 'x');
assert.equal(dup.GL('X'), 'X');
-
- result.pass();
});
-hterm.VT.CharacterMaps.Tests =
- new lib.TestManager.Suite('hterm.VT.CharacterMaps.Tests');
-
/**
* Verify basic character map handling.
*/
-hterm.VT.CharacterMaps.Tests.addTest('basic', function(result, cx) {
+it('basic', () => {
var maps = new hterm.VT.CharacterMaps();
// The default mapping should pass through to the default table.
@@ -143,27 +128,23 @@
maps.reset();
assert.strictEqual(maps.maps_, maps.mapsBase_);
assert.strictEqual(maps.maps_, hterm.VT.CharacterMaps.DefaultMaps);
-
- result.pass();
});
/**
* Verify getMap works.
*/
-hterm.VT.CharacterMaps.Tests.addTest('getMap', function(result, cx) {
+it('getMap', () => {
var maps = new hterm.VT.CharacterMaps();
assert.isUndefined(maps.getMap('X'));
assert.isDefined(maps.getMap('0'));
assert.strictEqual(maps.getMap('0'), hterm.VT.CharacterMaps.DefaultMaps['0']);
-
- result.pass();
});
/**
* Verify adding a new mapping doesn't mess with the default table.
*/
-hterm.VT.CharacterMaps.Tests.addTest('new-map', function(result, cx) {
+it('new-map', () => {
var maps = new hterm.VT.CharacterMaps();
var map = new hterm.VT.CharacterMap('test', {});
@@ -181,14 +162,12 @@
maps.reset();
assert.strictEqual(maps.maps_, maps.mapsBase_);
assert.strictEqual(maps.maps_, hterm.VT.CharacterMaps.DefaultMaps);
-
- result.pass();
});
/**
* Verify updating an existing mapping doesn't mess with the default table.
*/
-hterm.VT.CharacterMaps.Tests.addTest('update-map', function(result, cx) {
+it('update-map', () => {
var maps = new hterm.VT.CharacterMaps();
var map = new hterm.VT.CharacterMap('test', {});
@@ -206,14 +185,12 @@
maps.reset();
assert.strictEqual(maps.maps_, maps.mapsBase_);
assert.strictEqual(maps.maps_, hterm.VT.CharacterMaps.DefaultMaps);
-
- result.pass();
});
/**
* Verify setting overrides work.
*/
-hterm.VT.CharacterMaps.Tests.addTest('overrides', function(result, cx) {
+it('overrides', () => {
var maps = new hterm.VT.CharacterMaps();
var map;
@@ -263,6 +240,6 @@
assert.isUndefined(maps.getMap('X'));
assert.isDefined(maps.getMap('0'));
assert.strictEqual(hterm.VT.CharacterMaps.DefaultMaps['0'], maps.getMap('0'));
+});
- result.pass();
});
diff --git a/hterm/js/hterm_vt_tests.js b/hterm/js/hterm_vt_tests.js
index 6df23bb..ae6f293 100644
--- a/hterm/js/hterm_vt_tests.js
+++ b/hterm/js/hterm_vt_tests.js
@@ -12,56 +12,6 @@
* the terminal to verify that everyone did the right thing.
*/
-hterm.VT.Tests = new lib.TestManager.Suite('hterm.VT.Tests');
-
-hterm.VT.Tests.prototype.setup = function(cx) {
- this.visibleColumnCount = 15;
- this.visibleRowCount = 6;
-};
-
-/**
- * Clear out the current document and create a new hterm.Terminal object for
- * testing.
- *
- * Called before each test case in this suite.
- */
-hterm.VT.Tests.prototype.preamble = function(result, cx, done) {
- var document = cx.window.document;
-
- var div = document.createElement('div');
- div.style.position = 'absolute';
- div.style.height = '100%';
- div.style.width = '100%';
- document.body.appendChild(div);
-
- this.div = div;
-
- cx.window.terminal = this.terminal = new hterm.Terminal();
-
- this.terminal.decorate(div);
- this.terminal.setWidth(this.visibleColumnCount);
- this.terminal.setHeight(this.visibleRowCount);
- this.terminal.onTerminalReady = () => {
- this.terminal.setCursorPosition(0, 0);
- this.terminal.setCursorVisible(true);
- done();
- };
-
- MockNotification.start();
-};
-
-/**
- * Ensure that blink is off after the test so we don't have runaway timeouts.
- *
- * Called after each test case in this suite.
- */
-hterm.VT.Tests.prototype.postamble = function(result, cx) {
- document.body.removeChild(this.div);
- this.terminal.setCursorBlink(false);
-
- MockNotification.stop();
-};
-
/**
* Create a MouseEvent/WheelEvent that the VT layer expects.
*
@@ -87,11 +37,61 @@
return ret;
};
+describe('hterm_vt_tests.js', () => {
+
+before(function() {
+ this.visibleColumnCount = 15;
+ this.visibleRowCount = 6;
+});
+
+/**
+ * Clear out the current document and create a new hterm.Terminal object for
+ * testing.
+ *
+ * Called before each test case in this suite.
+ */
+beforeEach(function(done) {
+ const document = window.document;
+
+ var div = document.createElement('div');
+ div.style.position = 'absolute';
+ div.style.height = '100%';
+ div.style.width = '100%';
+ document.body.appendChild(div);
+
+ this.div = div;
+
+ this.terminal = new hterm.Terminal();
+
+ this.terminal.decorate(div);
+ this.terminal.setWidth(this.visibleColumnCount);
+ this.terminal.setHeight(this.visibleRowCount);
+ this.terminal.onTerminalReady = () => {
+ this.terminal.setCursorPosition(0, 0);
+ this.terminal.setCursorVisible(true);
+ done();
+ };
+
+ MockNotification.start();
+});
+
+/**
+ * Ensure that blink is off after the test so we don't have runaway timeouts.
+ *
+ * Called after each test case in this suite.
+ */
+afterEach(function() {
+ document.body.removeChild(this.div);
+ this.terminal.setCursorBlink(false);
+
+ MockNotification.stop();
+});
+
/**
* Basic sanity test to make sure that when we insert plain text it appears
* on the screen and scrolls into the scrollback buffer correctly.
*/
-hterm.VT.Tests.addTest('sanity', function(result, cx) {
+it('sanity', function() {
this.terminal.interpret('0\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n' +
'7\r\n8\r\n9\r\n10\r\n11\r\n12');
@@ -99,8 +99,6 @@
assert.equal(text, '0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12');
assert.equal(this.terminal.scrollbackRows_.length, 7);
-
- result.pass();
});
/**
@@ -108,7 +106,7 @@
* across writes and invalid sequences should result in replacement
* characters.
*/
-hterm.VT.Tests.addTest('utf8', function(result, cx) {
+it('utf8', function() {
// 11100010 10000000 10011001 split over two writes.
this.terminal.io.writeUTF8('\xe2\x80');
this.terminal.io.writeUTF8('\x99\r\n');
@@ -133,14 +131,12 @@
'a\ufffd\ufffd\ufffdb\ufffdc\ufffd\ufffdd\n' +
'\ufffd'.repeat(12) +
'\ndone');
-
- result.pass();
});
/**
* Verify we can write ArrayBuffers of UTF-8 data.
*/
-hterm.VT.Tests.addTest('utf8-arraybuffer', function(result, cx) {
+it('utf8-arraybuffer', function() {
// Test splitting a single code point over multiple writes.
let data = new Uint8Array([0xe2, 0x80, 0x99, 0xd, 0xa]);
for (let i = 0; i < data.length; ++i) {
@@ -166,8 +162,6 @@
'a\ufffd\ufffd\ufffdb\ufffdc\ufffd\ufffdd\n' +
'\ufffd'.repeat(12),
text);
-
- result.pass();
});
/**
@@ -181,11 +175,10 @@
* to make sure we don't significantly regress (like we have in the past) by
* producing something like "âc".
*/
-hterm.VT.Tests.addTest('utf8-combining', function(result, cx) {
+it('utf8-combining', function() {
this.terminal.interpret('abc\b\b\u{302}\n');
var text = this.terminal.getRowsText(0, 1);
assert.equal(text, 'a\u{302}bc');
- result.pass();
});
/**
@@ -193,7 +186,7 @@
*
* TODO(rginda): Test the VT52 variants too.
*/
-hterm.VT.Tests.addTest('cursor-relative', function(result, cx) {
+it('cursor-relative', function() {
this.terminal.interpret('line 1\r\nline 2\r\nline 3');
this.terminal.interpret('\x1b[A\x1b[Dtwo' +
'\x1b[3D' +
@@ -203,13 +196,12 @@
'\x1b[Cthree');
var text = this.terminal.getRowsText(0, 3);
assert.equal(text, 'line one\nline two\nline three');
- result.pass();
});
/**
* Test absolute cursor positioning.
*/
-hterm.VT.Tests.addTest('cursor-absolute', function(result, cx) {
+it('cursor-absolute', function() {
this.terminal.interpret('line 1\r\nline 2\r\nline 3');
this.terminal.interpret('\x1b[1Gline three' +
@@ -218,14 +210,12 @@
var text = this.terminal.getRowsText(0, 3);
assert.equal(text, 'line one\nline two\nline three');
-
- result.pass();
});
/**
* Test line positioning.
*/
-hterm.VT.Tests.addTest('line-position', function(result, cx) {
+it('line-position', function() {
this.terminal.interpret('line 1\r\nline 2\r\nline 3');
this.terminal.interpret('\x1b[Fline two' +
@@ -234,14 +224,13 @@
var text = this.terminal.getRowsText(0, 3);
assert.equal(text, 'line one\nline two\nline three');
- result.pass();
});
/**
* Test that a partial sequence is buffered until the entire sequence is
* received.
*/
-hterm.VT.Tests.addTest('partial-sequence', function(result, cx) {
+it('partial-sequence', function() {
this.terminal.interpret('line 1\r\nline 2\r\nline three');
this.terminal.interpret('\x1b');
@@ -254,26 +243,24 @@
var text = this.terminal.getRowsText(0, 3);
assert.equal(text, 'line one\nline two\nline three');
- result.pass();
});
/**
* Test that two ESC characters in a row are handled properly.
*/
-hterm.VT.Tests.addTest('double-sequence', function(result, cx) {
+it('double-sequence', function() {
this.terminal.interpret('line one\r\nline two\r\nline 3');
this.terminal.interpret('\x1b[\x1b[Dthree');
var text = this.terminal.getRowsText(0, 3);
assert.equal(text, 'line one\nline two\nline three');
- result.pass();
});
/**
* Test that 8-bit control characters are properly ignored.
*/
-hterm.VT.Tests.addTest('8-bit-control', function(result, cx) {
+it('8-bit-control', function() {
var title = null;
this.terminal.setWindowTitle = function(t) {
// Set a default title so we can catch the potential for this function
@@ -308,14 +295,12 @@
this.terminal.interpret('\u{9d}0;test title\x07!!');
assert.equal(title, 'test title');
assert.equal(this.terminal.getRowsText(0, 1), '!!');
-
- result.pass();
});
/**
* If we see embedded escape sequences, we should reject them.
*/
-hterm.VT.Tests.addTest('embedded-escape-sequence', function(result, cx) {
+it('embedded-escape-sequence', function() {
var title = null;
this.terminal.setWindowTitle = function(t) {
// Set a default title so we can catch the potential for this function
@@ -328,12 +313,12 @@
['\a', '\x1b\\'].forEach((seq) => {
// We get all the data at once with a terminated sequence.
- terminal.reset();
+ this.terminal.reset();
this.terminal.interpret('\x1b]0;asdf\x1b x ' + seq);
assert.isNull(title);
// We get the data in pieces w/a terminated sequence.
- terminal.reset();
+ this.terminal.reset();
this.terminal.interpret('\x1b]0;asdf');
this.terminal.interpret('\x1b');
this.terminal.interpret(' x ' + seq);
@@ -341,19 +326,17 @@
});
// We get the data in pieces but no terminating sequence.
- terminal.reset();
+ this.terminal.reset();
this.terminal.interpret('\x1b]0;asdf');
this.terminal.interpret('\x1b');
this.terminal.interpret(' ');
assert.isNull(title);
-
- result.pass();
});
/**
* Verify that split ST sequences are buffered/handled correctly.
*/
-hterm.VT.Tests.addTest('split-ST-sequence', function(result, cx) {
+it('split-ST-sequence', function() {
var title = null;
this.terminal.setWindowTitle = function(t) {
// Set a default title so we can catch the potential for this function
@@ -368,16 +351,14 @@
// We get the first half of the ST one byte at a time.
title = null;
- terminal.reset();
+ this.terminal.reset();
this.terminal.interpret('\x1b]0;asdf');
this.terminal.interpret('\x1b');
this.terminal.interpret('\\');
assert.equal(title, 'asdf');
-
- result.pass();
});
-hterm.VT.Tests.addTest('dec-screen-test', function(result, cx) {
+it('dec-screen-test', function() {
this.terminal.interpret('\x1b#8');
var text = this.terminal.getRowsText(0, 6);
@@ -388,11 +369,9 @@
'EEEEEEEEEEEEEEE\n' +
'EEEEEEEEEEEEEEE\n' +
'EEEEEEEEEEEEEEE');
- result.pass();
-
});
-hterm.VT.Tests.addTest('newlines-1', function(result, cx) {
+it('newlines-1', function() {
// Should be off by default.
assert.isFalse(this.terminal.options_.autoCarriageReturn);
@@ -403,11 +382,9 @@
'vtabine\n' +
' ff\n' +
' bye');
-
- result.pass();
});
-hterm.VT.Tests.addTest('newlines-2', function(result, cx) {
+it('newlines-2', function() {
this.terminal.interpret('\x1b[20h');
assert.isTrue(this.terminal.options_.autoCarriageReturn);
@@ -417,14 +394,12 @@
'vtabine\n' +
'ff\n' +
'bye');
-
- result.pass();
});
/**
* Test the default tab stops.
*/
-hterm.VT.Tests.addTest('tabs', function(result, cx) {
+it('tabs', function() {
this.terminal.interpret('123456789012345\r\n');
this.terminal.interpret('1\t2\ta\r\n');
this.terminal.interpret('1\t2\tb\r\n');
@@ -439,14 +414,12 @@
'1 2 c\n' +
'1 2 d\n' +
'1 2 e');
-
- result.pass();
});
/**
* Test terminal reset.
*/
-hterm.VT.Tests.addTest('reset', function(result, cx) {
+it('reset', function() {
this.terminal.interpret(
// Switch to alternate screen and set some attributes.
'\x1b[?47h\x1b[1;33;44m' +
@@ -499,14 +472,12 @@
assert.isNull(this.terminal.vtScrollBottom_);
assert.equal(this.terminal.screen_.cursorPosition.row, 0);
assert.equal(this.terminal.screen_.cursorPosition.column, 0);
-
- result.pass();
});
/**
* Test the erase left command.
*/
-hterm.VT.Tests.addTest('erase-left', function(result, cx) {
+it('erase-left', function() {
this.terminal.interpret('line one\r\noooooooo\r\nline three');
this.terminal.interpret('\x1b[5D\x1b[A' +
'\x1b[1Ktw');
@@ -516,13 +487,12 @@
'line one\n' +
' two\n' +
'line three');
- result.pass();
});
/**
* Test the erase left command with widechar string.
*/
-hterm.VT.Tests.addTest('erase-left-widechar', function(result, cx) {
+it('erase-left-widechar', function() {
this.terminal.interpret('第一行\r\n第二行\r\n第三行');
this.terminal.interpret('\x1b[5D' +
'\x1b[A' +
@@ -533,13 +503,12 @@
' OO \u884c\n' +
'\u7b2c\u4e09\u884c',
text);
- result.pass();
});
/**
* Test the erase right command.
*/
-hterm.VT.Tests.addTest('erase-right', function(result, cx) {
+it('erase-right', function() {
this.terminal.interpret('line one\r\nline XXXX\r\nline three');
this.terminal.interpret('\x1b[5D\x1b[A' +
'\x1b[0Ktwo');
@@ -549,13 +518,12 @@
'line one\n' +
'line two\n' +
'line three');
- result.pass();
});
/**
* Test the erase right command with widechar string.
*/
-hterm.VT.Tests.addTest('erase-right-widechar', function(result, cx) {
+it('erase-right-widechar', function() {
this.terminal.interpret('第一行\r\n第二行\r\n第三行');
this.terminal.interpret('\x1b[5D\x1b[A' +
'\x1b[0KOO');
@@ -565,13 +533,12 @@
' OO\n' +
'\u7b2c\u4e09\u884c',
text);
- result.pass();
});
/**
* Test the erase line command.
*/
-hterm.VT.Tests.addTest('erase-line', function(result, cx) {
+it('erase-line', function() {
this.terminal.interpret('line one\r\nline twoo\r\nline three');
this.terminal.interpret('\x1b[5D\x1b[A' +
'\x1b[2Ktwo');
@@ -581,13 +548,12 @@
'line one\n' +
' two\n' +
'line three');
- result.pass();
});
/**
* Test the erase above command.
*/
-hterm.VT.Tests.addTest('erase-above', function(result, cx) {
+it('erase-above', function() {
this.terminal.interpret('line one\r\noooooooo\r\nline three');
this.terminal.interpret('\x1b[5D\x1b[A' +
'\x1b[1Jtw');
@@ -597,13 +563,12 @@
'\n' +
' two\n' +
'line three');
- result.pass();
});
/**
* Test the erase all command.
*/
-hterm.VT.Tests.addTest('erase-all', function(result, cx) {
+it('erase-all', function() {
this.terminal.interpret('line one\r\nline XXXX\r\nline three');
this.terminal.interpret('\x1b[5D\x1b[A' +
'\x1b[2Jtwo');
@@ -612,13 +577,12 @@
assert.equal(text,
'\n' +
' two\n');
- result.pass();
});
/**
* Test the erase below command.
*/
-hterm.VT.Tests.addTest('erase-below', function(result, cx) {
+it('erase-below', function() {
this.terminal.interpret('line one\r\nline XXXX\r\nline three');
this.terminal.interpret('\x1b[5D\x1b[A' +
'\x1b[0Jtwo');
@@ -627,13 +591,12 @@
assert.equal(text,
'line one\n' +
'line two\n');
- result.pass();
});
/**
* Test the erase character command.
*/
-hterm.VT.Tests.addTest('erase-char', function(result, cx) {
+it('erase-char', function() {
this.terminal.interpret('line one\r\nline XXXX\r\nline three');
this.terminal.interpret('\x1b[5D\x1b[A' +
'\x1b[4Xtwo');
@@ -652,13 +615,12 @@
'line one\n' +
'line wo\n' +
'line three');
- result.pass();
});
/**
* Test the insert line command.
*/
-hterm.VT.Tests.addTest('insert-line', function(result, cx) {
+it('insert-line', function() {
this.terminal.interpret('line two\r\nline three');
this.terminal.interpret('\x1b[5D\x1b[2A\x1b[L' +
'line one');
@@ -668,13 +630,12 @@
'line one\n' +
'line two\n' +
'line three');
- result.pass();
});
/**
* Test the insert line command with an argument.
*/
-hterm.VT.Tests.addTest('insert-lines', function(result, cx) {
+it('insert-lines', function() {
this.terminal.interpret('line three\r\n\r\n');
this.terminal.interpret('\x1b[5D\x1b[2A\x1b[2L' +
'line one\r\nline two');
@@ -684,13 +645,12 @@
'line one\n' +
'line two\n' +
'line three');
- result.pass();
});
/**
* Test that the insert line command handles overflow properly.
*/
-hterm.VT.Tests.addTest('insert-toomany-lines', function(result, cx) {
+it('insert-toomany-lines', function() {
this.terminal.interpret('XXXXX');
this.terminal.interpret('\x1b[6L' +
'line one\r\nline two\r\nline three');
@@ -701,13 +661,12 @@
'line two\n' +
'line three\n' +
'\n');
- result.pass();
});
/**
* Test the delete line command.
*/
-hterm.VT.Tests.addTest('delete-line', function(result, cx) {
+it('delete-line', function() {
this.terminal.interpret('line one\r\nline two\r\n' +
'XXXXXXXX\r\n' +
'line XXXXX');
@@ -718,13 +677,12 @@
'line one\n' +
'line two\n' +
'line three');
- result.pass();
});
/**
* Test the delete line command with an argument.
*/
-hterm.VT.Tests.addTest('delete-lines', function(result, cx) {
+it('delete-lines', function() {
this.terminal.interpret('line one\r\nline two\r\n' +
'XXXXXXXX\r\nXXXXXXXX\r\n' +
'line XXXXX');
@@ -735,13 +693,12 @@
'line one\n' +
'line two\n' +
'line three');
- result.pass();
});
/**
* Test the insert space command.
*/
-hterm.VT.Tests.addTest('insert-space', function(result, cx) {
+it('insert-space', function() {
this.terminal.interpret('line one\r\nlinetwo\r\nline three');
this.terminal.interpret('\x1b[6D\x1b[A\x1b[@');
@@ -750,13 +707,12 @@
'line one\n' +
'line two\n' +
'line three');
- result.pass();
});
/**
* Test the insert space command with an argument.
*/
-hterm.VT.Tests.addTest('insert-spaces', function(result, cx) {
+it('insert-spaces', function() {
this.terminal.interpret('line one\r\nlinetwo\r\nline three');
this.terminal.interpret('\x1b[6D\x1b[A\x1b[3@');
@@ -765,13 +721,12 @@
'line one\n' +
'line two\n' +
'line three');
- result.pass();
});
/**
* Test the delete characters command.
*/
-hterm.VT.Tests.addTest('delete-chars', function(result, cx) {
+it('delete-chars', function() {
this.terminal.interpret('line one\r\nline XXXX\r\nline three');
this.terminal.interpret('\x1b[5D\x1b[A\x1b[4Ptwo');
@@ -780,13 +735,12 @@
'line one\n' +
'line two\n' +
'line three');
- result.pass();
});
/**
* Test that the delete characters command handles overflow properly.
*/
-hterm.VT.Tests.addTest('delete-toomany', function(result, cx) {
+it('delete-toomany', function() {
this.terminal.interpret('line one\r\nline XXXX\r\nline three');
this.terminal.interpret('\x1b[5D\x1b[A\x1b[20Ptwo');
@@ -795,13 +749,12 @@
'line one\n' +
'line two\n' +
'line three');
- result.pass();
});
/**
* Test the scroll up command.
*/
-hterm.VT.Tests.addTest('scroll-up', function(result, cx) {
+it('scroll-up', function() {
this.terminal.interpret('\r\n\r\nline one\r\nline two\r\nline XXXXX');
this.terminal.interpret('\x1b[5D\x1b[2A\x1b[2Sthree');
@@ -810,13 +763,12 @@
'line one\n' +
'line two\n' +
'line three');
- result.pass();
});
/**
* Test the scroll down command.
*/
-hterm.VT.Tests.addTest('scroll-down', function(result, cx) {
+it('scroll-down', function() {
this.terminal.interpret('line one\r\nline two\r\nline XXXXX\r\n');
this.terminal.interpret(' \x1b[Tthree');
@@ -827,13 +779,12 @@
'line two\n' +
'line three\n' +
' ');
- result.pass();
});
/**
* Test the absolute line positioning command.
*/
-hterm.VT.Tests.addTest('line-position-absolute', function(result, cx) {
+it('line-position-absolute', function() {
this.terminal.interpret('line XXX\r\nline YYY\r\nline ZZZZZ\r\n');
this.terminal.interpret(' \x1b[3dthree\x1b[5D');
this.terminal.interpret('\x1b[2dtwo\x1b[3D');
@@ -844,40 +795,38 @@
'line one\n' +
'line two\n' +
'line three');
- result.pass();
});
/**
* Test the device attributes command.
*/
-hterm.VT.Tests.addTest('device-attributes', function(result, cx) {
+it('device-attributes', function() {
var resultString;
this.terminal.io.sendString = (str) => resultString = str;
this.terminal.interpret('\x1b[c');
assert.equal(resultString, '\x1b[?1;2c');
- result.pass();
});
/**
* TODO(rginda): Test the clear tabstops on this line command.
*/
-hterm.VT.Tests.disableTest('clear-line-tabstops', function(result, cx) {
+it.skip('clear-line-tabstops', function() {
'[0g';
});
/**
* TODO(rginda): Test the clear all tabstops command.
*/
-hterm.VT.Tests.disableTest('clear-all-tabstops', function(result, cx) {
+it.skip('clear-all-tabstops', function() {
'[3g';
});
/**
* TODO(rginda): Test text attributes.
*/
-hterm.VT.Tests.addTest('color-change', function(result, cx) {
+it('color-change', function() {
this.terminal.interpret('[mplain....... [0;36mHi\r\n' +
'[mitalic...... [3;36mHi\r\n' +
'[mbright...... [0;96mHi\r\n' +
@@ -906,11 +855,9 @@
row.childNodes[1].style.fontStyle, (i == 1 ? 'italic' : ''),
'i: ' + i);
}
-
- result.pass();
});
-hterm.VT.Tests.addTest('color-change-wc', function(result, cx) {
+it('color-change-wc', function() {
this.terminal.io.print('[mplain....... [0;36mä¸\r\n' +
'[mitalic...... [3;36mä¸\r\n' +
'[mbright...... [0;96mä¸\r\n' +
@@ -939,11 +886,9 @@
row.childNodes[1].style.fontStyle, (i == 1 ? 'italic' : ''),
'i: ' + i);
}
-
- result.pass();
});
-hterm.VT.Tests.addTest('bold-as-bright', function(result, cx) {
+it('bold-as-bright', function() {
var attrs = this.terminal.primaryScreen_.textAttributes;
var alt_attrs = this.terminal.alternateScreen_.textAttributes;
attrs.enableBoldAsBright = true;
@@ -985,11 +930,9 @@
var row_bright_bold = this.terminal.getRowNode(4);
assert.equal(row_bright_bold.childNodes[1].style.color, fg_bright,
'bright bold color');
-
- result.pass();
});
-hterm.VT.Tests.addTest('disable-bold-as-bright', function(result, cx) {
+it('disable-bold-as-bright', function() {
var attrs = this.terminal.primaryScreen_.textAttributes;
var alt_attrs = this.terminal.alternateScreen_.textAttributes;
attrs.enableBoldAsBright = false;
@@ -1031,16 +974,14 @@
var row_bright_bold = this.terminal.getRowNode(4);
assert.equal(row_bright_bold.childNodes[1].style.color, fg_bright,
'bright bold color');
-
- result.pass();
});
/**
* Test the status report command.
*/
-hterm.VT.Tests.addTest('status-report', function(result, cx) {
+it('status-report', function() {
var resultString;
- terminal.io.sendString = (str) => resultString = str;
+ this.terminal.io.sendString = (str) => resultString = str;
this.terminal.interpret('\x1b[5n');
assert.equal(resultString, '\x1b0n');
@@ -1057,8 +998,6 @@
'line one\n' +
'line two\n' +
'line three');
-
- result.pass();
});
/**
@@ -1066,7 +1005,7 @@
*
* Most of these should have more in-depth testing below.
*/
-hterm.VT.Tests.addTest('mode-bits', function(result, cx) {
+it('mode-bits', function() {
this.terminal.interpret('\x1b[?1h');
assert.isTrue(this.terminal.keyboard.applicationCursor);
@@ -1180,14 +1119,12 @@
this.terminal.interpret('\x1b[?1049l');
assert(this.terminal.screen_ === this.terminal.primaryScreen_);
-
- result.pass();
});
/**
* Check parseInt behavior.
*/
-hterm.VT.Tests.addTest('parsestate-parseint', function(result, cx) {
+it('parsestate-parseint', function() {
const parserState = new hterm.VT.ParseState();
// Check default arg handling.
@@ -1204,14 +1141,12 @@
assert.equal(5, parserState.parseInt('5'));
assert.equal(5, parserState.parseInt('5', 0));
assert.equal(5, parserState.parseInt('5', 1));
-
- result.pass();
});
/**
* Check iarg handling.
*/
-hterm.VT.Tests.addTest('parsestate-iarg', function(result, cx) {
+it('parsestate-iarg', function() {
const parserState = new hterm.VT.ParseState();
// Check unset args.
@@ -1226,14 +1161,12 @@
assert.equal(1, parserState.iarg(0, 1));
assert.equal(5, parserState.iarg(1));
assert.equal(5, parserState.iarg(1, 1));
-
- result.pass();
});
/**
* Check handling of subargs.
*/
-hterm.VT.Tests.addTest('parsestate-subargs', function(result, cx) {
+it('parsestate-subargs', function() {
const parserState = new hterm.VT.ParseState();
// Check initial/null state.
@@ -1244,14 +1177,12 @@
parserState.argSetSubargs(1);
assert.isTrue(!parserState.argHasSubargs(0));
assert.isTrue(parserState.argHasSubargs(1));
-
- result.pass();
});
/**
* Check handling of extended ISO 8613-6 colors.
*/
-hterm.VT.Tests.addTest('sgr-extended-colors-parser', function(result, cx) {
+it('sgr-extended-colors-parser', function() {
const parserState = new hterm.VT.ParseState();
const ta = this.terminal.getTextAttributes();
@@ -1305,8 +1236,6 @@
assert.equal(expSkipCount, ret.skipCount, input);
assert.equal(expColor, ret.color, input);
});
-
- result.pass();
});
/**
@@ -1314,7 +1243,7 @@
*
* This also indirectly checks chaining SGR behavior.
*/
-hterm.VT.Tests.addTest('true-color-colon', function(result, cx) {
+it('true-color-colon', function() {
let text;
let style;
const ta = this.terminal.getTextAttributes();
@@ -1375,14 +1304,12 @@
assert.equal('', style.backgroundColor);
text = this.terminal.getRowText(0);
assert.equal('HI5', text);
-
- result.pass();
});
/**
* Test setting of 256 color mode in colon delimited formats.
*/
-hterm.VT.Tests.addTest('256-color-colon', function(result, cx) {
+it('256-color-colon', function() {
let text;
let style;
const ta = this.terminal.getTextAttributes();
@@ -1407,14 +1334,12 @@
assert.equal('rgb(95, 95, 135)', style.backgroundColor);
text = this.terminal.getRowText(0);
assert.equal('HI2', text);
-
- result.pass();
});
/**
* Test setting of true color mode on text
*/
-hterm.VT.Tests.addTest('true-color-mode', function(result, cx) {
+it('true-color-mode', function() {
function getEscape(row, fg) {
return '\x1b[' + (fg == true ? 38 : 48) + ';2;' + row[1] + ';' +
row[2] + ';' + row[3] + 'm';
@@ -1451,14 +1376,12 @@
assert.equal(style.backgroundColor, bg);
}
}
-
- result.pass();
});
/**
* Check chained SGR sequences.
*/
-hterm.VT.Tests.addTest('chained-sgr', function(result, cx) {
+it('chained-sgr', function() {
let text;
let style;
const ta = this.terminal.getTextAttributes();
@@ -1522,14 +1445,12 @@
assert.equal('rgb(0, 95, 0)', style.backgroundColor);
text = this.terminal.getRowText(0);
assert.equal('HI2', text);
-
- result.pass();
});
/**
* Check various underline modes.
*/
-hterm.VT.Tests.addTest('underline-sgr', function(result, cx) {
+it('underline-sgr', function() {
const ta = this.terminal.getTextAttributes();
// Default mode 4: plain underline.
@@ -1573,20 +1494,18 @@
this.terminal.interpret('\x1b[0m');
assert.isFalse(ta.underline);
assert.equal(ta.SRC_DEFAULT, ta.underlineSource);
-
- result.pass();
});
/**
* TODO(rginda): Test origin mode.
*/
-hterm.VT.Tests.disableTest('origin-mode', function(result, cx) {
+it.skip('origin-mode', function() {
});
/**
* Test insert/overwrite mode.
*/
-hterm.VT.Tests.addTest('insert-mode', function(result, cx) {
+it('insert-mode', function() {
// Should be off by default.
assert.isFalse(this.terminal.options_.insertMode);
@@ -1604,14 +1523,12 @@
'line one\n' +
'line two\n' +
'line three');
-
- result.pass();
});
/**
* Test wraparound mode.
*/
-hterm.VT.Tests.addTest('wraparound-mode-on', function(result, cx) {
+it('wraparound-mode-on', function() {
// Should be on by default.
assert.isTrue(this.terminal.options_.wraparound);
@@ -1633,11 +1550,9 @@
assert.equal(this.terminal.getCursorRow(), 5);
assert.equal(this.terminal.getCursorColumn(), 14);
-
- result.pass();
});
-hterm.VT.Tests.addTest('wraparound-mode-off', function(result, cx) {
+it('wraparound-mode-off', function() {
this.terminal.interpret('\x1b[?7l');
assert.isFalse(this.terminal.options_.wraparound);
@@ -1658,14 +1573,12 @@
assert.equal(this.terminal.getCursorRow(), 0);
assert.equal(this.terminal.getCursorColumn(), 14);
-
- result.pass();
});
/**
* Test the interactions between insert and wraparound modes.
*/
-hterm.VT.Tests.addTest('insert-wrap', function(result, cx) {
+it('insert-wrap', function() {
// Should be on by default.
assert.isTrue(this.terminal.options_.wraparound);
@@ -1684,14 +1597,12 @@
assert.equal(this.terminal.getRowText(3), ' A');
assert.equal(this.terminal.getRowText(4), 'XXAAA');
assert.equal(this.terminal.getRowText(5), 'XX A');
-
- result.pass();
});
/**
* Test a line that is long enough to need to be wrapped more than once.
*/
-hterm.VT.Tests.addTest('long-wrap', function(result, cx) {
+it('long-wrap', function() {
var str = '';
for (var i = 0; i < this.visibleColumnCount * 3; i++)
str += 'X';
@@ -1701,14 +1612,12 @@
assert.equal(this.terminal.getRowText(0), 'XXXXXXXXXXXXXXX');
assert.equal(this.terminal.getRowText(1), 'XXXXXXXXXXXXXXX');
assert.equal(this.terminal.getRowText(2), 'XXXXXXXXXXXXXXX');
-
- result.pass();
});
/**
* Test reverse wraparound.
*/
-hterm.VT.Tests.addTest('reverse-wrap', function(result, cx) {
+it('reverse-wrap', function() {
// A line ending with a hard CRLF.
var str = 'AAAA\r\n';
@@ -1753,15 +1662,13 @@
assert.equal(this.terminal.getRowText(3), '');
assert.equal(this.terminal.getRowText(4), '');
assert.equal(this.terminal.getRowText(5), ' X');
-
- result.pass();
});
/**
* Test interactions between the cursor overflow bit and various
* escape sequences.
*/
-hterm.VT.Tests.addTest('cursor-overflow', function(result, cx) {
+it('cursor-overflow', function() {
// Should be on by default.
assert.isTrue(this.terminal.options_.wraparound);
@@ -1803,11 +1710,9 @@
assert.equal(this.terminal.getCursorRow(), 5);
assert.equal(this.terminal.getCursorColumn(), 14);
-
- result.pass();
});
-hterm.VT.Tests.addTest('alternate-screen', function(result, cx) {
+it('alternate-screen', function() {
this.terminal.interpret('1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10');
this.terminal.interpret('\x1b[3;3f'); // Leave the cursor at (3,3)
var text = this.terminal.getRowsText(0, 10);
@@ -1839,14 +1744,12 @@
this.terminal.interpret('XX');
text = this.terminal.getRowsText(0, 10);
assert.equal(text, '1\n2\n3\n4\n\n\n XX\n\n\n');
-
- result.pass();
});
/**
* Test basic hyperlinks.
*/
-hterm.VT.Tests.addTest('OSC-8', function(result, cx) {
+it('OSC-8', function() {
const tattrs = this.terminal.getTextAttributes();
// Start with links off.
@@ -1873,14 +1776,12 @@
assert.equal('foo', span.uriId);
assert.equal('click me', span.textContent);
assert.equal('uri-node', span.className);
-
- result.pass();
});
/**
* Test hyperlinks with blank ids.
*/
-hterm.VT.Tests.addTest('OSC-8-blank-id', function(result, cx) {
+it('OSC-8-blank-id', function() {
const tattrs = this.terminal.getTextAttributes();
// Create a link with a blank id.
@@ -1895,14 +1796,12 @@
assert.equal('', span.uriId);
assert.equal('click', span.textContent);
assert.equal('uri-node', span.className);
-
- result.pass();
});
/**
* Test changing hyperlinks midstream.
*/
-hterm.VT.Tests.addTest('OSC-8-switch-uri', function(result, cx) {
+it('OSC-8-switch-uri', function() {
const tattrs = this.terminal.getTextAttributes();
// Create a link then change it.
@@ -1923,14 +1822,12 @@
assert.equal('', span.uriId);
assert.equal('bat', span.textContent);
assert.equal('uri-node', span.className);
-
- result.pass();
});
/**
* Test iTerm2 growl notifications.
*/
-hterm.VT.Tests.addTest('OSC-9', function(result, cx) {
+it('OSC-9', function() {
assert.equal(0, Notification.count);
// We don't test the title as it's generated, and the iTerm2 API doesn't
@@ -1945,14 +1842,12 @@
this.terminal.interpret('\x1b]9;this is a title\x07');
assert.equal(2, Notification.count);
assert.equal('this is a title', Notification.call.body);
-
- result.pass();
});
/**
* Verify setting text foreground color.
*/
-hterm.VT.Tests.addTest('OSC-10', function(result, cx) {
+it('OSC-10', function() {
// Make sure other colors aren't changed by accident.
const backColor = this.terminal.getBackgroundColor();
const cursorColor = this.terminal.getCursorColor();
@@ -1966,14 +1861,12 @@
// Make sure other colors aren't changed by accident.
assert.equal(backColor, this.terminal.getBackgroundColor());
assert.equal(cursorColor, this.terminal.getCursorColor());
-
- result.pass();
});
/**
* Verify setting text background color.
*/
-hterm.VT.Tests.addTest('OSC-11', function(result, cx) {
+it('OSC-11', function() {
// Make sure other colors aren't changed by accident.
const foreColor = this.terminal.getForegroundColor();
const cursorColor = this.terminal.getCursorColor();
@@ -1987,14 +1880,12 @@
// Make sure other colors aren't changed by accident.
assert.equal(foreColor, this.terminal.getForegroundColor());
assert.equal(cursorColor, this.terminal.getCursorColor());
-
- result.pass();
});
/**
* Verify setting text cursor color (not the mouse cursor).
*/
-hterm.VT.Tests.addTest('OSC-12', function(result, cx) {
+it('OSC-12', function() {
// Make sure other colors aren't changed by accident.
const foreColor = this.terminal.getForegroundColor();
const backColor = this.terminal.getBackgroundColor();
@@ -2008,14 +1899,12 @@
// Make sure other colors aren't changed by accident.
assert.equal(foreColor, this.terminal.getForegroundColor());
assert.equal(backColor, this.terminal.getBackgroundColor());
-
- result.pass();
});
/**
* Verify chaining color change requests.
*/
-hterm.VT.Tests.addTest('OSC-10-11-12', function(result, cx) {
+it('OSC-10-11-12', function() {
// Set 10-11-12 at once.
this.terminal.interpret('\x1b]10;red;green;blue\x07');
assert.equal('rgb(255, 0, 0)', this.terminal.getForegroundColor());
@@ -2027,39 +1916,36 @@
assert.equal('rgb(255, 0, 0)', this.terminal.getForegroundColor());
assert.equal('rgb(255, 255, 255)', this.terminal.getBackgroundColor());
assert.equal('rgb(0, 0, 0)', this.terminal.getCursorColor());
-
- result.pass();
});
/**
* Test that we can use OSC 52 to copy to the system clipboard.
*/
-hterm.VT.Tests.addTest('OSC-52', function(result, cx) {
+it('OSC-52', function(done) {
// Mock this out since we can't document.execCommand from the
// test harness.
var old_cCSTC = hterm.copySelectionToClipboard;
hterm.copySelectionToClipboard = function(document, str) {
hterm.copySelectionToClipboard = old_cCSTC;
assert.equal(str, 'copypasta!');
- result.pass();
+ done();
};
this.terminal.interpret('\x1b]52;c;Y29weXBhc3RhIQ==\x07');
- result.requestTime(200);
});
/**
* Test that OSC 52 works when large strings are split across multiple interpret
* calls.
*/
-hterm.VT.Tests.addTest('OSC-52-big', function(result, cx) {
+it('OSC-52-big', function(done) {
// Mock this out since we can't document.execCommand from the
// test harness.
var old_cCSTC = hterm.copySelectionToClipboard;
hterm.copySelectionToClipboard = function(document, str) {
hterm.copySelectionToClipboard = old_cCSTC;
assert.equal(str, expect);
- result.pass();
+ done();
};
var expect = '';
@@ -2076,10 +1962,9 @@
this.terminal.interpret(encode);
this.terminal.interpret(encode);
this.terminal.interpret('\x07');
- result.requestTime(200);
});
-hterm.VT.Tests.addTest('OSC-4', function(result, cx) {
+it('OSC-4', function() {
var resultString;
this.terminal.io.sendString = (str) => resultString = str;
@@ -2098,13 +1983,12 @@
'rgb:bebe/bebe/bebe\x07');
assert.equal(resultString, '\x1b]4;1;rgb:0101/0101/0101;' +
'2;rgb:bebe/bebe/bebe\x07');
- result.pass();
});
/**
* Test the cursor shape changes using OSC 50.
*/
-hterm.VT.Tests.addTest('OSC-50, cursor shapes', function(result, cx) {
+it('OSC-50, cursor shapes', function() {
assert.strictEqual(this.terminal.getCursorShape(),
hterm.Terminal.cursorShape.BLOCK);
@@ -2128,14 +2012,12 @@
this.terminal.syncCursorPosition_();
assert.strictEqual(this.terminal.getCursorShape(),
hterm.Terminal.cursorShape.BLOCK);
-
- result.pass();
});
/**
* Verify resetting the color palette.
*/
-hterm.VT.Tests.addTest('OSC-104', function(result, cx) {
+it('OSC-104', function() {
let resultString;
this.terminal.io.sendString = (str) => resultString = str;
@@ -2153,14 +2035,12 @@
// Verify it changed.
this.terminal.interpret('\x1b]4;1;?\x07');
assert.equal(resultString, '\x1b]4;1;rgb:cccc/0000/0000\x07');
-
- result.pass();
});
/**
* Verify resetting text foreground color.
*/
-hterm.VT.Tests.addTest('OSC-110', function(result, cx) {
+it('OSC-110', function() {
// Make sure other colors aren't changed by accident.
const backColor = this.terminal.getBackgroundColor();
const cursorColor = this.terminal.getCursorColor();
@@ -2174,14 +2054,12 @@
// Make sure other colors aren't changed by accident.
assert.equal(backColor, this.terminal.getBackgroundColor());
assert.equal(cursorColor, this.terminal.getCursorColor());
-
- result.pass();
});
/**
* Verify resetting text background color.
*/
-hterm.VT.Tests.addTest('OSC-111', function(result, cx) {
+it('OSC-111', function() {
// Make sure other colors aren't changed by accident.
const foreColor = this.terminal.getForegroundColor();
const cursorColor = this.terminal.getCursorColor();
@@ -2195,14 +2073,12 @@
// Make sure other colors aren't changed by accident.
assert.equal(foreColor, this.terminal.getForegroundColor());
assert.equal(cursorColor, this.terminal.getCursorColor());
-
- result.pass();
});
/**
* Verify resetting text cursor color (not the mouse cursor).
*/
-hterm.VT.Tests.addTest('OSC-112', function(result, cx) {
+it('OSC-112', function() {
// Make sure other colors aren't changed by accident.
const foreColor = this.terminal.getForegroundColor();
const backColor = this.terminal.getBackgroundColor();
@@ -2216,14 +2092,12 @@
// Make sure other colors aren't changed by accident.
assert.equal(foreColor, this.terminal.getForegroundColor());
assert.equal(backColor, this.terminal.getBackgroundColor());
-
- result.pass();
});
/**
* Test URxvt notify module.
*/
-hterm.VT.Tests.addTest('OSC-777-notify', function(result, cx) {
+it('OSC-777-notify', function() {
assert.equal(0, Notification.count);
// An empty notification. We don't test the title as it's generated.
@@ -2255,26 +2129,22 @@
assert.equal(5, Notification.count);
assert.include(Notification.call.title, 'my title');
assert.include(Notification.call.body, 'my body;and a semi');
-
- result.pass();
});
/**
* Test iTerm2 1337 non-file transfers.
*/
-hterm.VT.Tests.addTest('OSC-1337-ignore', function(result, cx) {
+it('OSC-1337-ignore', function() {
this.terminal.displayImage =
() => assert.fail('Unknown should not trigger file display');
this.terminal.interpret('\x1b]1337;CursorShape=1\x07');
-
- result.pass();
});
/**
* Test iTerm2 1337 file transfer defaults.
*/
-hterm.VT.Tests.addTest('OSC-1337-file-defaults', function(result, cx) {
+it('OSC-1337-file-defaults', function(done) {
this.terminal.displayImage = (options) => {
assert.equal('', options.name);
assert.equal(0, options.size);
@@ -2285,7 +2155,7 @@
assert.equal('left', options.align);
assert.isUndefined(options.uri);
assert.deepStrictEqual(new Uint8Array([10]).buffer, options.buffer);
- result.pass();
+ done();
};
this.terminal.interpret('\x1b]1337;File=:Cg==\x07');
@@ -2294,12 +2164,12 @@
/**
* Test iTerm2 1337 invalid values.
*/
-hterm.VT.Tests.addTest('OSC-1337-file-invalid', function(result, cx) {
+it('OSC-1337-file-invalid', function(done) {
this.terminal.displayImage = (options) => {
assert.equal('', options.name);
assert.equal(1, options.size);
assert.isUndefined(options.unk);
- result.pass();
+ done();
};
this.terminal.interpret(
@@ -2315,7 +2185,7 @@
/**
* Test iTerm2 1337 valid options.
*/
-hterm.VT.Tests.addTest('OSC-1337-file-valid', function(result, cx) {
+it('OSC-1337-file-valid', function(done) {
// Check "false" values.
this.terminal.displayImage = (options) => {
assert.isFalse(options.preserveAspectRatio);
@@ -2340,7 +2210,7 @@
assert.equal('50%', options.height);
assert.equal('center', options.align);
- result.pass();
+ done();
};
this.terminal.interpret(
'\x1b]1337;File=' +
@@ -2355,7 +2225,7 @@
/**
* Test handling of extra data after an iTerm2 1337 file sequence.
*/
-hterm.VT.Tests.addTest('OSC-1337-file-queue', function(result, cx) {
+it('OSC-1337-file-queue', function(done) {
let text;
// For non-inline files, things will be processed right away.
@@ -2372,21 +2242,19 @@
io.pop();
text = this.getRowsText(0, 1);
assert.equal('OK', text);
- result.pass();
+ done();
}, 0);
};
this.terminal.clearHome();
this.terminal.interpret('\x1b]1337;File=inline=1:Cg==\x07OK');
text = this.terminal.getRowsText(0, 1);
assert.equal('', text);
-
- result.requestTime(200);
});
/**
* Test the cursor shape changes using DECSCUSR.
*/
-hterm.VT.Tests.addTest('DECSCUSR, cursor shapes', function(result, cx) {
+it('DECSCUSR, cursor shapes', function() {
assert.strictEqual(this.terminal.getCursorShape(),
hterm.Terminal.cursorShape.BLOCK);
assert.isFalse(this.terminal.options_.cursorBlink);
@@ -2420,13 +2288,11 @@
assert.strictEqual(this.terminal.getCursorShape(),
hterm.Terminal.cursorShape.BLOCK);
assert.isFalse(this.terminal.options_.cursorBlink);
-
- result.pass();
});
-hterm.VT.Tests.addTest('bracketed-paste', function(result, cx) {
+it('bracketed-paste', function() {
var resultString;
- terminal.io.sendString = (str) => resultString = str;
+ this.terminal.io.sendString = (str) => resultString = str;
assert.isFalse(this.terminal.options_.bracketedPaste);
@@ -2441,11 +2307,9 @@
this.terminal.onPaste_({text: 'hello world'});
assert.equal(resultString, 'hello world');
-
- result.pass();
});
-hterm.VT.Tests.addTest('fullscreen', function(result, cx) {
+it('fullscreen', function(done) {
this.div.style.height = '100%';
this.div.style.width = '100%';
@@ -2461,16 +2325,14 @@
lib.f.getWhitespace(indent) + '*\n');
}
- result.pass();
+ done();
}, 100);
-
- result.requestTime(200);
});
/**
* Verify switching character maps works.
*/
-hterm.VT.Tests.addTest('character-maps', function(result, cx) {
+it('character-maps', function() {
// This test checks graphics handling in ISO-2022 mode.
this.terminal.vt.setEncoding('iso-2022');
@@ -2499,14 +2361,12 @@
this.terminal.interpret('\x1b(' + map + line);
assert.equal(this.terminal.getRowText(0), gl(line));
}
-
- result.pass();
});
/**
* Verify DOCS (encoding) switching behavior.
*/
-hterm.VT.Tests.addTest('docs', function(result, cx) {
+it('docs', function() {
// This test checks graphics handling in ISO-2022 mode.
this.terminal.vt.setEncoding('iso-2022');
@@ -2570,14 +2430,12 @@
assert.isTrue(this.terminal.vt.codingSystemUtf8_);
assert.isTrue(this.terminal.vt.codingSystemLocked_);
assert.equal(this.terminal.getRowText(0), line);
-
- result.pass();
});
/**
* Verify DOCS (encoding) invalid escapes don't mess things up.
*/
-hterm.VT.Tests.addTest('docs-invalid', function(result, cx) {
+it('docs-invalid', function() {
// This test checks graphics handling in ISO-2022 mode.
this.terminal.vt.setEncoding('iso-2022');
@@ -2612,14 +2470,12 @@
assert.isFalse(this.terminal.vt.codingSystemLocked_);
assert.equal(this.terminal.getRowText(0), '');
});
-
- result.pass();
});
/**
* Check cursor save/restore behavior.
*/
-hterm.VT.Tests.addTest('cursor-save-restore', function(result, cx) {
+it('cursor-save-restore', function() {
let tattrs;
// Save the current cursor state.
@@ -2649,14 +2505,12 @@
// Make sure color palette did not change.
assert.equal('rgb(0, 0, 0)', tattrs.colorPalette[0]);
assert.equal('rgba(17, 34, 51, 1)', tattrs.colorPalette[1]);
-
- result.pass();
});
/**
* Check different mouse mode selection.
*/
-hterm.VT.Tests.addTest('mouse-switching', function(result, cx) {
+it('mouse-switching', function() {
const terminal = this.terminal;
const assertMouse = (report, coordinates) => {
@@ -2706,14 +2560,12 @@
terminal.interpret('\x1b[?1006h');
assertMouse(terminal.vt.MOUSE_REPORT_PRESS,
terminal.vt.MOUSE_COORDINATES_SGR);
-
- result.pass();
});
/**
* Check mouse behavior when reporting is disabled.
*/
-hterm.VT.Tests.addTest('mouse-disabled', function(result, cx) {
+it('mouse-disabled', function() {
const terminal = this.terminal;
let e;
@@ -2727,13 +2579,12 @@
terminal.vt.onTerminalMouse_(e);
assert.isUndefined(resultString);
- result.pass();
});
/**
* Check mouse behavior when press reports are enabled.
*/
-hterm.VT.Tests.addTest('mouse-report-press', function(result, cx) {
+it('mouse-report-press', function() {
const terminal = this.terminal;
let e;
@@ -2758,8 +2609,6 @@
e = MockTerminalMouseEvent('mouseup');
terminal.vt.onTerminalMouse_(e);
assert.isUndefined(resultString);
-
- result.pass();
});
/**
@@ -2767,7 +2616,7 @@
*
* Namely, keyboard modifiers shouldn't be reported.
*/
-hterm.VT.Tests.addTest('mouse-report-press-keyboard', function(result, cx) {
+it('mouse-report-press-keyboard', function() {
const terminal = this.terminal;
let e;
@@ -2811,14 +2660,12 @@
terminal.vt.onTerminalMouse_(e);
assert.equal('\x1b[<0;0;0M', resultString);
resultString = undefined;
-
- result.pass();
});
/**
* Check mouse press behavior in X10 coordinates.
*/
-hterm.VT.Tests.addTest('mouse-press-x10-coord', function(result, cx) {
+it('mouse-press-x10-coord', function() {
const terminal = this.terminal;
let e;
@@ -2861,14 +2708,12 @@
terminal.vt.onTerminalMouse_(e);
assert.equal('\x1b[M \xff\xff', resultString);
*/
-
- result.pass();
});
/**
* Check mouse press behavior in UTF8 coordinates.
*/
-hterm.VT.Tests.addTest('mouse-press-utf8-coord', function(result, cx) {
+it('mouse-press-utf8-coord', function() {
const terminal = this.terminal;
let e;
@@ -2914,14 +2759,12 @@
'mousedown', {terminalRow: 3000, terminalColumn: 3000});
terminal.vt.onTerminalMouse_(e);
assert.equal('\x1b[M \u07ff\u07ff', resultString);
-
- result.pass();
});
/**
* Check mouse press behavior in SGR coordinates.
*/
-hterm.VT.Tests.addTest('mouse-press-sgr-coord', function(result, cx) {
+it('mouse-press-sgr-coord', function() {
const terminal = this.terminal;
let e;
@@ -2955,14 +2798,12 @@
'mousedown', {terminalRow: 99999, terminalColumn: 55555});
terminal.vt.onTerminalMouse_(e);
assert.equal('\x1b[<0;55555;99999M', resultString);
-
- result.pass();
});
/**
* Check mouse behavior when press clicks are enabled.
*/
-hterm.VT.Tests.addTest('mouse-report-click', function(result, cx) {
+it('mouse-report-click', function() {
const terminal = this.terminal;
let e;
@@ -2987,8 +2828,6 @@
e = MockTerminalMouseEvent('mouseup');
terminal.vt.onTerminalMouse_(e);
assert.equal('\x1b[M# ', resultString);
-
- result.pass();
});
/**
@@ -2998,7 +2837,7 @@
* released ('mouseup') while saying it's still pressed ('buttons'). The
* VT code doesn't check for this, so (ab)use this to simplify the test.
*/
-hterm.VT.Tests.addTest('mouse-report-click-buttons', function(result, cx) {
+it('mouse-report-click-buttons', function() {
const terminal = this.terminal;
let e;
@@ -3061,14 +2900,12 @@
e = MockTerminalMouseEvent('mouseup', {button: 1, buttons: 0});
terminal.vt.onTerminalMouse_(e);
assert.equal('\x1b[<1;0;0m', resultString);
-
- result.pass();
});
/**
* Check mouse click behavior with keyboard modifiers.
*/
-hterm.VT.Tests.addTest('mouse-report-click-keyboard', function(result, cx) {
+it('mouse-report-click-keyboard', function() {
const terminal = this.terminal;
let e;
@@ -3137,14 +2974,12 @@
e = MockTerminalMouseEvent('mouseup', {button: 2, shiftKey: true});
terminal.vt.onTerminalMouse_(e);
assert.equal('\x1b[<2;0;0m', resultString);
-
- result.pass();
});
/**
* Check mouse behavior when drags are enabled.
*/
-hterm.VT.Tests.addTest('mouse-report-drag', function(result, cx) {
+it('mouse-report-drag', function() {
const terminal = this.terminal;
let e;
@@ -3173,14 +3008,12 @@
e = MockTerminalMouseEvent('mouseup');
terminal.vt.onTerminalMouse_(e);
assert.equal('\x1b[M# ', resultString);
-
- result.pass();
});
/**
* Check mouse drag behavior with buttons.
*/
-hterm.VT.Tests.addTest('mouse-report-drag-buttons', function(result, cx) {
+it('mouse-report-drag-buttons', function() {
const terminal = this.terminal;
let e;
@@ -3209,14 +3042,12 @@
e = MockTerminalMouseEvent('mousemove', {buttons: 7});
terminal.vt.onTerminalMouse_(e);
assert.equal('\x1b[<32;0;0M', resultString);
-
- result.pass();
});
/**
* Check mouse drag behavior with keyboard modifiers.
*/
-hterm.VT.Tests.addTest('mouse-report-drag-keyboard', function(result, cx) {
+it('mouse-report-drag-keyboard', function() {
const terminal = this.terminal;
let e;
@@ -3255,14 +3086,12 @@
'mousemove', {buttons: 1, shiftKey: true, ctrlKey: true, metaKey: true});
terminal.vt.onTerminalMouse_(e);
assert.equal('\x1b[<60;0;0M', resultString);
-
- result.pass();
});
/**
* Check mouse wheel behavior when reports are enabled.
*/
-hterm.VT.Tests.addTest('mouse-report-wheel', function(result, cx) {
+it('mouse-report-wheel', function() {
const terminal = this.terminal;
let e;
@@ -3281,14 +3110,12 @@
e = MockTerminalMouseEvent('wheel', {deltaY: -1});
terminal.vt.onTerminalMouse_(e);
assert.equal('\x1b[M` ', resultString);
-
- result.pass();
});
/**
* Check mouse wheel behavior in X10 coordinates.
*/
-hterm.VT.Tests.addTest('mouse-wheel-x10-coord', function(result, cx) {
+it('mouse-wheel-x10-coord', function() {
const terminal = this.terminal;
let e;
@@ -3331,14 +3158,12 @@
terminal.vt.onTerminalMouse_(e);
assert.equal('\x1b[Ma\xff\xff', resultString);
*/
-
- result.pass();
});
/**
* Check mouse wheel behavior in UTF8 coordinates.
*/
-hterm.VT.Tests.addTest('mouse-wheel-utf8-coord', function(result, cx) {
+it('mouse-wheel-utf8-coord', function() {
const terminal = this.terminal;
let e;
@@ -3384,14 +3209,12 @@
'wheel', {terminalRow: 3000, terminalColumn: 3000});
terminal.vt.onTerminalMouse_(e);
assert.equal('\x1b[Ma\u07ff\u07ff', resultString);
-
- result.pass();
});
/**
* Check mouse wheel behavior in SGR coordinates.
*/
-hterm.VT.Tests.addTest('mouse-wheel-sgr-coord', function(result, cx) {
+it('mouse-wheel-sgr-coord', function() {
const terminal = this.terminal;
let e;
@@ -3425,14 +3248,12 @@
'wheel', {terminalRow: 99999, terminalColumn: 55555});
terminal.vt.onTerminalMouse_(e);
assert.equal('\x1b[<65;55555;99999M', resultString);
-
- result.pass();
});
/**
* Verify CSI-J-0 (erase below) works.
*/
-hterm.VT.Tests.addTest('csi-j-0', function(result, cx) {
+it('csi-j-0', function() {
const terminal = this.terminal;
// Fill the screen with something useful.
@@ -3468,14 +3289,12 @@
// The scrollback should stay intact.
assert.equal('ab0', terminal.getRowText(0));
assert.equal(rowCount, terminal.getRowCount());
-
- result.pass();
});
/**
* Verify CSI-J-1 (erase above) works.
*/
-hterm.VT.Tests.addTest('csi-j-1', function(result, cx) {
+it('csi-j-1', function() {
const terminal = this.terminal;
// Fill the screen with something useful.
@@ -3502,14 +3321,12 @@
// The scrollback should stay intact.
assert.equal('ab0', terminal.getRowText(0));
assert.equal(rowCount, terminal.getRowCount());
-
- result.pass();
});
/**
* Verify CSI-J-2 (erase screen) works.
*/
-hterm.VT.Tests.addTest('csi-j-2', function(result, cx) {
+it('csi-j-2', function() {
const terminal = this.terminal;
// Fill the screen with something useful.
@@ -3536,14 +3353,12 @@
// The scrollback should stay intact.
assert.equal('ab0', terminal.getRowText(0));
assert.equal(rowCount, terminal.getRowCount());
-
- result.pass();
});
/**
* Verify CSI-J-3 (erase scrollback) works.
*/
-hterm.VT.Tests.addTest('csi-j-3', function(result, cx) {
+it('csi-j-3', function() {
const terminal = this.terminal;
// Fill the screen with something useful.
@@ -3582,6 +3397,6 @@
// The scrollback should be gone.
assert.equal(this.visibleRowCount, terminal.getRowCount());
assert.deepStrictEqual([], terminal.scrollbackRows_);
+});
- result.pass();
});