Skip to content

Commit

Permalink
add API tests for typescript language
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kosyakov <[email protected]>
  • Loading branch information
akosyakov committed Mar 18, 2020
1 parent c1a8936 commit c4051f2
Show file tree
Hide file tree
Showing 15 changed files with 642 additions and 70 deletions.
2 changes: 1 addition & 1 deletion dev-packages/application-manager/src/expose-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export = function (this: webpack.loader.LoaderContext, source: string, sourceMap
this.cacheable();
}

let modulePackage = modulePackages.find(({ dir }) => this.resourcePath.startsWith(dir));
let modulePackage = modulePackages.find(({ dir }) => this.resourcePath.startsWith(dir + '/'));
if (modulePackage) {
this.callback(undefined, exposeModule(modulePackage, this.resourcePath, source), sourceMap);
return;
Expand Down
25 changes: 12 additions & 13 deletions examples/api-tests/src/saveable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ describe('Saveable', function () {

const { EditorManager } = require('@theia/editor/lib/browser/editor-manager');
const { EditorWidget } = require('@theia/editor/lib/browser/editor-widget');
const { PreferenceService, PreferenceScope } = require('@theia/core/lib/browser/preferences/preference-service');
const { PreferenceService } = require('@theia/core/lib/browser/preferences/preference-service');
const Uri = require('@theia/core/lib/common/uri');
const { Saveable, SaveableWidget } = require('@theia/core/lib/browser/saveable');
const { WorkspaceService } = require('@theia/workspace/lib/browser/workspace-service');
const { FileSystem } = require('@theia/filesystem/lib/common/filesystem');
const { MonacoEditor } = require('@theia/monaco/lib/browser/monaco-editor');
const { DisposableCollection } = require('@theia/core/lib/common/disposable');
const { Deferred } = require('@theia/core/lib/common/promise-util');

/** @type {import('inversify').Container} */
Expand Down Expand Up @@ -79,9 +78,9 @@ describe('Saveable', function () {
assert.isTrue(Saveable.isDirty(widget), `should be dirty before '${edit}' save`);
await Saveable.save(widget);
assert.isFalse(Saveable.isDirty(widget), `should NOT be dirty after '${edit}' save`);
assert.equal(editor.getControl().getValue(), edit, `model should be updated with '${edit}'`);
assert.equal(editor.getControl().getValue().trimRight(), edit, `model should be updated with '${edit}'`);
const state = await fileSystem.resolveContent(fileUri.toString());
assert.equal(state.content, edit, `fs should be updated with '${edit}'`);
assert.equal(state.content.trimRight(), edit, `fs should be updated with '${edit}'`);
}
});

Expand Down Expand Up @@ -129,7 +128,7 @@ describe('Saveable', function () {
assert.isTrue(outOfSync, 'file should be out of sync');
assert.equal(outOfSyncCount, 1, 'user should be prompted only once with out of sync dialog');
assert.isTrue(Saveable.isDirty(widget), 'should be dirty after rejected save');
assert.equal(editor.getControl().getValue(), longContent.substring(3), 'model should be updated');
assert.equal(editor.getControl().getValue().trimRight(), longContent.substring(3), 'model should be updated');
const state = await fileSystem.resolveContent(fileUri.toString());
assert.equal(state.content, 'baz', 'fs should NOT be updated');
});
Expand All @@ -151,7 +150,7 @@ describe('Saveable', function () {
await Saveable.save(widget);
assert.isTrue(outOfSync, 'file should be out of sync');
assert.isTrue(Saveable.isDirty(widget), 'should be dirty after rejected save');
assert.equal(editor.getControl().getValue(), 'bar', 'model should be updated');
assert.equal(editor.getControl().getValue().trimRight(), 'bar', 'model should be updated');
let state = await fileSystem.resolveContent(fileUri.toString());
assert.equal(state.content, 'baz', 'fs should NOT be updated');

Expand All @@ -164,9 +163,9 @@ describe('Saveable', function () {
await Saveable.save(widget);
assert.isTrue(outOfSync, 'file should be out of sync');
assert.isFalse(Saveable.isDirty(widget), 'should NOT be dirty after save');
assert.equal(editor.getControl().getValue(), 'bar', 'model should be updated');
assert.equal(editor.getControl().getValue().trimRight(), 'bar', 'model should be updated');
state = await fileSystem.resolveContent(fileUri.toString());
assert.equal(state.content, 'bar', 'fs should be updated');
assert.equal(state.content.trimRight(), 'bar', 'fs should be updated');
});

it('accept new save', async () => {
Expand All @@ -181,9 +180,9 @@ describe('Saveable', function () {
await Saveable.save(widget);
assert.isTrue(outOfSync, 'file should be out of sync');
assert.isFalse(Saveable.isDirty(widget), 'should NOT be dirty after save');
assert.equal(editor.getControl().getValue(), 'bar', 'model should be updated');
assert.equal(editor.getControl().getValue().trimRight(), 'bar', 'model should be updated');
const state = await fileSystem.resolveContent(fileUri.toString());
assert.equal(state.content, 'bar', 'fs should be updated');
assert.equal(state.content.trimRight(), 'bar', 'fs should be updated');
});

it('cancel save on close', async () => {
Expand Down Expand Up @@ -243,7 +242,7 @@ describe('Saveable', function () {
assert.isTrue(outOfSync, 'file should be out of sync');
assert.isTrue(widget.isDisposed, 'model should be disposed after close');
const state = await fileSystem.resolveContent(fileUri.toString());
assert.equal(state.content, 'bar', 'fs should be updated');
assert.equal(state.content.trimRight(), 'bar', 'fs should be updated');
});

it('normal close', async () => {
Expand All @@ -254,7 +253,7 @@ describe('Saveable', function () {
});
assert.isTrue(widget.isDisposed, 'model should be disposed after close');
const state = await fileSystem.resolveContent(fileUri.toString());
assert.equal(state.content, 'bar', 'fs should be updated');
assert.equal(state.content.trimRight(), 'bar', 'fs should be updated');
});

it('delete file for saved', async () => {
Expand Down Expand Up @@ -320,7 +319,7 @@ describe('Saveable', function () {
assert.isFalse(Saveable.isDirty(widget), 'should NOT be dirty after save');
assert.isTrue(editor.document.valid, 'should be valid after save');
const state = await fileSystem.resolveContent(fileUri.toString());
assert.equal(state.content, 'bar', 'fs should be updated');
assert.equal(state.content.trimRight(), 'bar', 'fs should be updated');
});

it('move file for saved', async function () {
Expand Down
Loading

0 comments on commit c4051f2

Please sign in to comment.