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, namely when verifying if the title has been
updated.

Signed-off-by: vince-fugnitto <vincent.fugnitto@ericsson.com>
  • Loading branch information
vince-fugnitto committed Nov 10, 2020
1 parent 632a67a commit 877a479
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions examples/api-tests/src/saveable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,20 @@ describe('Saveable', function () {
const autoSave = preferences.get('editor.autoSave', undefined, rootUri.toString());

beforeEach(async () => {
preferences.set('editor.autoSave', 'off', undefined, rootUri.toString());
await preferences.set('editor.autoSave', 'off', undefined, rootUri.toString());
await editorManager.closeAll({ save: false });
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());
await 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 @@ -268,19 +274,6 @@ describe('Saveable', function () {
assert.equal(state.value.trimRight(), 'bar', 'fs should be updated');
});

it('delete file for saved', async () => {
assert.isFalse(Saveable.isDirty(widget), 'should NOT be dirty before delete');
const waitForDisposed = new Deferred();
const listener = editor.onDispose(() => waitForDisposed.resolve());
try {
await fileService.delete(fileUri);
await waitForDisposed.promise;
assert.isTrue(widget.isDisposed, 'model should be disposed after delete');
} finally {
listener.dispose();
}
});

it('delete and add again file for dirty', async () => {
editor.getControl().setValue('bar');
assert.isTrue(Saveable.isDirty(widget), 'should be dirty before delete');
Expand Down Expand Up @@ -390,7 +383,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 +406,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,10 +427,23 @@ 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());
});

it('delete file for saved', async () => {
assert.isFalse(Saveable.isDirty(widget), 'should NOT be dirty before delete');
const waitForDisposed = new Deferred();
const listener = editor.onDispose(() => waitForDisposed.resolve());
try {
await fileService.delete(fileUri);
await waitForDisposed.promise;
assert.isTrue(widget.isDisposed, 'model should be disposed after delete');
} finally {
listener.dispose();
}
});

});

0 comments on commit 877a479

Please sign in to comment.