Skip to content

Commit 2f1929a

Browse files
committed
Use async/await
To increase the readability
1 parent 98eddd0 commit 2f1929a

File tree

4 files changed

+56
-53
lines changed

4 files changed

+56
-53
lines changed

test/lib/clipboard.test.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@ const Clipboard = require('../../lib/clipboard');
33

44
suite('Clipboard', () => {
55

6-
test('it reads text from clipboard', () => {
6+
test('it reads text from clipboard', async () => {
77
const clipboardy = {read: () => Promise.resolve('LINE1\r\r\nLINE2\r\r\n')};
88
const clipboard = new Clipboard({clipboardy});
9-
return clipboard.read().then(text => {
10-
expect(text).to.eql('LINE1\r\r\nLINE2\r\r\n');
11-
});
9+
const text = await clipboard.read();
10+
expect(text).to.eql('LINE1\r\r\nLINE2\r\r\n');
1211
});
1312

14-
test('it replaces `\\r\\r\\n` to `\\r\\n` on Windows', () => {
13+
test('it replaces `\\r\\r\\n` to `\\r\\n` on Windows', async () => {
1514
const clipboardy = {read: () => Promise.resolve('LINE1\r\r\nLINE2\r\r\n')};
1615
const platform = 'win32';
1716
const clipboard = new Clipboard({clipboardy, platform});
18-
return clipboard.read().then(text => {
19-
expect(text).to.eql('LINE1\r\nLINE2\r\n');
20-
});
17+
const text = await clipboard.read();
18+
expect(text).to.eql('LINE1\r\nLINE2\r\n');
2119
});
2220

2321
});

test/lib/commands/compare-selection-with-clipboard.test.js

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const CompareSelectionWithClipboardCommand = require('../../../lib/commands/comp
33

44
suite('CompareSelectionWithClipboardCommand', () => {
55

6-
test('it compares selected text with clipboard text', () => {
6+
test('it compares selected text with clipboard text', async () => {
77
const clipboard = {read: () => Promise.resolve('CLIPBOARD_TEXT')};
88
const selectionInfoBuilder = {
99
extract: stubWithArgs(['EDITOR'], {
@@ -20,32 +20,34 @@ suite('CompareSelectionWithClipboardCommand', () => {
2020
selectionInfoBuilder,
2121
selectionInfoRegistry
2222
});
23-
return command.execute('EDITOR').then(() => {
24-
expect(selectionInfoRegistry.set).to.have.been.calledWith(
25-
'clipboard',
26-
{
27-
text: 'CLIPBOARD_TEXT',
28-
fileName: 'Clipboard'
29-
}
30-
);
31-
expect(selectionInfoRegistry.set).to.have.been.calledWith(
32-
'reg2',
33-
{
34-
text: 'SELECTED_TEXT',
35-
fileName: 'FILENAME',
36-
lineRange: 'SELECTED_RANGE'
37-
}
38-
);
39-
expect(diffPresenter.takeDiff).to.have.been.calledWith('clipboard', 'reg2');
40-
});
23+
24+
await command.execute('EDITOR');
25+
26+
expect(selectionInfoRegistry.set).to.have.been.calledWith(
27+
'clipboard',
28+
{
29+
text: 'CLIPBOARD_TEXT',
30+
fileName: 'Clipboard'
31+
}
32+
);
33+
expect(selectionInfoRegistry.set).to.have.been.calledWith(
34+
'reg2',
35+
{
36+
text: 'SELECTED_TEXT',
37+
fileName: 'FILENAME',
38+
lineRange: 'SELECTED_RANGE'
39+
}
40+
);
41+
expect(diffPresenter.takeDiff).to.have.been.calledWith('clipboard', 'reg2');
4142
});
4243

43-
test('it prints callstack if error occurred', () => {
44+
test('it prints callstack if error occurred', async () => {
4445
const logger = {error: sinon.spy()};
4546
const command = new CompareSelectionWithClipboardCommand({logger});
46-
return command.execute('EDITOR').then(() => {
47-
expect(logger.error).to.have.been.called;
48-
});
47+
48+
await command.execute('EDITOR');
49+
50+
expect(logger.error).to.have.been.called;
4951
});
5052

5153
});

test/lib/commands/compare-selection-with-text1.test.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const CompareSelectionWithText1 = require('../../../lib/commands/compare-selecti
33

44
suite('CompareSelectionWithText1', () => {
55

6-
test('it saves selected text and takes a diff of 2 texts', () => {
6+
test('it saves selected text and takes a diff of 2 texts', async () => {
77
const selectionInfoBuilder = {
88
extract: stubWithArgs(['EDITOR'], {
99
text: 'SELECTED_TEXT',
@@ -14,25 +14,27 @@ suite('CompareSelectionWithText1', () => {
1414
const selectionInfoRegistry = {set: sinon.spy()};
1515
const diffPresenter = {takeDiff: sinon.spy()};
1616
const command = new CompareSelectionWithText1({diffPresenter, selectionInfoBuilder, selectionInfoRegistry});
17-
return command.execute('EDITOR').then(() => {
18-
expect(selectionInfoRegistry.set).to.have.been.calledWith(
19-
'reg2',
20-
{
21-
text: 'SELECTED_TEXT',
22-
fileName: 'FILENAME',
23-
lineRange: 'SELECTED_RANGE'
24-
}
25-
);
26-
expect(diffPresenter.takeDiff).to.have.been.calledWith('reg1', 'reg2');
27-
});
17+
18+
await command.execute('EDITOR');
19+
20+
expect(selectionInfoRegistry.set).to.have.been.calledWith(
21+
'reg2',
22+
{
23+
text: 'SELECTED_TEXT',
24+
fileName: 'FILENAME',
25+
lineRange: 'SELECTED_RANGE'
26+
}
27+
);
28+
expect(diffPresenter.takeDiff).to.have.been.calledWith('reg1', 'reg2');
2829
});
2930

30-
test('it prints callstack if error occurred', () => {
31+
test('it prints callstack if error occurred', async () => {
3132
const logger = {error: sinon.spy()};
3233
const command = new CompareSelectionWithText1({logger});
33-
return command.execute('EDITOR').then(() => {
34-
expect(logger.error).to.have.been.called;
35-
});
34+
35+
await command.execute('EDITOR');
36+
37+
expect(logger.error).to.have.been.called;
3638
});
3739

3840
});

test/lib/diff-presenter.test.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const DiffPresenter = require('../../lib/diff-presenter');
33

44
suite('DiffPresenter', () => {
55

6-
test('it compares two files', () => {
6+
test('it compares two files', async () => {
77
const commands = fakeCommands();
88
const selectionInfoRegistry = {
99
get: stubWithArgs(
@@ -19,11 +19,12 @@ suite('DiffPresenter', () => {
1919
)
2020
};
2121
const diffPresenter = new DiffPresenter({commands, textTitleBuilder, selectionInfoRegistry, textResourceUtil});
22-
return diffPresenter.takeDiff('TEXT1', 'TEXT2').then(() => {
23-
expect(commands.executeCommand).to.have.been.calledWith(
24-
'vscode.diff', 'URI_INSTANCE_1', 'URI_INSTANCE_2', 'TITLE_TEXT_INFO_1 \u2194 TITLE_TEXT_INFO_2'
25-
);
26-
});
22+
23+
await diffPresenter.takeDiff('TEXT1', 'TEXT2');
24+
25+
expect(commands.executeCommand).to.have.been.calledWith(
26+
'vscode.diff', 'URI_INSTANCE_1', 'URI_INSTANCE_2', 'TITLE_TEXT_INFO_1 \u2194 TITLE_TEXT_INFO_2'
27+
);
2728
});
2829

2930
function fakeCommands() {

0 commit comments

Comments
 (0)