Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: fix 'saveable' test-case #8736

Merged
merged 1 commit into from
Nov 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
});

});