Skip to content

Commit

Permalink
ci: fix 'saveable' test-case
Browse files Browse the repository at this point in the history
The following commit fixes an issue with the `saveable.spec.js` api
test, where due to a quick `ADDED/DELETE` event, NSFW was not properly
notified of the event, causing the test to fail when attempting to
verify its assertions. The fix includes waiting a bit before deleting
the resource so NSFW can properly listen to both `ADDED` and
`DELETED` events.

Signed-off-by: vince-fugnitto <vincent.fugnitto@ericsson.com>
  • Loading branch information
vince-fugnitto committed Nov 9, 2020
1 parent 632a67a commit 5591a5c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions examples/api-tests/src/saveable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ describe('Saveable', function () {
await fileService.create(fileUri, 'foo', { fromUserGesture: false, overwrite: true });
widget = /** @type {EditorWidget & SaveableWidget} */
(await editorManager.open(fileUri, { mode: 'reveal' }));
editor = MonacoEditor.get(widget);
editor = /** @type {MonacoEditor} */ (MonacoEditor.get(widget));
});

afterEach(async () => {
toTearDown.dispose();
preferences.set('editor.autoSave', autoSave, undefined, rootUri.toString());
// @ts-ignore
editor = undefined;
// @ts-ignore
widget = undefined;
await editorManager.closeAll({ save: false });
await fileService.delete(fileUri.parent, { fromUserGesture: false, useTrash: false, recursive: true });
Expand All @@ -104,6 +106,7 @@ describe('Saveable', function () {
editor.getControl().setValue(longContent);
await Saveable.save(widget);

// @ts-ignore
editor.getControl().getModel().applyEdits([{
range: monaco.Range.fromPositions({ lineNumber: 1, column: 1 }, { lineNumber: 1, column: 4 }),
forceMoveMarkers: false,
Expand All @@ -113,6 +116,7 @@ describe('Saveable', function () {

const resource = editor.document['resource'];
const version = resource.version;
// @ts-ignore
await resource.saveContents('baz');
assert.notEqual(version, resource.version, 'latest version should be different after write');

Expand All @@ -128,6 +132,7 @@ describe('Saveable', function () {
const saveContentChanges = resource.saveContentChanges;
resource.saveContentChanges = async (changes, options) => {
incrementalUpdate = true;
// @ts-ignore
return saveContentChanges.bind(resource)(changes, options);
};
try {
Expand Down Expand Up @@ -156,6 +161,7 @@ describe('Saveable', function () {

const resource = editor.document['resource'];
const version = resource.version;
// @ts-ignore
await resource.saveContents('bazz');
assert.notEqual(version, resource.version, 'latest version should be different after write');

Expand Down Expand Up @@ -289,6 +295,8 @@ describe('Saveable', function () {
const listener = () => waitForDidChangeTitle.resolve();
widget.title.changed.connect(listener);
try {
// Wait a little before attempting to `delete` so watchers are properly notified.
await new Promise(resolve => setTimeout(resolve, 1000));
await fileService.delete(fileUri);
await waitForDidChangeTitle.promise;
assert.isTrue(widget.title.label.endsWith('(deleted from disk)'), 'should be marked as deleted');
Expand Down Expand Up @@ -390,7 +398,7 @@ describe('Saveable', function () {

widget = /** @type {EditorWidget & SaveableWidget} */
(await editorManager.open(fileUri, { mode: 'reveal' }));
editor = MonacoEditor.get(widget);
editor = /** @type {MonacoEditor} */ (MonacoEditor.get(widget));

assert.strictEqual('utf8', editor.document.getEncoding());
assert.strictEqual('foo', editor.document.getText().trimRight());
Expand All @@ -413,7 +421,7 @@ describe('Saveable', function () {

widget = /** @type {EditorWidget & SaveableWidget} */
(await editorManager.open(fileUri, { mode: 'reveal' }));
editor = MonacoEditor.get(widget);
editor = /** @type {MonacoEditor} */ (MonacoEditor.get(widget));

assert.strictEqual('utf16le', editor.document.getEncoding());
assert.notEqual('foo', editor.document.getText().trimRight());
Expand All @@ -434,7 +442,7 @@ describe('Saveable', function () {

widget = /** @type {EditorWidget & SaveableWidget} */
(await editorManager.open(fileUri, { mode: 'reveal' }));
editor = MonacoEditor.get(widget);
editor = /** @type {MonacoEditor} */ (MonacoEditor.get(widget));

assert.strictEqual('utf16le', editor.document.getEncoding());
assert.strictEqual('foo', editor.document.getText().trimRight());
Expand Down

0 comments on commit 5591a5c

Please sign in to comment.