Skip to content

Commit e10980b

Browse files
committed
optimizations to tests (reduces test runtime by about 70% on my MacPro)
1 parent 341c414 commit e10980b

1 file changed

Lines changed: 16 additions & 25 deletions

File tree

tests/test.spec.ts

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const fileUrl = `file://${filePath}`;
77

88
test.describe('test', () => {
99
test.beforeEach(async ({ page }) => {
10-
await page.goto(fileUrl);
10+
await page.goto(fileUrl);
1111
});
1212

1313
test('sanity startup', async ({ page }) => {
@@ -28,23 +28,27 @@ test.describe('input caret selection', () => {
2828

2929
test.beforeEach(async ({ page }) => {
3030
await page.goto(fileUrl);
31-
// TODO: these tests run slow as heck, can we eliminate the focus() calls below, and run them all in a single await Promise.all() ?
32-
// TODO: also look into using playwright multithreaded mode to it's best use
33-
await page.locator('[name=suffix]').focus();
34-
await page.locator('[name=suffix]').fill(suffix);
35-
await page.locator('[name=prefix]').focus();
36-
await page.locator('[name=prefix]').fill(prefix);
37-
await page.locator('[name=precision]').focus();
38-
await page.locator('[name=precision]').fill(precision);
39-
await page.locator('[name=apply]').click();
31+
await Promise.all([
32+
page.locator('[name=suffix]').focus(),
33+
page.locator('[name=suffix]').fill(suffix),
34+
]);
35+
await Promise.all([
36+
page.locator('[name=prefix]').focus(),
37+
page.locator('[name=prefix]').fill(prefix),
38+
]);
39+
await Promise.all([
40+
page.locator('[name=precision]').focus(),
41+
page.locator('[name=precision]').fill(precision),
42+
]);
43+
await Promise.all([
44+
page.locator('[name=apply]').click(),
45+
]);
4046
});
4147

4248
test.describe('basic caret movement', () => {
4349
test('focus sets selection to last character before suffix', async ({ page }) => {
4450
const currencyInput = await page.locator('#currency-input');
4551
await currencyInput.focus();
46-
// TODO: are these waitforTimeouts necessary?
47-
await page.waitForTimeout(1);
4852
const inputValue = await currencyInput.inputValue();
4953
const inputLength = inputValue.length;
5054
const selectionStart = await currencyInput.evaluate(el => el.selectionStart);
@@ -56,7 +60,6 @@ test.describe('input caret selection', () => {
5660
test('cursor right from end does not allow caret selection to move', async ({ page }) => {
5761
const currencyInput = await page.locator('#currency-input');
5862
await currencyInput.focus();
59-
await page.waitForTimeout(1);
6063
await currencyInput.press('ArrowRight');
6164
const inputValue = await currencyInput.inputValue();
6265
const inputLength = inputValue.length;
@@ -69,7 +72,6 @@ test.describe('input caret selection', () => {
6972
test('cursor left from end allows caret to move one backwards', async ({ page }) => {
7073
const currencyInput = await page.locator('#currency-input');
7174
await currencyInput.focus();
72-
await page.waitForTimeout(1);
7375
await currencyInput.press('ArrowLeft');
7476
const inputValue = await currencyInput.inputValue();
7577
const inputLength = inputValue.length;
@@ -82,7 +84,6 @@ test.describe('input caret selection', () => {
8284
test('cursor left twice from end allows caret to move two backwards', async ({ page }) => {
8385
const currencyInput = await page.locator('#currency-input');
8486
await currencyInput.focus();
85-
await page.waitForTimeout(1);
8687
await currencyInput.press('ArrowLeft');
8788
await currencyInput.press('ArrowLeft');
8889
const inputValue = await currencyInput.inputValue();
@@ -96,7 +97,6 @@ test.describe('input caret selection', () => {
9697
test('cursor left thrice from end allows caret to move three backwards', async ({ page }) => {
9798
const currencyInput = await page.locator('#currency-input');
9899
await currencyInput.focus();
99-
await page.waitForTimeout(1);
100100
await currencyInput.press('ArrowLeft');
101101
await currencyInput.press('ArrowLeft');
102102
await currencyInput.press('ArrowLeft');
@@ -111,7 +111,6 @@ test.describe('input caret selection', () => {
111111
test('cursor home from end places caret selection in front of prefix', async ({ page }) => {
112112
const currencyInput = await page.locator('#currency-input');
113113
await currencyInput.focus();
114-
await page.waitForTimeout(1);
115114
await currencyInput.press('Home');
116115
const inputValue = await currencyInput.inputValue();
117116
const inputLength = inputValue.length;
@@ -124,9 +123,7 @@ test.describe('input caret selection', () => {
124123
test('cursor left from beginning does not allow caret selection to move', async ({ page }) => {
125124
const currencyInput = await page.locator('#currency-input');
126125
await currencyInput.focus();
127-
await page.waitForTimeout(1);
128126
await currencyInput.press('Home');
129-
await page.waitForTimeout(1);
130127
await currencyInput.press('ArrowLeft');
131128
const inputValue = await currencyInput.inputValue();
132129
const inputLength = inputValue.length;
@@ -141,7 +138,6 @@ test.describe('input caret selection', () => {
141138
test('enter 123 from end sets value to $1.23', async ({ page }) => {
142139
const currencyInput = await page.locator('#currency-input');
143140
await currencyInput.focus();
144-
await page.waitForTimeout(1);
145141
await currencyInput.type('123');
146142
const inputValue = await currencyInput.inputValue();
147143
const inputLength = inputValue.length;
@@ -155,7 +151,6 @@ test.describe('input caret selection', () => {
155151
test('enter 123 then backspace once sets value to $0.12', async ({ page }) => {
156152
const currencyInput = await page.locator('#currency-input');
157153
await currencyInput.focus();
158-
await page.waitForTimeout(1);
159154
await currencyInput.type('123');
160155
await currencyInput.press('Backspace');
161156
const inputValue = await currencyInput.inputValue();
@@ -170,7 +165,6 @@ test.describe('input caret selection', () => {
170165
test('enter 123 then backspace twice sets value to $0.01', async ({ page }) => {
171166
const currencyInput = await page.locator('#currency-input');
172167
await currencyInput.focus();
173-
await page.waitForTimeout(1);
174168
await currencyInput.type('123');
175169
await currencyInput.press('Backspace');
176170
await currencyInput.press('Backspace');
@@ -186,7 +180,6 @@ test.describe('input caret selection', () => {
186180
test('enter 123 then backspace thrice sets value to $0.00', async ({ page }) => {
187181
const currencyInput = await page.locator('#currency-input');
188182
await currencyInput.focus();
189-
await page.waitForTimeout(1);
190183
await currencyInput.type('123');
191184
await currencyInput.press('Backspace');
192185
await currencyInput.press('Backspace');
@@ -203,7 +196,6 @@ test.describe('input caret selection', () => {
203196
test('enter 123 then left arrow then backspace sets value to $0.13 and leaves caret selection one left of end', async ({ page }) => {
204197
const currencyInput = await page.locator('#currency-input');
205198
await currencyInput.focus();
206-
await page.waitForTimeout(1);
207199
await currencyInput.type('123');
208200
await currencyInput.press('ArrowLeft');
209201
await currencyInput.press('Backspace');
@@ -219,7 +211,6 @@ test.describe('input caret selection', () => {
219211
test('enter 123 then left arrow then backspace twice sets value to $0.03 and leaves caret selection one left of end', async ({ page }) => {
220212
const currencyInput = await page.locator('#currency-input');
221213
await currencyInput.focus();
222-
await page.waitForTimeout(1);
223214
await currencyInput.type('123');
224215
await currencyInput.press('ArrowLeft');
225216
await currencyInput.press('Backspace');

0 commit comments

Comments
 (0)